(a) Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(a) Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, and 2, one at a time and in the giver order, into an initially empty binary min heap. (b) Show the result of performing three deleteMin operations in the heap of the previous binary min heap. (c) Write a method replaceKey in the MinHeap class with the following signature: public void replaceKey(Integer oldKey, Integer newKey) The method will replace the first occurrence of oldKey with the newKey, and restore the Min-Heap property after the change. If the oldKey does not exist in the heap, the method prints an appropriate message and returns without changing the heap. Example: Suppose our binary heap object (bh) has the following keys: *** 4 6 7 32 19 64 26 99 42 54 28 Then the method call: bh.replaceKey (oldKey Integer(54), newKey Integer(2)) should change the keys to: *** 2 4 7 32 6 64 26 99 42 19 28 Note: You can assume that the methods perlocateUp and perlocateDown are already implemented in your MinHeap class. (d) What is the running time complexity of your replaceKey method? Justify (e) Consider an initially empty max-heap, where the following keys are to be inserted one at a time: 11, 19, 23, 12, 13, 17, 13, 14, 18, and 33. Draw the tree that results after building this max-heap. (f) Is it possible to find the maximum in a min-heap with N integer nodes in O(logn) time? Justify. Important Notes: For this problem, you have only one Java implementation in part (c). In this part you need to submit only the implementation of the replaceKey method. For parts (a), (b), and (e) of this problem, you must draw the min (or max) heaps using the appropriate graphics tools at your convenience. Heaps that were drawn by hand will be not accepted. (a) Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, and 2, one at a time and in the giver order, into an initially empty binary min heap. (b) Show the result of performing three deleteMin operations in the heap of the previous binary min heap. (c) Write a method replaceKey in the MinHeap class with the following signature: public void replaceKey(Integer oldKey, Integer newKey) The method will replace the first occurrence of oldKey with the newKey, and restore the Min-Heap property after the change. If the oldKey does not exist in the heap, the method prints an appropriate message and returns without changing the heap. Example: Suppose our binary heap object (bh) has the following keys: *** 4 6 7 32 19 64 26 99 42 54 28 Then the method call: bh.replaceKey (oldKey Integer(54), newKey Integer(2)) should change the keys to: *** 2 4 7 32 6 64 26 99 42 19 28 Note: You can assume that the methods perlocateUp and perlocateDown are already implemented in your MinHeap class. (d) What is the running time complexity of your replaceKey method? Justify (e) Consider an initially empty max-heap, where the following keys are to be inserted one at a time: 11, 19, 23, 12, 13, 17, 13, 14, 18, and 33. Draw the tree that results after building this max-heap. (f) Is it possible to find the maximum in a min-heap with N integer nodes in O(logn) time? Justify. Important Notes: For this problem, you have only one Java implementation in part (c). In this part you need to submit only the implementation of the replaceKey method. For parts (a), (b), and (e) of this problem, you must draw the min (or max) heaps using the appropriate graphics tools at your convenience. Heaps that were drawn by hand will be not accepted.
Expert Answer:
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
What is the future value of the following cash flows, given an appropriate discount rate of 7.74% (to the nearest penny)? Year 1 Year 2 Year 3 Year 4 Year 5 $2,005 $4,054 $6,159 $8,532 $11,985
-
Guillemette Gounod is CEO of the Gounod Corporation, a manufacturer of smartcards and electronic personal identification devices. As chair of the annual meeting of shareholders she is reporting on...
-
For two events A and B, the following probabilities are given. P(A) = A P(B) = .25 P(A|B) = .7 Use the appropriate laws of probability to calculate (a) P() (b) P(AB) (c) P(A U B)
-
Compare and contrast monogamy, polygyny, and polyandry and give examples of each.
-
Carrie D'Lake, Reed A. Green, and Doug A. Divot share a passion for golf and decide to go into the golf club manufacturing business together. On January 2, 2015, D'Lake, Green, and Divot form the...
-
7. Consider the following data set of training exames Attribute Distinguishing Attribute Noise Attribute A1 A2 1 Records B1 Class A Class B B2 (a) How does Nave Bayes perform on this data set with...
-
Ybankhasofferedyoua10000005yearloanataninterestrateof115 requiring equal annual endofyear payments that include both principal and interest on the unpaid balance Develop an amortization schedule for...
-
A $1,000 par value 10-year bond with annual coupons is redeemable at $1,055, and has a purchase price of $986 at a yield rate of 4% per annum. The coupons are non-level and increase by $2 per year....
-
Suppose a stock index contains the stock of 3 firms: A, B and C. The stock prices for the three firms are $29. $53 and $72, respectively. The firms have 153 million, 191 million and 91 million shares...
-
Super Toys are planning to market one of three new superhero toys. The company estimates that potential profit, given one of the three economic situations, is as follows: Recession Stable R'000...
-
The cash-flow diagram is provided. a. If P = $2,000, A = $250, and i% = 9% per year, then N = ? b. If P = $2,000, A = $250, and N= 8 years, then i = ? c. If A = $250, 1% = 9% per year, and N=4 years,...
-
Assume the following for the town of Boone: The town has a total population of 40,000 people, of which 4,000 are under 16 years of age or are institutionalized; 5,000 are full-time students who are...
-
Reviews and comments plays major role in any e commerce industry. As we have pretty good reviews regarding the delivery. And recently we got bad reviews regarding refunds for a customer, its taking...
-
Data 9.2 on page 540 introduces the dataset Cereal, which includes information on the number of grams of fiber in a serving for 30 different breakfast cereals. The cereals come from three different...
-
Find the response of the system described in Example 2.1 using Eq. (2.23). Data From Example 2.1:- Equation 2.23:- An undamped single-degree-of-freedom system has a mass of 1 kg and a stiffness of...
-
Describe how the phase angle \(\phi_{0}\) in Eq. (2.23) is to be computed for different combinations of positive and negative values of the initial displacement \(\left(x_{0} ight)\) and the initial...
-
Find the response of the system described in Problem 2.59 using Eq. (2.23). Data From Problem 2.59:- An undamped single-degree-of-freedom system consists of a mass \(5 \mathrm{~kg}\) and a spring of...
Study smarter with the SolutionInn App