Problem 3 (20 points) Complete the code of a recursive linear-time function isSe
ID: 3702370 • Letter: P
Question
Problem 3 (20 points) Complete the code of a recursive linear-time function isSearchTree below that takes a pointer to the root of a binary tree and tests whether this binary tree satisfies the search tree property at every node: // test whether a given binary tree is a binary search tree and return true if it is, otherwise false bool isSearchTree(Node* node) {Explanation / Answer
struct Node { int key; Node *left, *right; }; bool isSearchTree(Node *node) { if(node == NULL) { return true; } else { if(node->left != NULL) { if(node->key left->key) { return false; } } if(node->right != NULL) { if(node->key > node->right->key) { return false; } } return isSearchTree(node->left) && isSearchTree(node->right); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.