Many entities, such as hurricanes, can be organized in a hierarchy. How would you design a system that stores the hierarchy and allow queries on the hierarchy?

The goal of HW3 is to build a tree from categories of hurricanes and answer queries on the tree. Your submission has a Tree class that has a linked structure of tree nodes and supports (at least) the following operations:

  • addChild(parentNode, childNode) // to maintain alphabetical/lexicographical order of the children
  • getChildren(node)
  • getParent(node)

For each node, you may not assume it has a fixed or maximum number of children.

Input: Input is from the command-line arguments for hw3.c (HW3.java) in this order:

1. filename of the datathe first line has the top category, followed by its sub-categories; each of the following lines has a category, followed by its sub-categories.

2. filename of queries, each line has one of the following queries:

  • GetNamesByCategory category
  • GetNamesByState state
  • GetNamesByCategoryAndState category state
  • GetNamesWithMultipleStates
  • GetNamesWithMultipleCategories
  • GetCategory name
  • GetState name

You may assume each query is valid (name, category, and state exist in the data), but some queries do not have results. Sample input files are on the course website.

Output: Output goes to the standard output (screen), each line has an answer with the corresponding query:

  • GetNamesByCategory category name1 name2 ...
  • GetNamesByState state name1 name2 ...
  • GetNamesByCategoryAndState category state name1 name2 ...
  • GetNamesWithMultipleStates name1 name2 ...
  • GetNamesWithMultipleCategories name1 name2 ...
  • GetCategory name category1 ...
  • GetState name state1 ...

Note that a hurricane can create hurricane conditions in more than one state in different categories, so GetState/GetCategory might have more than one state/category and getNames should not have duplicates. All results should be alphabeti- cally/lexicographically ordered. Report "none" if there are no results.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.