Java homework

PresidentSearcher - Finding Paths through a Binary Search Tree (BST)

We said that we may also represent a tree using nodes. In this part we will build a binary search tree using such a strategy.

Examine the following 4 files:

* [url removed, login to view]

* [url removed, login to view]

* [url removed, login to view]

* [url removed, login to view]

Again, go through the code and read the documentation. You'll see that PresidentSearcher is an application that makes use of PresidentBST, a class that manages a binary search tree of President objects.


Define the following four methods as follows:

* public void addPresidentIteratively(President presidentToAdd) - This method should add the presidentToAdd to the binary search tree in its proper sorted location using an iterative implementation. Note that it need not guarantee that the tree is balanced or minimum depth, it should simply add it to the appropriate place as the tree exists. Note that the method should not add any duplicates to the tree.

* public void addPresidentRecursively(President presidentToAdd) - This method should do the same thing as its iterative counterpart, adding the presidentToAdd data to the binary search tree. This method should do so using a recursive implementation. Again, duplicates should not be added.

* public Vector<President> findPathIteratively(int presidentNumber) - This method should find a path from the tree's root to the president in the tree whose number corresponds to the presidentNumber argument. The path should be returned as a vector of President objects, including all nodes from the root to the node being searched for. This method should do this using an iterative implementation. If no node is found in the tree corresponding to the number being searched for, the method should simply return a Vector with no elements.

* public Vector<President> findPathRecursively(int presidentNumber) - This method should do the same thing as its iterative counterpart, building a path from the root to the appropriately numbered president. This method should do this using a recursive implementation.

Taidot: Java

Näytä lisää: vector int, vector binary search, vector add, using binary search java, use binary search tree, tree node, tree binary search, sorted binary tree, search bst, search binary tree, search binary, search tree, return path, recursive tree method, recursive binary search, read vector, number nodes tree, node tree, java binary search method, java binary search code, java binary search, iterative binary search, implementation binary search, find binary, depth binary search tree

About the Employer:
( 5 reviews ) Providence, United States

Projektin tunnus: #416823