Write a program in Java that implements the Rooted Tree with Unbound Branching:
ID: 664709 • Letter: W
Question
Write a program in Java that implements the Rooted Tree with Unbound Branching: a) This tree should support multiple children nodes (not just binary tree), with the left-child right-sibling scheme b) The program should support a search method that can locate the first instance of the node that holds the given key and returns true if the node is found c) There should be an insert method that takes a parent node (key value) and the node to be inserted as arguments: public void insert(Node parent, Node child) d) If the parent node does not have a child, then the new node becomes the leftchild. Otherwise, it becomes the right-most child of the parent node (i.e., insert at the end) e) Test your program by building a tree with 3 levels: a. Use the insert method to build the tree. Call this method several times with the proper parent and child nodes as arguments. b. Root node has key = 100, and it has 4 children with keys 200, 300, 400, and 500 (node 200 is the left-child) c. The node 200 has 3 children with keys 210, 220, and 230 d. The node 300 has 1 child with key 310 e. The node 400 has 2 children with keys 410 and 420 f. The node 500 has 3 children with keys 510, 520, and 530 g. Use the search method to search for node 220 and node 520. Display the results.
Explanation / Answer
Rooted trees with unbounded branching
The scheme for this property representing a binary tree can be extended to any class of trees in which the number of children of each and every node is at most some constant k: we replace the left and right fields by child1, child2,..., childk. This scheme now no longer works when the number of children of a node is unbounded, since we do not know how many ever fields (arrays in the multiple-array representation) to allocate in advance. Moreover, even if the number of children k always is bounded by a large constant but most nodes have a small number of children, we may waste a lot of memory is the final conclusion.
Have given a program to implement the rooted tree :
Dont have much to tell on unbounded branching.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.