Our implementation of the treeSearch utility, from Code Fragment 11.3, relies on recursion. For a large unbalanced
Question:
Transcribed Image Text:
1 /** An implementation of a sorted map using a binary search tree. */ 2 public class TreeMap
1 /** An implementation of a sorted map using a binary search tree. */ 2 public class TreeMap extends AbstractSortedMap { // To represent the underlying tree structure, we use a specialized subclass of the // LinkedBinary Tree class that we name BalanceableBinary Tree (see Section 11.2). protected BalanceableBinary Tree tree = new BalanceableBinary Tree<>(); /** Constructs an empty map using the natural ordering of keys. */ public TreeMap() { super(); tree.addRoot(null); } /** Constructs an empty map using the given comparator to order keys. */ public TreeMap(Comparator comp) { super(comp); tree.addRoot(null); / the AbstractSortedMap constructor // create a sentinel leaf as root 9. 10 11 12 13 // the AbstractSortedMap constructor // create a sentinel leaf as root 14 15 16 /** Returns the number of entries in the map. */ public int size() { return (tree.size() – 1) / 2; } /** Utility used when inserting a new entry at a leaf of the tree */ private void expandExternal(Position> p, Entry entry) { tree.set(p, entry); tree.addLeft(p, null); tree.addRight(p, null); 17 18 // only internal nodes have entries 19 20 21 22 // store new entry at p // add new sentinel leaves as children 23 24 25 26 27 // Omitted from this code fragment, but included in the online version of the code, // are a series of protected methods that provide notational shorthands to wrap // operations on the underlying linked binary tree. For example, we support the // protected syntax root() as shorthand for tree.root() with the following utility: protected Position> root() { return tree.root(); } 28 29 30 31 32 33 /** Returns the position in p's subtree having given key (or else the terminal leaf).*/ private Position> treeSearch(Position> p. K key) { if (isExternal(p)) return p; int comp = compare(key, p.getElement()); if (comp 34 35 36 // key not found; return the final leaf 37 38 39 // key found; return its position 40 return p: else if (comp < 0) return treeSearch(left(p), key); else 41 // search left subtree 42 43 // search right subtree return treeSearch(right(p), key); } 44 45
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 61% (13 reviews)
private Position treeSearchPosition p K key Position walk p while i...View the full answer
Answered By
Mamba Dedan
I am a computer scientist specializing in database management, OS, networking, and software development. I have a knack for database work, Operating systems, networking, and programming, I can give you the best solution on this without any hesitation. I have a knack in software development with key skills in UML diagrams, storyboarding, code development, software testing and implementation on several platforms.
4.90+
97+ Reviews
194+ Question Solved
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Question Posted:
Students also viewed these Computer science questions
-
Consider lines 3133 of Code Fragment 10.8 in our implementation of the class ChainHashMap. We use the difference in the size of a secondary bucket before and after a call to bucket.remove(k) to...
-
If the outermost while loop of our implementation of quickSortInPlace (line 9 of Code Fragment 12.6) were changed to use condition left < right, instead of condition left /** Sort the subarray S[a.b]...
-
In our implementation of the scale function (page 25), the body of the loop executes the command data[j] *= factor. We have discussed that numeric types are immutable, and that use of the *= operator...
-
You are looking at buying a piece of real estate and you intend to borrow as much as you possibly can from a bank to buy the property. The bank you are dealing with has a requirement that the LVR for...
-
Mercury Company has only one inventory pool. On December 31, 2018, Mercury adopted the dollar-value LIFO inventory method. The inventory on that date using the dollar-value LIFO method was $200,000....
-
What documents trigger and support batch processing systems?
-
Recommend a technique that Family Services can use to evaluate how much of their time is being spent on a relatively few number of clients. LO.1
-
Gottschalk Company sponsors a defined benefit plan for its 100 employees. On January 1, 2017, the company's actuary provided the following information. Accumulated other comprehensive loss...
-
QUESTION 8 Narrative 9-1 Workers are paid on a differential piecework schedule as follows: Pay Level Units Produced Rate per Unit 1 1-50 $2.82 2 51-100 $3.05 101-150 $3.55 4 over 150 $4.30 Refer to...
-
Consider the following facts to quantify the tax costs of various taxable acquisition structures when the target is a freestanding C corporation. Wolverine, Inc., wants to purchase Reel Deal, Inc.,...
-
Is the search tree of Figure 11.22(a) a (2,4) tree? Why or why not? Figure 11.22(a) 22 5 10 25 3 4 23 24 6 8 14 27 11 13 17 (a)
-
Dr. Amongus claims that the order in which a fixed set of entries is inserted into an AVL tree does not matterthe same AVL tree results every time. Give a small example that proves he is wrong.
-
Consider the demand for park visitation, Eq. (9.12b). a. We discussed (and illustrated in Figure 9.5) the effect of a change in \(q\) on demand for visits, \(v\). How would you expect the other...
-
(a) Draw a simplified ray diagram showing the three principal rays for an object located inside the focal length of a converging lens, closer to the lens than to the focal point. (b) Is the image...
-
Power efficiency has become very important for modern processors, particularly for embedded systems. Create a version of gcc for two architectures that you have access to, such as x86, RISC-V,...
-
There is a movement toward wireless mobile computing using thin-client technology. Go to the Web and visit some of the ma jor computer vendors that are producing thin-client products such as handheld...
-
Draw a B-tree of order 4 and height 3 containing the fewest elements. Show an example of a split that would be applied by inserting the fewest number of elements.
-
Repeat Example 10-4, except calculate the diameter at the bottom of the column. Example 10-4 A distillation column is separating n-hexane from n-heptane using 1-in. ceramic Intalox saddles. The...
-
In exercises find the derivative of the function by the limit process. 2 h(s) = 3 + s
-
Kims Konstructions has assembled the following data for a proposed straw-reinforced brick maker (SRBM): SRBM Cost: $26,000 Life: 5 years Revenue (p.a.) $11,000 Operating Expenses (p.a.) $3,000...
-
We can improve the running time of quicksort in practice by taking advantage of the fast running time of insertion sort when its input is "nearly" sorted. Upon calling quicksort on a subarray with...
-
Consider a sorting problem in which we do not know the numbers exactly. Instead, for each number, we know an interval on the real line to which it belongs. That is, we are given n closed intervals of...
-
Argue that for any constant 0 < 1/2, the probability is approximately 1 - 2 that on a random input array, PARTITION produces a split more balanced than 1 to .
-
Use the following information: \ table [ [ Country , \ table [ [ Consumer Prices ] ] , Interest Rates,Current Units ( per US$ ) ] , [ Forecast , 3 - month, 1 - yx Covt Bond,, ] , [ 2 0 2 4 e ,...
-
Year-to-date, Yum Brands had earned a 3.70 percent return. During the same time period, Raytheon earned 4.58 percent and Coca-Cola earned 0.53 percent. If you have a portfolio made up of 40 percent...
-
Rate of Return If State Occurs State of Probability of Economy State of Economy Stock A Stock B Stock C Boom .15 .31 .41 .21 Good .60 .16 .12 .10 Poor .20 .03 .06 .04 Bust .05 .11 .16 .08 a. Your...
Study smarter with the SolutionInn App