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

Assignment Help:

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);

}


Related Discussions:- Test whether a binary tree is a binary search tree

Efficiency of linear search, Efficiency of Linear Search How much numbe...

Efficiency of Linear Search How much number of comparisons is there in this search in searching for a particular element? The number of comparisons based upon where the reco

Graph search using iterative deepening, Prove that uniform cost search and ...

Prove that uniform cost search and breadth- first search with constant steps are optimal when used with the Graph-Search algorithm (see Figure). Show a state space with varying ste

Steps of pre-order traversal, Pre-order Traversal The method of doing a...

Pre-order Traversal The method of doing a pre-order traversal iteratively then has the several steps(suppose that a stack is available to hold pointers to the appropriate nodes

Merge sort, Merge sort is a sorting algorithm which uses the basic idea of ...

Merge sort is a sorting algorithm which uses the basic idea of divide and conquers. This algorithm initially divides the array into two halves, sorts them separately and then merge

Write the algorithm of the quick sort, Ans. An algorithm for the quick...

Ans. An algorithm for the quick sort is as follows: void quicksort ( int a[ ], int lower, int upper ) { int i ; if ( upper > lower ) { i = split ( a, lower, up

Explain the concept of colouring, Colouring The use of colours in CAD/C...

Colouring The use of colours in CAD/CAM has two main objectives : facilitate creating geometry and display images. Colours can be used in geometric construction. In this case,

Advantage of list over arrays, The advantage of list over Arrays is flexibi...

The advantage of list over Arrays is flexibility. Over flood is not a problem until the computer memory is bushed. When the individual record are quite large, it may be difficult t

Define tree ?, A tree is a non-empty set one component of which is designat...

A tree is a non-empty set one component of which is designated the root of the tree while the remaining components are partitioned into non-empty groups each of which is a subtree

Explain complexity of an algorithm, Complexity of an Algorithm An algo...

Complexity of an Algorithm An algorithm is a sequence of steps to solve a problem; there may be more than one algorithm to solve a problem. The choice of a particular algorith

Best case, Best Case: If the list is sorted already then A[i] T (n) = ...

Best Case: If the list is sorted already then A[i] T (n) = c1n + c2 (n -1) + c3(n -1) + c4 (n -1)  = O (n), which indicates that the time complexity is linear. Worst Case:

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd