Pergunta de entrevista da empresa Red Hat

You are given a binary tree as input , find whether the tree is a BST or not .

Respostas da entrevista

Sigiloso

15 de ago. de 2013

Take the inorder traversal of the tree . If its a sorted list , its bst .

Sigiloso

19 de fev. de 2019

bool isBST(Node* root) { if (root == NULL) return true; bool lbst = true; bool rbst = true; if (root->left) { if(root->left->val val) return false; lbst = isBST(root->left); } if (lbst && root->right) { if (root->right->val > root->val) return false; rbst = isBST(root->right); } return rbst && lbst;