Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the zip file there are four incomplete files, PrettyPrinter1.java, PrettyPrinter2.java, PrettyPrinter3.java and Hw1.java. Your assignment is to complete the four incomplete files. In addition,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In the zip file there are four incomplete files, PrettyPrinter1.java, PrettyPrinter2.java, PrettyPrinter3.java and Hw1.java. Your assignment is to complete the four incomplete files. In addition, the zip file includes three files, BTree.java, Traverse.java, and PrettyPrintero.java, that are written for you and should not be modified. The term "prettyprint" usually means finding a way to represent a tree as a multi-line string. For example, this binary tree, can be represented by the following string, (a (b de) (c() (f (g() h) ()))) which is not very easy to read. We can improve the readability of this string representation if we use multiple lines along with indentation. G Notice that the root of a tree is printed right after an opening parenthesis, the two sub trees are printed below the root and slightly indented from it, and the closing parenthesis is printed on its own line just below its matching opening parenthesis. Also, the empty tree is treated as a special case and is represented by "0". This binary tree can also be represented by the following, more compact, multi-line string. In this string, small sub trees that have depth 1 are "inlined". (a (b de) (c 0 (f (8 () h) coa o , This representation can be made even more compact. In this string, the root of every left child is "inlined" with its parent's root. (a (b de) (6 () (f (g() h) In the file PrettyPrinter1.java, complete the method prettyPrinter() so that it implements the first kind of prettyprinting described above. In the file PrettyPrinter2.java, complete the method prettyPrinter() so that it implements the second kind of prettyprinting described above. And in the file PrettyPrinter3.java, complete the method prettyPrinter() so that it implements the third kind of prettyprinting described above. In the zip file there are image files for five binary trees, the tree above and the four trees below. O O ODOS on sart while Q a In the file Hw1.java, complete the Java declarations that instantiate binary trees that represent each of the binary trees in these image files (the first one is done for you). Then compile and run your program. The output of your program should look exactly like the contents of the file output.txt contained in the zip file. The three prettyprinting methods are, for the most part, a variation on a preorder traversal of the binary tree. First you prettyprint the root, then you (recursively) prettyprint the left sub tree, then (recursively) prettyprint the right sub tree. For the first prettyprinter, you need to think about three cases, the empty tree, a tree of just a single node, and a tree with more than one node. For the second prettyprinter, you need to consider four cases, an empty tree, a tree of a single node, a tree of depth one, and a tree of depth greater than one. For the third prettyprinter, you have the same four cases, but the root of the left child is always in-line with its parent's root (and be sure to keep opening and closing parentheses vertically aligned). Turn in a zip file called CS51530Hw1Surname.zip (where Surname is your last name) containing your versions of PrettyPrinter1.java, PrettyPrinter2.java, PrettyPrinter3.java and Hw1.java Be sure to put your name and email address in every file your turn in. In the zip file there are four incomplete files, PrettyPrinter1.java, PrettyPrinter2.java, PrettyPrinter3.java and Hw1.java. Your assignment is to complete the four incomplete files. In addition, the zip file includes three files, BTree.java, Traverse.java, and PrettyPrintero.java, that are written for you and should not be modified. The term "prettyprint" usually means finding a way to represent a tree as a multi-line string. For example, this binary tree, can be represented by the following string, (a (b de) (c() (f (g() h) ()))) which is not very easy to read. We can improve the readability of this string representation if we use multiple lines along with indentation. G Notice that the root of a tree is printed right after an opening parenthesis, the two sub trees are printed below the root and slightly indented from it, and the closing parenthesis is printed on its own line just below its matching opening parenthesis. Also, the empty tree is treated as a special case and is represented by "0". This binary tree can also be represented by the following, more compact, multi-line string. In this string, small sub trees that have depth 1 are "inlined". (a (b de) (c 0 (f (8 () h) coa o , This representation can be made even more compact. In this string, the root of every left child is "inlined" with its parent's root. (a (b de) (6 () (f (g() h) In the file PrettyPrinter1.java, complete the method prettyPrinter() so that it implements the first kind of prettyprinting described above. In the file PrettyPrinter2.java, complete the method prettyPrinter() so that it implements the second kind of prettyprinting described above. And in the file PrettyPrinter3.java, complete the method prettyPrinter() so that it implements the third kind of prettyprinting described above. In the zip file there are image files for five binary trees, the tree above and the four trees below. O O ODOS on sart while Q a In the file Hw1.java, complete the Java declarations that instantiate binary trees that represent each of the binary trees in these image files (the first one is done for you). Then compile and run your program. The output of your program should look exactly like the contents of the file output.txt contained in the zip file. The three prettyprinting methods are, for the most part, a variation on a preorder traversal of the binary tree. First you prettyprint the root, then you (recursively) prettyprint the left sub tree, then (recursively) prettyprint the right sub tree. For the first prettyprinter, you need to think about three cases, the empty tree, a tree of just a single node, and a tree with more than one node. For the second prettyprinter, you need to consider four cases, an empty tree, a tree of a single node, a tree of depth one, and a tree of depth greater than one. For the third prettyprinter, you have the same four cases, but the root of the left child is always in-line with its parent's root (and be sure to keep opening and closing parentheses vertically aligned). Turn in a zip file called CS51530Hw1Surname.zip (where Surname is your last name) containing your versions of PrettyPrinter1.java, PrettyPrinter2.java, PrettyPrinter3.java and Hw1.java Be sure to put your name and email address in every file your turn in

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions