Deck 11: Binary Search Trees
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
Play
Full screen (f)
Deck 11: Binary Search Trees
1
A minheap is a complete binary tree in which each node is less than or equal to both the left child and the right child.
A) Minheap
B) Maxheap
C) Heap
D) Binary search tree
A) Minheap
B) Maxheap
C) Heap
D) Binary search tree
Minheap
2
A minheap stores its smallest element at the ________ of the binary tree.
A) leaf
B) internal node
C) root
D) sibling
A) leaf
B) internal node
C) root
D) sibling
root
3
Both children of the root of a minheap are _________.
A) Minheaps
B) Maxheaps
C) Heaps
D) Binary search trees
A) Minheaps
B) Maxheaps
C) Heaps
D) Binary search trees
Minheaps
4
The __________ method adds a given Comparable element to the appropriate location in the heap, maintaining both the completeness property and the ordering property of the heap.
A) add
B) addNext
C) addElement
D) none of the above
A) add
B) addNext
C) addElement
D) none of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Since a heap is a complete tree, there is only one correct location for the insertion of a new node, and that is either the next open position from the left at level h or the first position on the left at level h+1 if level h is full.
A) Minheap
B) Maxheap
C) Balanced tree
D) Complete tree
A) Minheap
B) Maxheap
C) Balanced tree
D) Complete tree
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
Typically, in heap implementations, we keep track of the position of the last node or, more precisely, the last leaf in the tree.
A) root
B) internal node
C) leaf
D) tree
A) root
B) internal node
C) leaf
D) tree
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
To maintain the completeness of the tree, there is only one valid element to replace the ________, and that is the element stored in the last leaf in the tree.
A) root
B) internal node
C) leaf
D) tree
A) root
B) internal node
C) leaf
D) tree
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Though not a queue at all, a minheap provides an efficient implementation of a _____________.
A) Priority queue
B) Circular queue
C) Deque
D) None of the above
A) Priority queue
B) Circular queue
C) Deque
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
Because of the requirement that we be able to traverse up the tree after an insertion, it is necessary for the nodes in a heap to store a pointer to their ________.
A) children
B) parent
C) siblings
D) none of the above
A) children
B) parent
C) siblings
D) none of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
In an array implementation of a binary tree, the root of the tree is in position 0, and for each node n, n's left child is in position ________ and n's right child is in position ________.
A) 2n + 1
B) 2n + 2
C) 2(n + 1)
D) A and B
E) A and C
F) B and C
A) 2n + 1
B) 2n + 2
C) 2(n + 1)
D) A and B
E) A and C
F) B and C
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
The addElement operation for both the linked and array implementations is O(__________).
A) n
B) log n
C) n log n
D) None of the above
A) n
B) log n
C) n log n
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
The removeMin operation for both the linked and array implementations is O(log n).
A) n
B) log n
C) n log n
D) None of the above
A) n
B) log n
C) n log n
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The __________ method consists of adding each of the elements of the list to a heap and then removing them one at a time.
A) heapSort
B) heapify
C) toString
D) None of the above
A) heapSort
B) heapify
C) toString
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Heap sort is O(________).
A) n
B) log n
C) n log n
D) None of the above
A) n
B) log n
C) n log n
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
A minheap is a complete ______ tree in which each node is less than or equal to both the left child and the right child.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
A ______ stores its smallest element at the root of the binary tree.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The addElement method adds a given ______ element to the appropriate location in the heap, maintaining both the completeness property and the ordering property of the heap.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Since a heap is a ______ tree, there is only one correct location for the insertion of a new node, and that is either the next open position from the left at level h or the first position on the left at level h+1 if level h is full.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
Typically, in ______ implementations, we keep track of the position of the last node or, more precisely, the last leaf in the tree.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
To maintain the ______ of the tree, there is only one valid element to replace the root, and that is the element stored in the last leaf in the tree.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Though not a queue at all, a ______ provides an efficient implementation of a priority queue.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Because of the requirement that we be able to traverse up the tree after an insertion, it is necessary for the nodes in a heap to store a pointer to their ______.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
In an array implementation of a binary tree, the root of the tree is in position 0, and for each node n, n's left child is in position ______ and n's right child is in position ______.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
The addElement operation for both the linked and array implementations is O(______).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
The removeMin operation for both the linked and array implementations is O(______)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
The heapSort method consists of adding each of the elements of the list to a ______ and then removing them one at a time. If the heap is a minheap, this results in ______ order. However, if the heap is a maxheap, this results in ______ order.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Heap sort is O(______).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
A minheap is a complete binary tree in which each node is less than or equal to both the left child and the right child.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
A minheap stores its largest element at the root of the binary tree, and both children of the root of a minheap are also minheaps.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
The addElement method adds a given Comparable element to the appropriate location in the heap, maintaining both the completeness property and the ordering property of the heap.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Since a heap is a binary search tree, there is only one correct location for the insertion of a new node, and that is either the next open position from the left at level h or the first position on the left at level h+1 if level h is full.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Typically, in heap implementations, we keep track of the position of the last node or, more precisely, the last leaf in the tree.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
To maintain the completeness of the tree, there is only one valid element to replace the root, and that is the element stored in the first leaf in the tree.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Though not a queue at all, a minheap provides an efficient implementation of a priority queue.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Because of the requirement that we be able to traverse up the tree after an insertion, it is necessary for the nodes in a heap to store a pointer to their parent.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
In an array implementation of a binary tree, the root of the tree is in position 0, and for each node n, n's left child is in position 2(n+1) and n's right child is in position 2(n+2).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
The addElement operation for both the linked and array implementations is O(n log n).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
The removeMin operation for both the linked and array implementations is O(log n).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
The heapSort method consists of adding each of the elements of the list to a heap and then removing them one at a time.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Heap sort is O(n log n).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
What is the difference between a heap (a minheap) and a binary search tree?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
What is the difference between a minheap and a maxheap?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
What does it mean for a heap to be complete?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Does a heap ever have to be rebalanced?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
The addElement operation for the linked implementation must determine the parent of the next node to be inserted. Why?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Why does the addElement operation for the array implementation not have to determine the parent of the next node to be inserted?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
The removeMin operation for both implementations replaces the element at the root with the element in the last leaf of the heap. Why is this the proper replacement?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
What is the time complexity of the addElement operation?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What is the time complexity of the removeMin operation?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
What is the time complexity of heap sort?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck