Test whether a binary tree is a binary search tree, Data Structure & Algorithms

Q. Write down an algorithm to test whether a Binary Tree is a Binary Search Tree.             

Ans.

The algorithm to check whether a Binary tree is as Binary Search tree is as

follows:

bstree(*tree)

{

while((tree->left !=null)&& (tree->right !=null))

{

if(tree->left < tree->root)

bstree(tree->left);

else return(1);

if(tree->right > tree->root)

bstree(tree->right);

else return(1);

}

return(0);

}

Posted Date: 7/13/2012 3:11:54 AM | Location : United States







Related Discussions:- Test whether a binary tree is a binary search tree, Assignment Help, Ask Question on Test whether a binary tree is a binary search tree, Get Answer, Expert's Help, Test whether a binary tree is a binary search tree Discussions

Write discussion on Test whether a binary tree is a binary search tree
Your posts are moderated
Related Questions
How sparse matrix stored in the memory of a computer?


In the present scenario of global warming, the computer hard ware and software are also contributing for the increase in the temperature in the environment and contributing for the

Addition of new records in a Binary tree structure always occurs as leaf nodes, which are further away from the root node making their access slower. If this new record is to be ac

What do you understand by tree traversal? The algorithm walks by the tree data structure and performs some computation at everynode in the tree. This process of walking by the

Q. The system allocates the memory for any of the multidimensional array from a big single dimensional array. Describe two mapping schemes that help us to store the two dimensi

data structure for multiqueue

A shop sells books, maps and magazines. Every item is identified by a unique 4 - digit code. All books have a code starting with a 1, all maps have a code which starts with a 2 and

When there is requirement to access records sequentially by some key value and also to access records directly by the similar key value, the collection of records may be organized

The most common way to insert nodes to a general tree is to first discover the desired parent of the node you desire to insert, and then insert the node to the parent's child list.