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 vector int, vector int int, vector int, vector binary search, vector add, using binary search in java, use of binary search tree, use of binary, tree node, tree binary search, sorted binary tree, search in binary tree, search bst, search binary tree, search binary search tree, search binary, search a tree, return path, recursive tree method, recursive binary search c, read vector, number of nodes in a tree, node of a tree, node in tree, java binary search method

Tietoa työnantajasta:
( 5 arvostelua ) Providence, United States

Projektin tunnus: #416823