1. Give a complete justification of Proposition 12.1.2. In the merge-sort tree shown in Figures 12.2 through 12.4, some edges are drawn as arrows. What is the meaning of a downward arrow? How about...
Recent Questions
1. The boolean indicator used to mark nodes in a red-black tree as being “red” or “black” is not strictly needed when we have distinct keys. Describe a scheme for implementing a red-black tree...
1. Draw a splay tree, T1, together with the sequence of updates that produced it, and a red-black tree, T2, on the same set of ten entries, such that a preorder traversal of T1 would be the same as...
Describe a modification to the binary search-tree data structure that would support the following two index-based operations for a sorted map in O(h) time, where h is the height of the...
If we maintain a reference to the position of the leftmost node of a binary search tree, then operation firstEntry can be performed in O(1) time. Describe how the implementation of the other map...
1. Show that at most one node in an AVL tree becomes temporarily unbalanced after the immediate deletion of a node as part of the standard remove map operation.2. In our AVL implementation, each...
1. Draw a schematic of an AVL tree such that a single remove operation could require Ω(logn) trinode restructurings (or rotations) from a leaf to the root in order to restore the height-balance...
If the approach described in the previous problem were implemented as part of the TreeMap class, what additional modifications (if any) would be necessary to a subclass such as AVLTreeMap in order...
Suppose we wish to support a new method countRange(k1, k2) that determines how many keys of a sorted map fall in the specified range. We could clearly implement this in O(s + h) time by adapting our...
Repeat the previous problem using an AVL tree, achieving a running time of O(slogn). Why doesn’t the solution to the previous problem trivially result in an O(s+logn) algorithm for AVL...
1. Let T be a red-black tree storing n entries, and let k be the key of an entry in T. Show how to construct from T, in O(logn) time, two red-black trees T′ and T′′, such that T′ contains all the...
Consider a sorted map that is implemented with a standard binary search tree T. Describe how to perform an operation removeSubMap(k1, k2) that removes all the entries whose keys fall within...
1. Show that any n-node binary tree can be converted to any other n-node binary tree using O(n) rotations.2. For a key k that is not found in binary search tree T, prove that both the greatest key...
1. Can we use a splay tree to sort n comparable elements in O(nlogn) time in the worst case? Why or why not?2. Implement a putIfAbsent method, as originally described in Exercise C-10.33, for the...
1. Explain why you would get the same output in an inorder listing of the entries in a binary search tree, T, independent of whether T is maintained to be an AVL tree, splay tree, or red-black...
1. Draw an example of a red-black tree that is not an AVL tree.2. Give a proof of Proposition 11.93. Give a proof of Proposition 11.10
Consider a tree T storing 100,000 entries. What is the worst-case height of T in the following cases?a. T is a binary search tree.b. T is an AVL tree.c. T is a splay tree.d. T is a (2,4) tree.e. T...
For the following statements about red-black trees, provide a justification for each true statement and a counterexample for each false one.a. A subtree of a red-black tree is itself a red-black...
Consider the sequence of keys (5,16,22,45,2,10,18,30,50,12,1). Draw the result of inserting entries with these keys (in the given order) intoa. An initially empty (2,4) tree. b. An initially empty...
1. Draw four different red-black trees that correspond to the same (2,4) tree.2. Consider the set of keys K = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}.a. Draw a (2,4) tree storing K as its keys using...
In Section 11.1.4 we claim that the subMap method of a binary search tree, as implemented in Code Fragment 11.6, executes in O(s + h) time where s is the number of entries contained within the...
1. An alternative way of performing a split at a node w in a (2,4) tree is to partition w into w′ and w′′, with w′ being a 2-node and w′′ a 3-node. Which of the keys k1, k2, k3, or k4 do we store at...
1. What does a splay tree look like if its entries are accessed in increasing order by their keys?2. Perform the following sequence of operations in an initially empty splay tree and draw the tree...
The rules for a deletion in an AVL tree specifically require that when the two subtrees of the node denoted as y have equal height, child x should be chosen to be “aligned” with y (so that x and y...
Repeat the previous problem, considering the case in which y’s children start with different heights.Exercises R-11.11Consider a deletion operation in an AVL tree that triggers a trinode...
1. Explain why performing a rotation in an n-node binary tree when using the arraybased representation of Section 8.3.2 takes Ω(n) time.2. Consider a deletion operation in an AVL tree that triggers...
Draw the AVL tree resulting from the removal of the entry with key 62 from the AVL tree of Figure 11.13b.Figure 11.13b
Draw the AVL tree resulting from the insertion of an entry with key 52 into the AVL tree of Figure 11.13b.Figure 11.13b
Does the trinode restructuring in Figure 11.11 rely on a single or double rotation? What about the restructuring in Figure 11.13?Figure 11.11 Figure 11.13
1. Dr. Amongus claims that the order in which a fixed set of entries is inserted into an AVL tree does not matter—the same AVL tree results every time. Give a small example that proves he is...
1. The splay tree does not have good performance for the sorted map operations, because those methods lack calls to the rebalanceAccess hook. Reimplement TreeMap to include such calls.2. Is the...
1. How many different binary search trees can store the keys {1,2,3}?2. Dr. Amongus claims that the order in which a fixed set of entries is inserted into a binary search tree does not matter—the...
Write a spell-checker class that stores a lexicon of words, W, in a set, and implements a method, check(s), which performs a spell check on the string s with respect to the set of words, W. If s is...
1. Extend the previous project by providing a graphical animation of the skip-list operations. Visualize how entries move up the skip list during insertions and are linked out of the skip list...
1. Perform a comparative analysis as in the previous exercise, but for 10-digit telephone numbers instead of character strings.2. Design a Java class that implements the skip-list data structure....
Perform a comparative analysis that studies the collision rates for various hash codes for character strings, such as polynomial hash codes for different values of the parameter a. Use a hash table...
Perform experiments on our ChainHashMap and ProbeHashMap classes to measure its efficiency using random key sets and varying limits on the load factor (see Exercise R-10.14).Exercise R-10.14Our...
Implement a LinkedHashMap class, as described in Exercise C-10.44, ensuring that the primary map operations run in O(1) expected time.Exercise C-10.44The java.util.LinkedHashMap class is a subclass...
An interesting strategy for hashing with separate chaining is known as powerof-two-choices hashing. Two independent hash functions are computed for each key, and a newly inserted element is placed...
An interesting strategy for hashing with open addressing is known as cuckoo hashing. Two independent hash functions are computed for each key, and an element is always stored in one of the two cells...
Recent Comments