(30 pts) A binary search tree is given, write a method to delete a node from...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(30 pts) A binary search tree is given, write a method to delete a node from the tree. Assume the successor and predecessor methods are provided, partial code is provided below. Finish the reset of the code in the blanks. public Blade deleteNode( BNode coat Comparable e) { if(root == null) return root; if (coat.getData().compareTo((Integer) e) > 0) { //move left caat left = }else if(caat getData().compareTo((Integer) e) < 0) { //move right Cat.cight = deleteNode(coetudeft, e); deleteNode(coat.right, e); if(castleft == null && coat tight == null){ //its a leaf else{ //oh yes, we finally found the target node; easy peasy else if(coot right != null){ // oh, it has a right child, don't make it an orphan or is it old enough to become a parent ? lets find out }else{ //oh it seems that I do not have a worthy successor, fallback, fallback } } } return root; private int successor (Bode, root) { root caturight; while(root left != null) { } } root = coat left; return (Integer) root getData(); private int predecessor (BNode root) { } root = coat left; while(coat cight != null) { root castights return (Integer) coat.getData(); } (30 pts) A binary search tree is given, write a method to delete a node from the tree. Assume the successor and predecessor methods are provided, partial code is provided below. Finish the reset of the code in the blanks. public Blade deleteNode( BNode coat Comparable e) { if(root == null) return root; if (coat.getData().compareTo((Integer) e) > 0) { //move left caat left = }else if(caat getData().compareTo((Integer) e) < 0) { //move right Cat.cight = deleteNode(coetudeft, e); deleteNode(coat.right, e); if(castleft == null && coat tight == null){ //its a leaf else{ //oh yes, we finally found the target node; easy peasy else if(coot right != null){ // oh, it has a right child, don't make it an orphan or is it old enough to become a parent ? lets find out }else{ //oh it seems that I do not have a worthy successor, fallback, fallback } } } return root; private int successor (Bode, root) { root caturight; while(root left != null) { } } root = coat left; return (Integer) root getData(); private int predecessor (BNode root) { } root = coat left; while(coat cight != null) { root castights return (Integer) coat.getData(); }
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
How is the claim amount calculated in a personal auto insurance policy if the policyholder's car is declared a total loss? How is the claim amount calculated in a personal auto insurance policy if...
-
The program BSTTesting.java in the src folder gives you a main method that you can use for testing your methods. The program provides a set of calls to build a tree and display values - use it to...
-
see below questions and provide me adjusted coding by using my coding. I share my coding and test failure message at the end. 1. BST.java 2.BSTNode.java Binary Search Tree you will be coding the...
-
Presented here are summarized data from the balance sheets and income statements of Wiper Inc.: WIPER INC. Condensed Balance Sheets December 31, 2020, 2019, 2018 (in millions) 2020 2019 Current...
-
Zero Corporation contributes inventory (computers) to State University for use in its mathematics program. The computers have a $1,225 cost basis and an $2,800 FMV. How much is Zeros charitable...
-
"Service with a smile" is a slogan that many businesses adhere to. However, there are some jobs (e.g., those of judges, law enforcement officers, pollsters) that require neutrality when dealing with...
-
BOP and Inflation. What are the direct and indirect relationships between the balance of payments and inflation?
-
Wayne Casting, Inc., produces a product made from a metal alloy. Wayne buys the alloy from two different suppliers, Chillicothe Metals and Ames Supply, in approximately equal amounts because of...
-
What are the values of and for the provided sampling distribution of the sample mean? Click here to view the sampling distribution of the sample mean. OA. H=10, =410 OB. H=410, = 20 OC. H=410, = 10...
-
Winning the lottery is only a dream for most - a one in a hundred million chance. However, what if you did win say $500 million dollars, might you consider giving $100 million to Penn State? The...
-
How do non-coding RNAs, such as long non-coding RNAs and microRNAs, participate in chromosomal organization and gene regulation, and what are their functional roles in chromatin remodeling and...
-
Beginning work-in-process inventory $70,000 Ending work-in-process inventory $40,000 Beginning finished goods inventory $160,000 Ending finished goods inventory $140,000 Cost of goods manufactured...
-
Most of us were taught right and wrong by a parent, sibling, friend, teacher, or other family members. We all have a framework for our value system, moral behavior, principles, and how we live our...
-
1.If you were to interview someone for an international business executive position, what are three questions you think it would be necessary to ask? Explain your reasoning.
-
Consider a force field F(x, y) = 3yi - xyj acting over the curve C given in the figure below. (-4,1) L (0,5) A (3,2) a) Show that the force field F is not conservative. b) Compute the work done by...
-
Distinguish the leadership skills and qualifications required to govern organizations. How can physicians play a key role in the governance of an organization? Describe the structures of the...
-
Transform the while loop from the previous exercise into an equivalent for loop (make sure it produces the same output).
-
The April 17, 2001, issue of the Wall Street Journal includes an article by James Bandler and Mark Maremont entitled "How Xerox's Plan to Reduce Taxes While Boosting Earnings Backfired." Instructions...
-
Ann Osborne recently graduated from college with a degree in landscape architecture. Her father runs a tree, shrub, and perennial-flower uursery, and her brother has a business delivering lopsoil,...
-
Net income is $132,000. During the year,counts payable increased $10,000, inventory decreased $6,000, and accounts receivable in- creased $12,000. Under the indirect method, net cash provided by...
Study smarter with the SolutionInn App