Table of Contents

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.

 
cs1102/tut8.txt · Last modified: 2009/04/02 16:41 by melvin
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki