Microsoft

  www.microsoft.com
  www.microsoft.com

Interview Question

Software Development Engineer Interview

check if a BT is BST

Tags:
technical, algorithm
Answer

Interview Answer

1 Answer

0

// Check if a BT is BST
bool IsBST(TreeNode* const root)
{
    if (!root)
        return true;

    bool ell = (root->left ? root->left->data < root->data : true);
    bool are = (root->right ? root->right->data >= root->data : true);

    return ell && are && IsBST(root->left) && IsBST(root->right);
}

Peter on Jul 21, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.