Writing program that allows the user to enter a binary tree

Assignment Help Data Structure & Algorithms
Reference no: EM133445951

Data Structures and Analysis - Project

The third programming project involves writing a program that allows the user to enter a binary tree in a parenthesized prefix format and then allows it to be categorized and allows various features of that tree to be displayed. An example of a tree written in the input format is the following:

(A(G(j)(1))(z(5)))

In the above example, data in each node of the tree contains a single alphanumeric character. No spaces are permitted. Each tree is enclosed in parentheses. Inside those parentheses, after the single character are either zero, one or two subtrees also enclosed in parentheses. When only one subtree is present, it is the left subtree and when two are present, they represent the left and right subtrees. So the above string represents the following binary tree:

824_binary tree.jpg

 

The various categorizations include the following:

1. Whether the binary tree is balanced, which means for each node in the tree, the absolute difference between the height of its left and right subtrees is at most 1. The above binary tree is balanced.

2. Whether the binary tree is full. A full binary tree has the maximum number of nodes for a tree of its height. The above tree is not full because a tree of that height can contain 7 nodes, but the above tree only has 6.

3. Whether the binary tree is proper. In a proper binary tree, every node has either 0 or 2 children. The above tree is not proper because the node containing z has only one child.

In addition, the program should allow the user to request that each of the following features of the tree be displayed:

1. The height of the tree. The height of a tree is the maximum level of all of its nodes. The root node containing A is at the level 0. Because all three leaf nodes in the above tree are at level 2, its height is 2.

2. The number of nodes in the tree. As previously mentioned, the above tree has 6 nodes.

3. An fully parenthesized inorder traversal of the tree. The following should be displayed as the inorder traversal of the above tree: ((( j ) G ( 1 )) A (( 5 ) z ))

This project should consist of three classes. The main class should create a GUI that allows the user to input a tree in the above described format and then construct the tree once the Make Tree button is clicked. The GUI should look as follows:

2160_binary tree1.jpg

 

The GUI must be generated by code that you write. You may not use a drag-and-drop GUI generator.

The second class should be the BinaryTree class, which should contain a static nested class to define the nodes of the binary tree, together with a constructor that is called when the Make Tree button is clicked and is supplied the string representation of the tree and constructs the actual tree from that string. In addition, it should have public methods that are called when each of the remaining six buttons are clicked. All of those public methods should have corresponding private methods that accomplish their tasks using recursion.

The third class should be named InvalidTreeSyntax, which defines a checked exception. It should be thrown when a invalid string is supplied and the Make Tree button is clicked. It should be caught in the main class and a JOptionPane window should be displayed that describes the reason for the invalid syntax.

You are to submit two files.

Question 1. The first is a .zip file that contains all the source code for the project. The .zip file should contain only source code and nothing else, which means only the .java files. If you elect to use a package the .java files should be in a folder whose name is the package name. Every outer class should be in a separate .java file with the same name as the class name. Each file should include a comment block at the top containing your name, the project name, the date, and a short description of the class contained in that file.

Question 2. The second is a Word document (PDF or RTF is also acceptable) that contains the documentation for the project, which should include the following:

a. A UML class diagram that includes all classes you wrote. Do not include predefined classes.

You need only include the class name for each individual class, not the variables or methods

b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing

c. A short paragraph on lessons learned from the project.

Reference no: EM133445951

Questions Cloud

List an example of sociological imagination that applies : List an example of sociological imagination that applies the concept of personal issues as public issues.
What type of reliability does my pattern of results apply to : What type of reliability does my pattern of results apply to? Which type do you think seems most like you?
Discuss how it may have made the application of cit : Choose one of the evolutions of Critcal Incidents Theory (CIT) and discuss how it may have made the application of CIT to specific leadership consultations more
Explain what the consequences to aversive racism : According to The Nature of Contemporary Prejudice: Insights from Aversive Racism. explain what the consequences to aversive racism, in helping behavior
Writing program that allows the user to enter a binary tree : Data Structures and Analysis - writing a program that allows the user to enter a binary tree in a parenthesized prefix format and then allows
Imagine you are part of a student treatment team : Imagine you are part of a student's treatment team and another professional is recommending the use of hyperbaric oxygen treatment to help improve the student
Describe the age appropriate transition assessments : Describe the age appropriate transition assessments and how they were used to develop the transition plan. Describe at least three age appropriate transition
What was your favorite component of the kidszone : How much homework do you think is appropriate for children of various ages? Be sure to list the citation info for the article that you read.
Discusses the ethical theories within the family of virtue : discusses the ethical theories within the family of virtue ethics. Choose three theories that, in your opinion, were the most important within Module 7.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Create a table that depicts the runtime for arrays of length

Create a table that depicts the runtime for arrays of length 1 to 10. Would you expect the general runtime to be O(n), O(n2), O(n3), or some other function of n? Explain.

  Design and build a prototype data warehouse

Design and build a prototype data warehouse using the data on Spend over £500 in the Department of Energy and Climate Change for the financial year 2012-2013 (April 2012 to March 2013 inclusive).

  Write a binary search tree method that takes two keys

Write a binary search tree method that takes two keys, low and high, and prints all elements X that are in the range specified by low and high.

  Reverse path flooding

Suppose we have a network of nodes connected via point to point links, and source S sends a message that will be broadcast to all nodes using Reverse Path Flooding.

  Design an application that has an array of twenty integers

Design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values.

  Prepare a flowchart to solve any linear equation

Prepare a flowchart to solve any linear equation ax^2+bx+C=0

  Find a stable state in a hopfield neural network

Consider the problem of finding a stable state in a Hopfield neural network, in the special case when all edge weights are positive. This corresponds to the Maximum-Cut Problem that we discussed earlier in the chapter: For every edge e in the grap..

  Determine if array is unique and in ascending order

I need to determine if my array is unique and in ascending order. I've got the ascending order part figured out but am not sure that I'm doing the unique part correctly. Could you check my pseudocode to see if I have it right? I not, please give m..

  How the action values are initialized and updated

Give pseudo-code for a complete algorithm for the n -armed bandit problem. Indicate how the action values are initialized and updated after each reward.

  What is time-complexity to insert item at end of linked list

CST 227- What is the time-complexity to insert an item at the end of a linked list? In an ordered list, we need to modify the algorithms (from a normal linked list) to implement the search, insert, and delete operations.

  Yaou will now look at stacks and queues using linked lists

you will now look at stacks and queues using linked lists. complete the following for this assignment1 create a

  What changes would you recommend in your proposed design

DSAA204 - Data Structures and Algorithms - Kent Institute - What changes would you recommend in your original proposed design and why

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd