Otherwise we go right we then treat the subtree the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: same way. Either we'll find the value we're looking for, or we'll head to a non-existent sub-tree. nonsubLet's look at an example. 3 7 8 5 0 7 6 9 0 2 6 Suppose we are looking for 6. Start at the root. Go left. 7 7 8 5 6 8 5 9 0 2 6 9 2 Suppose we are looking for 6. Start at the root. Go left. Go right. Suppose we are looking for 6. Start at the root. Go left. Go right. We're there. 7 7 8 5 0 9 2 Suppose we are looking for 6. Start at the root. 0 8 5 6 8 5 9 0 6 9 2 2 Suppose we want to add 4 to this tree. Just look for it. Suppose we want to add 4 to this tree. Just look for it. 4 7 8 5 0 7 6 8 5 0 9 6 9 2 2 Suppose we want to add 4 to this tree. Just look for it. Suppose we want to add 4 to this tree. Just look for it. 7 8 5 0 6 9 This shows us how to build a tree. Suppose the data was given to us in the order 5, 2, 6, 0, 8, 7, 9. So 5 becomes the root. 2 5 4 Suppose we want to add 4 to this tree. Just look for it. 2 0 It's just another data collection structure like li linked list. li Here's the interface for a...
View Full Document

Ask a homework question - tutors are online