Unformatted text preview: current points to a node, info(current) refers to the user’s data in the node, left(current) points to the root of the left subtree of current , and right(current) points to the root of the right subtree of current . If a pointer contains null , the subtree is empty. Using this notation, we can now write the search algorithm. We start at the root of the tree and move to the root of successive subtrees until we find the item we are looking for or we find an empty subtree. The item to be searched for and the root of the tree (subtree) are parameters. Boolean IsThere(current, item) If (current is null) return false Else Set result to item.compareTo(info(current)) If (result is equal to 0) return true Else If (result < 0) IsThere(left(current, item)) Else IsThere(right(current, item) Pointer to the root of the left subtree Pointer to the root of the right subtree User's data...
View
Full Document
 Fall '10
 MARIANAKANT
 Pointer, subtree

Click to edit the document details