Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, i am working on a project that i am having a really really hard time with. much help would be greatly appreciated The guidelines

Hi, i am working on a project that i am having a really really hard time with. much help would be greatly appreciated The guidelines for it are:

Requirements: Implement a binary search tree class. The binary search tree will be created from the same state data that was used in the last project.

Use the following class definition for a node in the tree (put this inside your search tree class and do not change it, except to add comments):

private class Node { String stateName; int statePopulation; Node leftChild; Node rightChild; public Node(String state, int population) { stateName = state; statePopulation = population; } public void printNode() { System.out.printf("%-25s%,10d ", stateName, statePopulation); } }

(1) . Create the BinarySearchTree class should implement the following public methods:

1. A no-arg constructor that creates an empty tree.

2. The method: public void insert(String state, int population) that will insert a node into the proper position in the search tree based on state name.

3. The method: public int find(String state) that will search the tree for the state of the given name and if found will return the population or -1 if not found.

4. The method: public void delete(String state) that will find and delete the given state from the tree.

5. The method: public void printInorder() that will traverse the tree in using a Inorder traversal (LNR) and print each node.

6. The method: public void printPreorder() that will traverse the tree in using a Preorder traversal (NLR) and print each node.

7. The method: public void printPostorder() that will traverse the tree in using a Postorder traversal (LRN) and print each node.

8. The method: public void printMinimum() that will find and print the state with the minimum population.

9. The method: public void printMaximum() that will find and print the state with the maximum population.

(2) . Create a class called Project4 that will

1. Read a file (csv) of states and create a binary search tree by calling the insert method.

2. Inorder traverse the tree and print all nodes using the printNode method as they are visited.

3. Delete states California, Florida and Michigan from the tree by calling the delete method; and preorder traverse the resulting tree printing all nodes as they are visited.

4. Search for states Kentucky, Rhode Island and Florida by calling the find method. For each search, print the population information of the found states, and not-found message if not found. Note, for each search, you will also print the number of non-leaf nodes visited to have or havent found the target state.

5. Delete states Delaware,Wyoming, West Virginia and South Dakota from the tree, and postorder traverse the remaining tree printing all nodes as they are visited.

6. Print the states with the minimum and maximum population in the tree by calling the printMinimum and printMaximum methods, respectively.

The input File to read from is :

State,Capital,Abbreviation,Population,Region,US House Seats

Louisiana,Baton Rouge,LA,4625470,South,6

Wisconsin,Madison,WI,5742713,Midwest,8

New Mexico,Santa Fe,NM,2085287,Southwest,3

New York,Albany,NY,19651127,Middle Atlantic,27

Hawaii,Honolulu,HI,1404054,West,2

Vermont,Montpelier,VT,626630,New England,1

Indiana,Indianapolis,IN,6570902,Midwest,9

Arkansas,Little Rock,AR,2959373,South,4

Utah,Salt Lake City,UT,2900872,West,4

West Virginia,Charleston,WV,1854304,Middle Atlantic,3

Montana,Helena,MT,1015165,West,1

Maine,Augusta,ME,1328302,New England,2

Mississippi,Jackson,MS,2991207,South,4

Arizona,Phoenix,AZ,6626624,Southwest,9

North Dakota,Bismarck,ND,723393,Midwest,1

Texas,Austin,TX,26448193,Southwest,36

Ohio,Columbus,OH,11570808,Midwest,16

Alabama,Montgomery,AL,4833722,South,7

Maryland,Annapolis,MD,5928814,Middle Atlantic,8

Colorado,Denver,CO,5268367,West,7

Iowa,Des Moines,IA,3090416,Midwest,4

New Jersey,Trenton,NJ,8899339,Middle Atlantic,12

Massachusetts,Boston,MA,6692824,New England,9

North Carolina,Raleigh,NC,9848060,South,13

Washington,Olympia,WA,6971406,West,10

Pennsylvania,Harrisburg,PA,12773801,Middle Atlantic,18

Wyoming,Cheyenne,WY,582658,West,1

Missouri,Jefferson City,MO,6044171,Midwest,8

Nevada,Carson City,NV,2790136,West,4

Kansas,Topeka,KS,2893957,Midwest,4

Kentucky,Frankfort,KY,4395295,South,6

Delaware,Dover,DE,925749,Middle Atlantic,1

South Dakota,Pierre,SD,844877,Midwest,1

California,Sacramento,CA,38332521,West,53

Oregon,Salem,OR,3930065,West,5

Tennessee,Nashville,TN,6495978,South,9

Illinois,Springfield,IL,12882135,Midwest,18

New Hampshire,Concord,NH,1323459,New England,2

Virginia,Richmond,VA,8260405,Middle Atlantic,11

Idaho,Boise,ID,1612136,West,2

Nebraska,Lincoln,NE,1868516,Midwest,3

Minnesota,St Paul,MN,5420380,Midwest,8

Rhode Island,Providence,RI,1051511,New England,2

Alaska,Juno,AK,735132,West,1

Connecticut,Hartford,CT,3596080,New England,5

South Carolina,Columbia,SC,4774839,South,7

Florida,Tallahassee,FL,19552860,South,27

Michigan,Lansing,MI,9895622,Midwest,14

Oklahoma,Oklahoma City,OK,3850568,Southwest,5

Georgia,Atlanta,GA,9992167,South,14

Example Output:

image text in transcribed

image text in transcribed

Example: COP3538 Project 4 - Xudong Liu Binary Search Trees Enter the file name: States4.csv There were 50 state records put on the binary search tree Inorder Traversal: State Name State Population Alabama Alaska 4, 833,722 735,132 Wisconsin hyoming 5,742,713 582, 658 California has been deleted from tree Florida has been deleted from tree Michigan has been deleted from tree Preorder Traversal State Name State Population Louisiana Hawaii 4,625,470 1,404,054 Virginia wyoming 8,260,405 582, 658 Kentucky is found with a population of 4,395,295 X nodes visited Rhode Island is found with a population of 1,051,511 X nodes visited Florida is not found X nodes visited Delaware has been deleted from tree Wyoming has been deleted from tree West Virginia has been deleted from tree South Dakota has been deleted from tree

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

Why doesn't a chain reaction normally occur in uranium mines?

Answered: 1 week ago