Question: Implement your class DrawTree using Java APT: Drawing Trees Problem Statement Given a tree, you are to return a representation of that tree as a

![a string 1]. The tree will be specified by public class Drawtree](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3152d62c3a_70166f3152d024bc.jpg)
APT: Drawing Trees Problem Statement Given a tree, you are to return a representation of that tree as a string 1]. The tree will be specified by public class Drawtree t a int[], where element i gives the index publie string[] draw (int[] parents, String[] names) of the parent of node i (indexed from 0 ). /1.111 in code here Exactly one element of this int [] will be 1, corresponding to the root of the tree. Element i of the int [] corresponds to element i of names, which gives the name of node i. The string[1 you return should have the root on the first line. Following the root, add elements to the return one subtree at a time. The subtrees should be sorted by the indices of their roots and drawn in the same way as the whole tree. However, the root of each subtree should be indented two more characters than its parent. After indenting, each node should be indicated by a plus ' + ', a minus ' ' , and then the name of the node from names. The plusses of siblings should be connected by vertical pipes 'I' as shown in the examples. For example, the tree given by the input: parents={1,0,1,1,0,0,5,5}names={"Root",5UbB","LEAF1","LEAF2","LEAF3","SUbA","LEAF4","LEAF5"} would result in the following return. +-Root+-SubB+-LEAF1+-LEAF2+-LRAF3+-SUbA+-LEAF4+-LEAF5 See the examples for more illustrations of exactly how this works. Constraints - parents will represent a tree: exactly one element will be 1, there will be no cycles, and all but one of the entries will refer to other elements of parents. - parents will contain between 1 and 50 elements, inclusive. 1. {1,0,1,1,0,0,5,5} {"Root","SUbB","LEAF1","LEAF2","LEAF3","SUbA","LEAF4","LeAF5"} Returns: 1"t-Root", +SubB ", +-LEAF 1 ", +-LEAF2", +-LEAF3", +SubA, +-LRAF 4 ", +-LEAF5 " } 2. {1,2,3,4,5,6,1}(nAn,"Bn,"Cn,"Dn,"En,"Fn,"Gn) Returns: 3. (1,0,1,1,2,2,3,3,0,8,8,9,9,10,10){(An,nBn,"C,"Dn,En,"Pn,"Gn,"H,"I,,"Jn,"K,"L,Mn,"Nn,"O"} Returns: ("+An,+Bn,+Cn,+Bn,+Fn,+Dn,+Cn,+Hn,+I,+J",+L,+M,+Kn,+=N=,+0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
