trees - CSC 202 Lab 5 Trees Trees are a very common form of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Trees Trees are a very common form of data. In fact, lists are simply trees with at most one branch at each node. Binary Search Trees We often want to be able to build a data structure that allows us to look up information based on some key value. One simple idea would be to just create a list of all the data items. The disadvantage is that it can then take a long time to find the items at the end of the list, since we have to look at all the prior items first. Many data structures can be used for this problem, one of which is a binary search tree . For simplicity, let's assume we just want to keep track of a bunch of numbers, remembering which ones we've seen. From this, we could easily generalize our results to, for example, keeping track of team player information indexed by player number, or to indexing on names rather than numbers. The following are some binary search trees for the numbers 1,3,4,6,9: 4 / \ 1 6 \ \ 3 9 3 / \ 1 6 / \ 4 9 3 / \ 1 4 \ 6 \ 9 Each node holds a data item (here, number) and two possibly-empty subtrees. All the nodes in the left branch are less than the current node. All the nodes in the right branch are greater than the current node. The ordering of the nodes depends on how the tree is built. Write Java Methods to do the following:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

trees - CSC 202 Lab 5 Trees Trees are a very common form of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online