Difference between binary tree and binary search tree

后端 未结 12 1653
情深已故
情深已故 2020-11-29 14:44

Can anyone please explain the difference between binary tree and binary search tree with an example?

12条回答
  •  一生所求
    2020-11-29 15:11

    To check wheather or not a given Binary Tree is Binary Search Tree here's is an Alternative Approach .

    Traverse Tree In Inorder Fashion (i.e. Left Child --> Parent --> Right Child ) , Store Traversed Node Data in a temporary Variable lets say temp , just before storing into temp , Check wheather current Node's data is higher then previous one or not . Then just break it out , Tree is not Binary Search Tree else traverse untill end.

    Below is an example with Java:

    public static boolean isBinarySearchTree(Tree root)
    {
        if(root==null)
            return false;
    
        isBinarySearchTree(root.left);
        if(tree.data

    Maintain temp variable outside

提交回复
热议问题