Closed rygh4775 closed 5 years ago
BST Sequences: A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.
7 3 10 1 5 8 12
then,
time complexity is O(h * 2^h) - to make combination of each level is O(2^h) and do it for each level h
O(h * 2^h)
level h
BST Sequences: A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.