Chapter 25 Binary Search Trees
Section 25.2 Binary Search Tree Basics
1. A (with no duplicate elements) has the property that for every node in the tree the value of any node in
its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value
of the node.
a. binary tree
b. binary search tree
c. list
d. linked list
#
2. The of a path is the number of the edges in the path.
a. length
b. depth
c. height
d. degree
#
3. The of a node is the length of the path from the root to the node.
a. length
b. depth
c. height
d. degree
#
4. The of a nonempty tree is the length of the path from the root node to its furthest leaf + 1.
a. length
b. depth
c. height
d. degree
#
Section 25.3 Representing Binary Search Trees
10. Which of the following is correct to create a TreeNode for integer 50.
a. TreeNode<int> node = new TreeNode<int>(50);
b. TreeNode<Integer> node = new TreeNode<Integer>(50);
c. TreeNode<Integer> node = new TreeNode<>(50);
d. TreeNode<int> node = new TreeNode<>(50);
#
Section 25.4 Searching for an Element
10. What is the return type for the search function?
a. int
b. double
c. char
d. boolean
#
11. The time complexity for searching an element in a binary search tree is .
a. O(n)
b. O(logn)
c. O(nlogn)
d. O(n^2)
#
Section 25.5 Inserting an Element into a BST
10. A new element is always inserted into a leaf node.
a. True
b. False
#
12. The time complexity for inserting an element into a binary search tree is .
a. O(n)
b. O(logn)
c. O(nlogn)
d. O(n^2)
#
Section 25.6 Tree Traversal
8. The is to visit the nodes level by level. First visit the root, then all children of the root from left to right,
then grandchildren of the root from left to right, and so on.
a. inorder traversal
b. preorder traversal
c. postorder traversal
d. breadth-first traversal
#
16. Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the inorder traversal of the
elements?
a. 3 4 12 21 45 92
b. 3 4 45 21 12 92
c. 12 21 92 45 4 3
d. 4 45 21 12 92 3
e. 4 21 12 92 45 3
#
18. Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the postorder traversal of the
elements?
a. 3 4 12 21 45 92
b. 3 4 45 21 12 92
c. 12 21 92 45 4 3
d. 4 45 21 12 92 3
e. 4 21 12 92 45 3
#
17. Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the
elements?
a. 3 4 12 21 45 92
b. 3 4 45 21 12 92
c. 12 21 92 45 4 3
d. 4 45 21 12 92 3
e. 4 21 12 92 45 3
#
19. Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the
elements after inserting 2 into the tree?
a. 3 2 4 12 21 45 92
b. 3 2 4 45 21 12 92
c. 12 2 21 92 45 4 3
d. 4 2 45 21 12 92 3
e. 4 2 21 12 92 45 3
#
5. The is to visit the left subtree of the current node first, then the current node itself, and finally the right
subtree of the current node.
a. inorder traversal
b. preorder traversal
c. postorder traversal
d. breadth-first traversal
#
6. The is to visit the left subtree of the current node first, then the right subtree of the current node, and
finally the current node itself.
a. inorder traversal
b. preorder traversal
c. postorder traversal
d. breadth-first traversal
#
7. The is to visit the current node first, then the left subtree of the current node, and finally the right
subtree of the current node.
a. inorder traversal
b. preorder traversal
c. postorder traversal
d. breadth-first traversal
#
Section 25.7 The BST Class
9. In the implementation of BST, which of the following are true?
a. Node is defined as an inner class inside BST.
b. Node is defined as a static inner class inside BST because it does not reference any instance data fields in BST.
c. Node has a property named left that links to the left subtree and a property named right that links to the right
subtree and a property named right
d. BST contains a property named root. If tree is empty, root is null.
#
Section 25.8 Deleting Elements from a BST
13. The time complexity for deleing an element into a binary search tree is .
a. O(n)
b. O(logn)
c. O(nlogn)
d. O(n^2)
#
Section 25.9 Tree Visualization and MVC
14. What is the signature of the recursive method in BTView.java?
a. displayTree()
b. displayTree(BST.TreeNode<Integer>, double, double, double)
c. displayTree(BST.TreeNode<String>, double, double, double)
#
20. Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the
elements after deleting 45 from the tree?
a. 3 4 12 21 92
b. 3 4 21 12 92
c. 12 21 92 45 4 3
#
Section 25.10 Iterators
14. True or False? You can traverse the elements in a BST using a foreach loop.
a. True
b. False
#
Section 25.11 Case Study: Data Compression
15. A Huffman tree is constructed using a algorithm.
a. dynamic programming
b. divide-andconquer
c. greedy
d. backtracking