Implement function boolean containsconsecutiveleftrededges

Assignment Help JAVA Programming
Reference no: EM131043984

Java Assignment

//
// LLRB --- L(eft)-L(eaning) R(ed)-B(lack) BST
//
// This class stores a set of integer keys using a left-leaning red-black BST
//
// HOMEWORK in this file is to implement:
//
// 1) public void insert()
// 2) public boolean containsRightRedEdge()
// 3) public boolean containsConsecutiveLeftRedEdges()
// 4) public int countBlackEdgesOnLeftmostPath()
// 5) public boolean sameBlackEdgesCountOnAllPaths(int count)
//
// As BONUS, there is one additional method to implement
//
// 1) public void fixLLRB()
//

package hw4;

public class LLRB {
private static final boolean RED = true;
private static final boolean BLACK = false;

public Node root;

public class Node {
public int key;
public boolean color;
public Node left, right;

public Node(int key, boolean color) {
this.key = key;
this.color = color;
}
}

// Constructor for LLRB
public LLRB() {
}

// Is parent link for node x red? false if x is null
private boolean isRed(Node x) {
if (x == null) return false;
return x.color == RED;
}

// Inserts a key without fixing the tree
public void bstInsert(int key) {
root = bstInsert(root, key);
}

// Recursive helper method for bstInsert
private Node bstInsert(Node x, int key) {
if (x == null) return new Node(key, RED);
if (key < x.key) x.left = bstInsert(x.left, key);
else if (key > x.key) x.right = bstInsert(x.right, key);
return x;
}

// Inserts a key fixing the red-black tree property
public void insert(int key) {
// TODO : complete this method
}

// Checks whether the tree contains a red right edge
public boolean containsRightRedEdge() {
// TODO : complete this method
return false;
}

// Checks whether the tree contains two left red edges in a row
public boolean containsConsecutiveLeftRedEdges() {
// TODO : complete this method
return false;
}

// Returns the maximum number of black edges (nodes) on any path from root to null
public int maxBlackEdgesDepth() {
// TODO : complete this method
return 0;
}

// Returns the minimum number of black edges (nodes) on any path from root to null
public int minBlackEdgesDepth() {
// TODO : complete this method
return 0;
}

// Checks whether the BST is a valid left leaning red-black tree
public boolean isValidLLRB() {
return (maxBlackEdgesDepth() == minBlackEdgesDepth() &&
!containsRightRedEdge() &&
!containsConsecutiveLeftRedEdges());
}

// Fixes the red-black tree if there is something to fix
public void fixLLRB() {
// TODO : complete this method
}
}

Attachment:- hw4.zip

Reference no: EM131043984

Questions Cloud

How much the underpricing is relative to the expected price : Calculate the price per share in the "good" state of the world, the price per share in the "bad" state of the world, and, hence, the expected price per share.
Create a presentation that includes your travel destination : Using the information that you gathered last week, create a PowerPoint presentation that introduces you, your employer (International Travel Company), and your travel destination.
Discuss the main reasons why a business : Discuss the main reasons why a business should or should not be involved in political discussions or take a political stand. Use terms found in Chapter 9 to demonstrate your understanding of the material.
Customer life time value in analyzing cases : How can one use breakeven market share and customoer life time value in analyzing cases? What is similar and different about them? (we have studied the cases such as Dove, Mountain Man Brewing Company, Circle K, Altius Golf)
Implement function boolean containsconsecutiveleftrededges : Implement the following functions- void insert(), boolean containsRightRedEdge(), boolean containsConsecutiveLeftRedEdges(), int countBlackEdgesOnLeftmostPath() and boolean sameBlackEdgesCountOnAllPaths(int count).
Employee management and business ethics : How is "just cause" and "due process' relevant to employee management and business ethics? Demonstrate your knowledge of these legal terms and justify your answer.  -Business Ethics, William H. Shaw
What are the roi and cost considerations : What are the ROI and cost considerations when considering one of these platforms? What are some of the best practices in implementing self-service applications and what are also some of the common errors?
Experience in airlines as a cargo officer : 1. What do you think about the results of Ms. Duckworth's research? 2. Were you surprised? 3. Do you have any personal experiences that support (or refute) her findings?
The standard normal curve to the left of these values : Calculate the area under the standard normal curve to the left of these values:a. z = -1.4 and z = 1.4b. z = -3.0 and z = 3.0

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a bag class with a generic type

Write a Bag class with a generic type. Write a class such as item that has a name and price. Add objects of item to the bag and find the average and the total of the price of all items in the bag.

  Use counting sort to sort an array

State the difficulty in attempting to use counting sort to sort an array of n floating-point numbers from the continuous interval [0,1].

  Convert the following expression to postfix

Convert the following expression to postfix. ( 5 * ( ( 9 * 8 ) + ( 7 * ( 4 + 6 ) ) ) )

  Write a java program that computes and prints the value

Write a Java program that computes and prints the value of 6!/5! using Scanner.

  Write a class named java1306cmis141c801 that performs the

write a class named java1306cmis141c801 that performs the following actions.prompt the user for an int between lower

  Declare another television object called portable

Add to the comment header as indicated at the top of the program.

  Once getting into student information menu

Once getting into student information menu, you should be able to see a full list of students' information (first name, last name, SSN, DOB, year and major).

  Difference between a java compiler and a java interpreter

Write a user-defined class called Person. This class should have private instance variables defined as:

  Procedural programming and object-oriented programming

What are the similarities between procedural programming and object-oriented programming? What are the differences between procedural programming and object-oriented programming

  Write a java program to read sequences of integers

Write a Java program to read sequences of integers from a text file, build a binary search tree for each sequence by inserting numbers in the sequence one after another into the search tree, and plot a picture of the finished tree.

  1 comparing portions of strings write an application that

1. comparing portions of strings write an application that uses string method region-matches to compare two strings

  Determine the precise big-oh values

Determine the precise Big-Oh values for each of the following code samples, based on the number of statement executions - Remember to consider each statement in compound statements separately.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd