Chapter 25 Check Point Questions
Section 25.2
▼25.2.1
Show the result of inserting 44 into Figure 25.4b.
▼25.2.2
Show the inorder, preorder, and postorder of traversing the elements in the binary tree shown in Figure 25.1b.
▼25.2.3
If a set of elements is inserted into a BST in two different orders, will the two corresponding BSTs look the same? Will the inorder traversal be the same? Will the postorder traversal be the same? Will the preorder traversal be the same?
▼25.2.4
What is the time complexity of inserting an element into a BST?
▼25.2.5
Implement the search(element) method using recursion.
Section 25.3
▼25.3.1
Show the result of deleting 55 from the tree in Figure 25.4b.
▼25.3.2
Show the result of deleting 60 from the tree in Figure 25.4b.
▼25.3.3
What is the time complexity of deleting an element from a BST?
▼25.3.4
Is the algorithm correct if lines 203-207 in Listing 25.4 in Case 2 of the delete() method are replaced by the following code?
parentOfRightMost.right = rightMost.left;
Section 25.4
▼25.4.1
How many times will the displayTree method be invoked if the tree is empty? How many times will the displayTree method be invoked if the tree has 100 nodes?
▼25.4.2
In what order are the nodes in the tree visited by the displayTree method: inorder, preorder, or postorder?
▼25.4.3
What would happen if the code in lines 47-52 in BTView.java is moved to line 33?
▼25.4.4
What is MVC? What are the benefits of the MVC?
Section 25.5
▼25.5.1
What is an iterator?
▼25.5.2
What method is defined in the java.lang.Iterable<E> interface?
▼25.5.3
Suppose you delete implements Collection<E> from line 3 in Listing 25.3,
Tree.java. Will Listing 25.10 still compile?
▼25.5.4
What is the benefit of being a subtype of Iterable<E>?
▼25.5.5
Write one statement that displays the maximum and minimum
element in a BST object named tree.
Section 25.6
▼25.6.1
Every internal node in a Huffman tree has two children. Is it true?
▼25.6.2
What is a greedy algorithm? Give an example.
▼25.6.3
If the Heap class in line 50 in Listing 25.9 is replaced by java.util.PriorityQueue, will the program still work?
▼25.6.4
How do you replace lines 94-99 in Listing 25.11 using one line?