Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote