struct Tree < int>>; bool ValsLess(Tree * t, int val) // post: return true if and only if all values in t are less than val
Partly B, college students are expected to write IsBST using ValsLess and you can provided that a similar setting ValsGreater exists. The answer is actually found below:
bool IsBST(Tree * t) // postcondition: returns true if t represents a binary search // tree containing no duplicate values; // otherwise, returns false. < if>left,t->info) && ValsGreater(t->right,t->info) && IsBST(t->left) && IsBST(t->right); >
Ahead of persisted you should try to determine/guess/reason about what the fresh complexity away from IsBST is actually for a keen letter-node tree. Believe that ValsLess and you can ValsGreater both run in O(n) returning to an enthusiastic letter-node tree.
A work with the same attributes
What is the asymptotic complexity of the function DoStuff shown below. Continue reading