Delivered by FeedBurner

New Answers in your Inbox

Binary Search Tree [CS62 june 2001]

Queation: 1.(c) Define binary search tree. Write a function in C to creat a binary search tree.

Answer:
A binary search has porperty that all elements in the left subtree of a node n are less than the contents of n and alll elements in the sight subtree of n are greater than or equal to the contents of n.
If a binary search tree is traversed in inorder (left, root, sight) and the contents of each node are printed as the node is visited, the numbers as the node is visited, the numbers are printed in ascending order.

q=null;
p=tree;
while(p!=null){
if (key ==k(p))
return(p);
q=p;
if(key < key(p))
p=left(p);
else
p=right(p);
}
v=maketree(rec,key);
if(q==null)
tree=v;
else
if(key < k(q))
left(q)=v;
else
right(q)=v;
return(v);


IGNOU BCA MCA