ACTUAL Exam Questions and CORRECT
Answers
True and False statement:
Algorithm upheap restores the heap-order property by swapping k along an upward path from the
insertion node. - CORRECT ANSWER - true
True and False statement:
The following is a heap property:
For a max heap, the value of each node is greater than or equal to the values of it's children, and
for a min heap, the value of each node is less than or equal to the values of it's children. -
CORRECT ANSWER - true
what is a heap?
A heap is a hash tree data structure that can be used to implement a priority queue efficiently.
A heap is a array list in a tree data structure that can be used to implement a priority queue
efficiently.
A heap is an unbalanced tree data structure that can be used to implement a priority queue
efficiently.
A heap is a binary tree data structure that can be used to implement a priority queue efficiently. -
CORRECT ANSWER - A heap is a binary tree data structure that can be used to
implement a priority queue efficiently.
In the following code:
,public static void main(String[] args) {
MergeKSortedLists merger = new MergeKSortedLists();
ListNode[] lists = new ListNode[3];
lists[0] = new ListNode(1);
lists[0].next = new ListNode(4);
lists[0].next.next = new ListNode(5);
lists[1] = new ListNode(1);
lists[1].next = new ListNode(3);
lists[1].next.next = new ListNode(4);
lists[2] = new ListNode(2);
lists[2].next = new ListNode(6);
ListNode mergedList = merger.mergeKLists(lists);
System.out.print("Merged List: ");
merger.printList(mergedList);
, }
}
What does the line [ ListNode mergedList = merger.mergeKLists(lists); ] do? - CORRECT
ANSWER - Merged the sorted lists
In the following code:
while (!minHeap.isEmpty()) {
ListNode node = minHeap.poll();
current.next = node;
current = current.next;
if (node.next != null) {
minHeap.offer(node.next);
}
}
What does the line [ ListNode node = minHeap.poll(); ] do? - CORRECT ANSWER -
Extract the node with the smallest value from the min heap
Priority queue can be implemented using the following data structures: (choose all that applies)
Arrays