Tuesday, October 14, 2008

6.7 Binary search Tree

Program Definition
A Program to perform the following operations:
1. Insert an element into a binary search tree.
2. Delete an element from a binary search tree
3. Search for a key element in a binary search tree.
Algorithm
BINARY SEARCH TREE OPERATIONS
Aim: Algorithm for insertion element
1. algorithm Insert (x)
2. // insert x into the binary search tree
3. {
4. found:= false;
5. p:= tree;
6. // search for x, q is parent of p
7. while ( (p != 0) and not found) do
8. {
9. q:= p; // save p
10. }
11. else
12. tree := p;
13. }
14. }

No comments: