Question

In: Computer Science

Create a subclass of BinaryTree whose nodes have fields for storing preorder, post-order, and in-order numbers....

  1. Create a subclass of BinaryTree whose nodes have fields for storing preorder, post-order, and in-order numbers. Write methods preOrderNumber(), inOrderNumber(), and postOrderNumbers() that assign these numbers correctly. These methods should each run in O(n) time.

Solutions

Expert Solution

Answer :

copyable code:

public class BTSubClass<Node extends BTSubClass.BTNode<Node,T>, T> extends

BinaryTree<Node>

class BTSubNode<Node extends BTSubNode<Node>,TT>extends BinaryTree.BTNode<Node> {

{

TT x;

int preOrdernum;

int postOrdernum;

int inOrdernum;

}

public static int poNum=0;

public static int pstNum=0;

public static int inNum=0;

protected Node newNode(T xx)

{

Node uu=super.newNode();

uu.x=xx;

preOrdernum=0;

postOrdernum=0;

inOrdernum=0;

return uu;

}

…….

//assign preorder number to nodes

public void preOrderNumber()

{

preOrderNumber(r);

}

public void preOrderNumber(Node rr)

{

if(rr!=nil)

{

poNum++;

rr.preOrdernum=poNum;

preOrderNumber(rr.left);

preOrderNumber(rr.right);

}

}

//assign postorder number to nodes

public void postOrderNumber()

{

postOrderNumber(r);

}

public void postOrderNumber(Node rr)

{

if(rr!=nil)

{

postOrderNumber(rr.left);

postOrderNumber(rr.right);

pstNum++;

rr.postOrdernum=pstNum;

}

}

//assign inorder number to nodes

public void inOrderNumber()

{

inOrderNumber(r);

}

public void inOrderNumber(Node rr)

{

if(rr!=nil)

{

inOrderNumber(rr.left);

inNum++;

rr.inOrdernum=inNum;

inOrderNumber(rr.right);

}

}

…….

}

NOTE : PLEASE GIVE ME UP VOTE. THANK YOU.


Related Solutions

Create a Binary Search Tree for the following data and do In-order, Preorder and Post-order traversal...
Create a Binary Search Tree for the following data and do In-order, Preorder and Post-order traversal of the tree. 50, 60, 25, 40, 30, 70, 35, 10, 55, 65, 5 Write an algorithm to delete a node in Singly Linked List                            [12 Write an algorithm of Binary Search                                                              [10] Write a program in ‘C’ to generate Fibonacci series using recursion            [8]
In your app.cpp file, create a demo illustrating a scenario where storing numbers in a linked...
In your app.cpp file, create a demo illustrating a scenario where storing numbers in a linked list is more efficient than an array. Your demo should generate a sufficiently large number of random integers and insert them into both the list, and the array. Your demo should also provide the time it took to complete the operations in the array, and in the linked list. It should show that the linked list was faster. app.cpp #include <iostream> #include <Array.h> #include...
C++ please Create a Stats class whose member data includes an array capable of storing 30...
C++ please Create a Stats class whose member data includes an array capable of storing 30 double data values, and whose member functions include total, average, lowest, and highest functions for returning information about the data to the client program. These are general versions of the same functions you created for Programming Challenge 7, but now they belong to the Stats class, not the application program. In addition to these functions, the Stats class should have a Boolean storeValue function...
A polymodal brain region is an association are whose neurons have receptive fields defined by MORE...
A polymodal brain region is an association are whose neurons have receptive fields defined by MORE THAN ONE sensory modality (e.g., vision, somatosensations or vision/hearing, etc.) Discuss the adaptive significance of the expansion of the polymodal regions PG and STS in humans compared to other primates.
Java basic sorting problem Supposed I have a simple array list storing the telephone numbers. How...
Java basic sorting problem Supposed I have a simple array list storing the telephone numbers. How can I sort the numbers in descending order with different ways? Give ArrayList<String> tel = ["11223344", "55442211", "99881122", "99002211", "34446666", "12342353"] I come up a solution using Collections.sort(tel), but it requires a compare method and I have no idea its contents and also the position of the method. Would you suggest 2 or 3 ways and write the code to achieve my purpose?
(JAVA) Create a program that takes in 15 numbers in sorted order from the console and...
(JAVA) Create a program that takes in 15 numbers in sorted order from the console and stores them in a 1D array of size 15. Next, prompt the user for a number to search for in the array (target). Then, print the array. Next, search the array using a linear search – printing out each of the indices (or “indexes”) that are being examined until the algorithm either finds the target or doesn’t. Then, do the same thing for a...
Create a class, called Song. Song will have the following fields:  artist (a string) ...
Create a class, called Song. Song will have the following fields:  artist (a string)  title (a string)  duration (an integer, recorded in seconds)  collectionName (a string) All fields, except for collectionName, will be unique for each song. The collectionName will have the same value for all songs. In addition to these four fields, you will also create a set of get/set methods and a constructor. The get/set methods must be present for artist, title, and duration....
Of all the numbers whose difference is 54, find the two that have the minimum product.
Of all the numbers whose difference is 54, find the two that have the minimum product.
Binary Tree Create a binary search tree using the given numbers in the order they’re presented....
Binary Tree Create a binary search tree using the given numbers in the order they’re presented. State if the resulting tree is FULL and/or BALANCED. 37, 20, 18, 56, 40, 42, 12, 5, 6, 77, 20, 54
n Java, Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have...
n Java, Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form realPart + imaginaryPart * i where i is square root of -1 Use floating-point variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. Provide a no-argument constructor with default values in case no initializers are provided. Provide public methods that perform the following operations: a)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT