CS 341, Fall 2023

Programming Assignment # 3

Due: midnightSunday 11/12/2023

 

Hierarchical structures:

 

Write a java MWAYTREE class to implement a Multi-way tree, with an appropriate constructor and methods for the following:

 

            Methods to find and insert on the tree.

 

            Method to return the height of the tree.

 

Methods to output the values from this tree in any one of the following ways:

 

            Pre-order:        Left to right order of siblings

            Post-order:      Right to left order of siblings

            Level order:    Left to right order of siblings

 

            Method to store the tree to a flat file per the format used for reading the file.

 

Write a Java application that reads an input file (mwaytree.dat) that describes a flattened tree and constructs the corresponding tree. The format of the mwaytree.dat is as follows:

 

The first line has an integer value, m, for an m-way tree described in the file.

The second line indicates the value at the root.

Each subsequent line will describe a node in the tree. There will be up to m+1 integer values separated by a space. The first value is the value at the node, and the subsequent values indicate the values in its children nodes.

 

Example:

 

3                                  The file describes a 3-way tree

1                                  The root has value 1

1 8 22 29                     Node with value 1 has children with values 8, 22, and 29

8 3 5 17

3 16 19 32

22 42                           Node with value 22 has a child with value 42.

19 10 15

42 13 18 49 55

29 4 9

 

Your implementation should handle the value m read from the file, and correspondingly implement the m-way tree. There will be any number of input lines.  A value will be described as a child before it is described with children i.e. parent node will be described before its children. Note that the tree is not a search-tree. You need to create a good data file and test with a test application.

 

Submission:    

 

Questions and Collaboration:  Any questions about the problem – email, inquire in class, or discuss with instructor. You are free to discuss the problem-solving part. Do not view or use code developed by others.