A Knuth Binary Tree has none, one or two branches. Figure 2 shows
a Knuth Binary Tree. Each node contains two pointers, one pointing to the
left subtree and one pointing to the right subtree. A Knuth Tree is easier
to implement than a strict binary tree as recursive algorithms can be used.
In a Binary Search Tree the values contained in the nodes in the left subtree,
child nodes, will all be less than that in the root node. Similarly the
values contained in the nodes in the right subtree will all be greater
than that in the root node. Trees can be reversed if required by making
the left subtrees contain larger values than the root.
Figure 3 shows the order of the nodes in a example of a binary search tree. The letters symbolise the order of the nodes. In a balanced tree the root node would be approximately midway in an ordered list of the contents of the nodes. Nodes with lower values than the root are found in the left subtree and higher values in the right subtree. Each subtree follows the same rule.
| method | description | direction | visit order |
| Top down | start at the root and visit nodes at each level | from left | DCFAEHBGI |
| Bottom up | start furthest from the root and visit nodes at each level | from left | BGIAEHCFD |
| Preorder (prefix) | visit the root, traverse each subtree (from left) | recursive | DCABFEHGI |
| Postorder (postfix) | traverse each subtree (from left) visit the root | recursive | BACDEGIHF |
| Linear Search | traverse left subtree visit root traverse right subtree | recursive | ABCDEFGHI |
If the tree is empty then make this item the tree else compare the item to the root if the item comes before the root add item to the left branch end if if the item comes after the root (if item is not unique need to use an else to allow for equality) add item to the right branch end if end if
if the tree is not empty and not found if the key sought equals the root's key then found is true else if the key sought is less than the root's key then search down the left tree else search down the right tree end if end if end if
There are 4 cases:
Free the space occupied by the leaf node. Make the pointer to the node from the parent node == NULL.
Graft the child branch of the node onto the parent node. Free the space occupied by the deleted node.
Copy data part of the RNLS to data part of node to be deleted Free the space occupied by the RNLS Make pointer to the RNLS from it's parent == NULL
Copy data part of RNLS to data part of node to be deleted Graft the child branch of the RNLS (can only be a left branch) onto the RNLS's parent node. Free the space occupied by the RNLS
The code imaged below is downloadable from here .






