Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement your class Drawtree using Java. Please include the full code and post the output APT: Drawing Trees Problem Statement Given a tree, you are

Implement your class Drawtree using Java. Please include the full code and post the output image text in transcribed
image text in transcribed
image text in transcribed
APT: Drawing Trees Problem Statement Given a tree, you are to return a representation of that tree as a public class Drawrree \{ publie string[] draw (int[] parents, string[] names) a int[], where element i gives the index of the parent of node i (indexed from 0 ). 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[] 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 % as shown in the examples. For example, the tree given by the input: parents={1,0,1,1,0,0,5,5}names={"Root","SubB","LRAF1","LEAF2","LEAF3","SUbA","LEAF4","LEAF5"} would result in the following return. +-Root+-SubB+-LEAF1+-LEAF2+-LEAF3+-SUbA+-LEAF4+-LENF5 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",LIEAF5"} Returns: {"+ +-Root", t-SubB", +-LEAF1", +-LEAF2", +-LEAF3", +SubA1, +-LEAF4", t-LEAFS = F 2. {1,2,3,4,5,6,1}("A,"B","C",nDn,"E","F","G") Returns: 3. {6,2,3,4,5,6,1}{An,Bn,Cn,"Dn,nE,Fn,C}Returns:f+6,t=An,+Eii+E,+D0+=C4,+B1} (1,0,1,1,2,2,3,3,0,8,8,9,9,10,10) Returns: An+nn+4C1,4Hn,+In+J+L+MtKn,+N+0=

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions