Write a method for the RedBlackTree class of Worked Example 17.2 that checks that the tree fulfills
Question:
Write a method for the RedBlackTree class of Worked Example 17.2 that checks that the tree fulfills the rules for a red-black tree.
Data from worked example 17.2
The code for fixing up a double-red violation is quite long. Recall that there are four possible arrangements of the double red nodes:
Transcribed Image Text:
WORKED EXAMPLE 17.2 Implementing a Red-Black Tree Problem Statement Implement a red-black tree using the algorithm for adding and removing elements from Section 17.5. Read that section first if you have not done so already. The Node Implementation The nodes of the red-black tree need to store the "color", which we represent as the cost of traversing the node: static final int BLACK = 1; static final int RED = 0; private static final int NEGATIVE RED = -1; private static final int DOUBLE BLACK = 2; static class Mode { public Comparable data; public Node left; public Node right; public Node parent; public int color; } The first two color constants and the Mode class have package visibility. We will add a test class to the same package, which is discussed later in this worked example. Nodes in a red-black tree also have a link to the parent. When adding or moving a node, it is important that the parent and child links are synchronized. Because this synchronization is tedious and error-prone, we provide several helper methods: public class RedBlackTree { static class Mode {
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 0% (2 reviews)
Answered By
Leah Muchiri
I am graduate in Bachelor of Actuarial Science and a certified accountant. I am also a prolific writer with six years experience in academic writing. My working principle are being timely and delivering 100% plagiarized free work. I usually present a precised solution to every work am assigned to do. Most of my student earn A++ GRADE using my precised and correct solutions.
4.90+
52+ Reviews
125+ Question Solved
Related Book For
Question Posted:
Students also viewed these Java Programming questions
-
Reimplement the remove method in the RedBlackTree class of Worked Example 17.2 so that the node is first removed using the binary search tree removal algorithm, and the tree is rebalanced after...
-
Implement an iterator for the RedBlackTree class in Worked Example 17.2 that visits the nodes in sorted order. Take advantage of the parent links. Data from worked example 17.2. The code for fixing...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
In Exercises find the vertex, focus, and directrix of the parabola, and sketch its graph. x 2 + = 0
-
An inventor claims to have developed a heat engine that receives 700 kJ of heat from a source at 500 K and produces 300 kJ of net work while rejecting the waste heat to a sink at 290 K. Is this a...
-
Write a program segment that displays the contents of a previously declared array of strings called Names. Assume that the last entry in Names is "ZZZ", which should not be displayed.
-
Barbara Vigil, Chief Justice, New Mexico Supreme Court Ken Badilla bought a pair of Brahma brand work boots from Wal-Mart on October 19, 2003. The boots packaging had these express descriptions: iron...
-
Jalapenos! is based in Pleasant Hill, California. The merchandising company has three divisions: Clothing, Food, and Spices. The Clothing division has two main product lines: T-shirts and...
-
On the first day of their vacation the Morales family drove 312 miles in 6 hours at that rate how far will they travel the next day if they drive for 8 hours
-
As a preliminary to requesting budget estimates of sales, costs, and expenses for the fiscal year beginning January 1, 20Y9, the following tentative trial balance as of December 31, 20Y8, is prepared...
-
Modify the implementation of the MinHeap class so that the parent and child index positions and elements are computed directly, without calling helper methods.
-
Implement an inorder method for the BinaryTree class of Section 17.2 so that it stops visiting when the visit method returns false. ( Have inorder return false when visit returns false.)
-
What is the Ka of HCN is its pKa = 9.31?
-
What is the level of assurance required for an annual financial statement for a reporting issuer?
-
What is a debt covenant?
-
Explain how internal performance reports may be used.
-
One of the most difficult problems facing management is that of how to minimize the transition time between changeover from a purely traditional organizational form to a project organizational form....
-
From an executive perspective, which of the following are the major benefits of a Critical Chain approach? a. Improved cash flow b. Less time to review major projects, with better reporting c. More...
-
Draw a breakeven chart to illustrate lowering price.
-
Following is the current balance sheet for a local partnership of doctors: The following questions represent independent situations: a. E is going to invest enough money in this partnership to...
-
What are the advantages to using object-oriented techniques?
-
You are probably wearing on your wrist one of the worlds most common types of objects a watch. Discuss how each of the following terms and concepts applies to the notion of a watch: object,...
-
What is the key accomplishment of the UML?
-
5 Woof pic manufactures one product, a luxury dog food which sells at 20. Calculate the following values from the last six months results ending 30 April: Month January February March April May June...
-
Credit Card B (For Clothes) $ 5,000 Nate's Student Loan Balance (Federal) $55,000 Cash on Hand $ 1,200 Personal Property $ 3,000 Credit Card D (For Misc. Items) $ 2,100 Nate's - Car Loan Balance...
-
A company launched business App. For smart mobile phones, the users who installed the app. in 2 0 1 4 were 1 4 2 0 0 0 users, and they increase by 1 0 % each succeeding year. a ) Determine the number...
Study smarter with the SolutionInn App