Write a function that takes a binary tree and returns
trueif it is a binary search tree, andfalseif not. In tests, use the following examples:head1 = 0 / \ 1 2 /\ /\ 3 4 5 6head1 is NOT a binary search tree.
head2 = 3 / \ 1 4 /\ /\ 0 2 5 6head2 is NOT a binary search tree.
head3 = 3 / \ 1 5 /\ 0 4head3 is NOT a binary search tree.
head4 = 3 / \ 1 5 /\ /\ 0 2 4 6head4 is a binary search tree.
I've written an implementation that determines the solution in O(n) time complexity in the worst case, where n is the number of Nodes in the Binary Tree.
Languages Implemented:
- JavaScript