Tutorial 8 - Trees
2b
Instead of creating new arrays to represent the inorder and preorder traversal of the subtrees, it is possible to save space by passing a pair of indices instead. Observe that the inorder/preorder traversal of the left and right subtrees are just contiguous segments of the inorder/preorder traversal of the whole tree. Therefore, we can represent the inorder/preorder traversal of the subtrees using a start and end index.
3a
A variant is to determine whether a given binary tree is complete in O(n) time. What is the simplest algorithm for this problem? Hint: think about the fact that a complete tree can be stored in an array.