Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

101.

What is the space complexity of searching in a heap?(a) O(logn)(b) O(n)(c) O(1)(d) O(nlogn)This interesting question is from Binary Heap topic in portion Heap of Data Structures & Algorithms II had been asked this question in an interview for internship.

Answer»

The correct choice is (B) O(n)

Easiest explanation - The SPACE complexity of searching an ELEMENT in heap is O (n). Heap consists of n elements and we NEED to compare every element. Here no ADDITION or deletion of elements takes place. Hence space complexity is O (n).

102.

An array consists of n elements. We want to create a heap using the elements. The time complexity of building a heap will be in order of(a) O(n*n*logn)(b) O(n*logn)(c) O(n*n)(d) O(n *logn *logn)The doubt is from Heap in chapter Heap of Data Structures & Algorithms II got this question in a national level competition.

Answer»

The correct choice is (B) O(N*logn)

Best explanation: The total time taken will be N times the complexity of ADDING a single element to the heap. And adding a single element TAKES logN time, so That is equal to N*logN.

103.

If we implement heap as maximum heap , adding a new node of value 15 to theleft most node of right subtree. What value will be atleaf nodes of the right subtree of the heap.(a) 15 and 1(b) 25 and 1(c) 3 and 1(d) 2 and 3This question is from Heap in chapter Heap of Data Structures & Algorithms IThe question was posed to me in my homework.

Answer»

Right option is (a) 15 and 1

The BEST EXPLANATION: As 15 is less than 25 so there would be no violation and the node will remain at that position. So leaf NODES with VALUE 15 and 1 will be at the position in right SUB tree.

104.

If we implement heap as min-heap, deleting root node (value 1)from the heap. What would be the value of root node after second iteration if leaf node (value 100)is chosen to replace the root at start.(a) 2(b) 100(c) 17(d) 3Query is from Heap in section Heap of Data Structures & Algorithms IThis question was addressed to me in examination.

Answer»

The correct choice is (a) 2

The explanation is: As the ROOT is deleted and NODE with value 100 is used as replaced one. There is a violation of property that root node must have value less than its children. So there will be shuffling of node with value 100 with node of value 2. And thus 2 becomes root. And it will remain to be at root after all the POSSIBLE OPERATIONS. So the value at root will be 2.

105.

Heap can be used as ________________(a) Priority queue(b) Stack(c) A decreasing order array(d) Normal ArrayThe question is from Heap in section Heap of Data Structures & Algorithms IThis question was addressed to me in final exam.

Answer»

Correct choice is (a) PRIORITY queue

For explanation: The property of heap that the VALUE of root MUST be either greater or less than both of its CHILDREN makes it WORK like a priority queue.

106.

The worst case complexity of deleting any arbitrary node value element from heap is __________(a) O(logn)(b) O(n)(c) O(nlogn)(d) O(n^2)My question is taken from Heap topic in chapter Heap of Data Structures & Algorithms IThis question was posed to me in an interview for internship.

Answer»

The correct choice is (a) O(logn)

Easy EXPLANATION - The TOTAL possible operation in DELETING the existing node and re locating new position to all its connected nodes will be EQUAL to height of the heap.

107.

What is the complexity of adding an element to the heap.(a) O(log n)(b) O(h)(c) O(log n) & O(h)(d) O(n)Asked question is from Heap topic in division Heap of Data Structures & Algorithms IThe question was posed to me during an interview.

Answer»

Right option is (c) O(log n) & O(h)

The best I can explain: The total POSSIBLE OPERATION in re LOCATING the new LOCATION to a new element will be equal to HEIGHT of the heap.

108.

Heap exhibits the property of a binary tree?(a) True(b) FalseMy doubt stems from Heap topic in division Heap of Data Structures & Algorithms II have been asked this question at a job interview.

Answer» RIGHT choice is (a) True

The explanation is: Yes, because the LEAF nodes are present at height H or h-1, which is a PROPERTY of complete binary tree.
109.

In a max-heap, element with the greatest key is always in the which node?(a) Leaf node(b) First node of left sub tree(c) root node(d) First node of right sub treeThis interesting question is from Heap topic in portion Heap of Data Structures & Algorithms II had been asked this question in a national level competition.

Answer» CORRECT option is (c) root NODE

The BEST EXPLANATION: This is one of the property of max-heap that root node MUST have key greater than its children.
110.

Naïve merge cannot be done in a skew merge.(a) true(b) false

Answer»

Correct option is (B) false

Best EXPLANATION: One WAY of doing skew merge is to begin with naïve merge and then swapping the left and right children of the TREE.

111.

The actual pairing heap implementation uses the right child and left child representation.(a) true(b) falsewhat is correct in this question.

Answer» CORRECT OPTION is (B) false

The explanation is: The actual PAIRING heap implementation uses a left child and right SIBLING representation since it follows heap order property.