Diagramatically, we can represent a binary tree as follows:
How would we find an item in a binary tree?
Let's consider this in structured English:
Note: each Node in the array/tree has 3 attributes: data, leftPointer and rightPointer
DECLARE tree: ARRAY[0:X] OF Node
DECLARE rootPointer, searchPointer, searchItem : INTEGER
← 0
searchPointer ← rootPointer
INPUT
WHILE tree[searchPointer].data <> searchITEM AND searchPointer <> -1 //or NULL
IF > searchItem THEN
searchPointer ←
ELSE
searchPointer ←
ENDIF
END WHILE
IF searchPointer = THEN
OUTPUT "ITEM NOT FOUND"
ELSE
OUTPUT searchPointer
END IF
data type INTEGER pseudocode REAL program code DATE STRING CHAR bubble sort BOOLEAN declare variable