Heap Data Structure MCQ
Q1.What is the location of parent node for any arbitary node i?
- (i/2) position
- (i+1)/ position
- floor(i/2) position
- ceil(i/2) position
Answer:- (C).
Explanations :For any node child nodes are located at either 2*i , 2*i +1 So the parent node could be found by taking the floor of the half of child node.
Explanations :For any node child nodes are located at either 2*i , 2*i +1 So the parent node could be found by taking the floor of the half of child node.
int function(vector arr) int len=arr.length(); if(len==0) return; temp=arr[len-1]; arr.pop_back(); return temp;
- o(n)
- O(logn)
- O(1)
- O(n logn)
Answer:- (C).
Explanations :Deletion in a min-heap is in O(1) time.
Explanations :Deletion in a min-heap is in O(1) time.
- O(n)
- O(1)
- O(logn)
- O(nlogn)
Answer:- (C).
Explanations :Decreasing a node value may result in violating the min property. As a result be there would be exchange in the value of parent and child which at max goes up to height of the heap.
Explanations :Decreasing a node value may result in violating the min property. As a result be there would be exchange in the value of parent and child which at max goes up to height of the heap.
int myfun(heap_arr[]) { int mini=INF; for(int i=0;i mini=min(mini,heap_arr) return mini; }
- Last added element to heap
- First element added to heap
- Root of the heap
- Leftmost node of the heap
Answer:- (C).
Explanations :The function return minimum value in the heap_Array which is equal to the root value of the heap.
Explanations :The function return minimum value in the heap_Array which is equal to the root value of the heap.
- Priority queue
- Stack
- A decreasing order array
- None of the mentioned
Answer:- (A).
Explanations :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.
Explanations :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.
- Yes
- No
- Both 1and2
- None of these
Answer:- (B).
Explanations :No, The inorder traversal will not give elements in sorted order. As heap is implemented as either min-heap or max-heap ,the root will be have highest or lowest value than remaining values of the nodes .So this traversal will not give a sorted list.
Explanations :No, The inorder traversal will not give elements in sorted order. As heap is implemented as either min-heap or max-heap ,the root will be have highest or lowest value than remaining values of the nodes .So this traversal will not give a sorted list.
FIB-INSERT(H, x) degree[x]= 0 p[x]= NIL child[x] =NIL left[x] =x right[x] =x mark[x] =FALSE concatenate the root list containing x with root list H if min[H] = NIL or key[x] > key[min[H]] then min[H]= x n[H]= n[H] + 1
- Line -11
- Line -3
- Line -9
- Line -7
Answer:- (C).
Explanations :The main characteristics of a Fibonacci heap is violated since min[H] must contain one with smallest value.
Explanations :The main characteristics of a Fibonacci heap is violated since min[H] must contain one with smallest value.
FIB_UNION(H1,H2) { H =MAKE_HEAP() min[H]= min[H1] concatenate the root list of H2 with the root list of H if (min[H1] = NIL) or (min[H2]!= NIL and min[H2] < min[H1]) then min[H] = min[H2] n[H]= n[H1] + n[H2] free the objects H1 and H2 return H }
- n+1
- n+n/2
- nlogn
- 2*n
Answer:- (A).
Explanations :Union of two trees increase the order of the resultant by atmost value 1.
Explanations :Union of two trees increase the order of the resultant by atmost value 1.
- O(log n)
- O(h)
- O(log n) & O(h)
- None of the mentioned
Answer:- (C).
Explanations :The total possible operation in re locating the new location to a new element will be equal to height of the heap.
Explanations :The total possible operation in re locating the new location to a new element will be equal to height of the heap.
- 2
- 100
- 17
- 3
Answer:- (A).
Explanations :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. If we implement heap as maximum heap, adding a new node of value 15 to the left most node of right subtree . What value will be at leaf nodes of the right subtree of the heap. correctchoice 15 and 1 25 and 1
Explanations :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. If we implement heap as maximum heap, adding a new node of value 15 to the left most node of right subtree . What value will be at leaf nodes of the right subtree of the heap. correctchoice 15 and 1 25 and 1
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.