Question d’entretien chez Amazon

How do you check if a Binary Tree is a Binary Search Tree?

Réponses aux questions d'entretien

Utilisateur anonyme

28 mars 2011

boolean isBST(Node root, int min, int max) { if (root == NULL) return true; if (root.value max) return false; return isBST(root.left, min, root.value) && isBST(root.right, root.key, max); } /* first call would be isBST(root,INT_MIN,INT_MAX); */

2

Utilisateur anonyme

10 mai 2011

Or, perform an in-order traversal and see if the values are sorted