Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Implement a binary tree using array as underline storage
+ root at index 1, 
+ left child at parent's (index * 2)
+ right child at patent's (index * 2 + 1)
+ parent is at child's (index / 2)

1. building a binary tree using array
2. implement tree traversals: pre-order, in-order, post-order, level-order
3. implement insert method that insert the element in the order of insertion

[
4. modify the insert method so the tree is a BST
5. add a method called "contains" to search for an element in the tree
6. add methods findMin and findMax 
]

*/


I am stuck can you help me to complete the implementation

public class ArrTree {
public static int DEFAULT_SIZE = 20;
//constructors
public ArrTree(){
this.buffer = new int[DEFAULT_SIZE];
this.size = 0;
}
public ArrTree(int n){ //create a tree with the given size n
this.buffer = new int[n+1];
this.size = 0; //empty tree
}

//mutators
public boolean insert(int v){
if(this.size < this.buffer.length){
this.buffer[++this.size] = v;
return true;
}
return false; // cannot insert the value
}

//methods

//traverse the tree in-order fashion - this is the interface for the user
public String preOrder(){
return doPreOrder(1); //start at the root
}

//this is the actual code handling the pre-order traversal
private String doPreOrder(int v){
if(v <= this.size){
return this.buffer[v] + " " +
doPreOrder(v*2) +
doPreOrder(v*2+1);

}else{ //nothing to do ==> extends out of the leaf
return "";
}
}

//attributes
private int buffer[];
private int size;

//===================================
//Driver to test the tree
public static void main(String[] args){

ArrTree t = new ArrTree(50);
for(int i = 0; i < 10; i++)
t.insert(i);

System.out.println(t.preOrder());

}
}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M981573

Have any Question?


Related Questions in Computer Engineering

With regards to data mining business analytics why is it

With regards to data mining/ business analytics, Why is it not ideal to evaluate a classifier's performance on the training data set?

Switches are an integral part of networks they are the

Switches are an integral part of networks. They are the devices you utilize for host connectivity to the network. Please identify and discuss an attack that takes advantage of a weakness in switches.

Wat are three 3 major categories of cyber terrorism and

What are three (3) major categories of cyber terrorism and / or information warfare. Among the chosen categories, determine the one (1) that should be the top priority for the federal government to address.

Question three academically reviewed articles on management

Question: Three academically reviewed articles on Management Information Systems and complete the following activities: 1. Summarize all three (3) articles in 600 words or more in APA format with reference 2. Discuss at ...

Doolittle co is expected to pay a dividend of 23 next year

Doolittle Co. is expected to pay a dividend of $2.3 next year. Doolittle is expected to pay 20% of its earnings as dividends and will have an ROE of 9% until the fourth year. After that, its ROE is expected to decrease t ...

Question can someone send me a complete produce a project

Question : Can someone send me a complete produce a project plan which results in the development of a major software product to solve a customer problem, for a Course Registration System.

Can someone design a small program for me in java that do

Can someone design a small program for me in Java that do the following: Implement at least four classes (showing inheritance) with suitable constructors and methods to set/retrieve values of from the properties. Try to ...

Describe how to discover cookies on web browsers what is a

Describe how to discover cookies on web browsers. what is a reverse DNS lookup and can it be used when attacking the network.

Shellys preferences for consumption and leisure can be

Shelly's preferences for consumption and leisure can be expressed as U(C, L) = (C - 100) (L - 40). This utility function implies that Shelly's marginal utility of leisure is C - 100 and her marginal utility of consumptio ...

Suppose that you sample 59 high school baseball pitchers in

Suppose that you sample 59 high school baseball pitchers in one county and find that they have a mean fastball pitching speed of 80.00 miles per hour (mph) with a standard deviation of 4.98 mph. Find a 95% confidence int ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As