Pergunta de entrevista da empresa Amazon

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

Respostas da entrevista

Sigiloso

28 de mar. de 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

Sigiloso

10 de mai. de 2011

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