330 likes | 347 Views
Trees. Ed. 2. and 3.: Chapter 6 Ed. 4.: Chapter 7. Trees What is a tree? - Examples of trees - Tree interface and interface hierarchy Algorithms on binary trees - Binary tree interface - Traversal on a binary tree - Binary tree implementation - Traversal on a tree
E N D
Trees • Ed. 2. and 3.: Chapter 6 • Ed. 4.: Chapter 7
Trees • What is a tree? - Examples of trees - Tree interface and interface hierarchy • Algorithms on binary trees - Binary tree interface - Traversal on a binary tree - Binary tree implementation - Traversal on a tree • Sample case study application
r T u v A formal definition of trees: A tree T is a set of nodes storing elements in a parent - child relationship with the following properties: · T has a special node r , called the root of T . · Each node v of T different from r has a parent node u .
… …
Comparing Example 6.3 with Example 6.2, we can see an important difference between the ordered tree and the unordered tree. In an ordered tree, the order of the children of a node is significant while in an unordered tree, the order of the children of a node is not important.
A Tree Interface in Java public interface Tree { public int size(); public Boolean isEmpty(); public ElementIterator elements(); public PositionIterator positions(); public void swapElements( Position v, Position w ); public Object replaceElement( Position v, Object e ); public Position root(); public Position parent( Position v ); public PositionIterator children( Position v ); public boolean isInternal( Position v ); public boolean isExternal( Position v ); public boolean isRoot( Position v ); }
IspectableContainer size isEmpty Elements IspectablePositionContainer positions InspectableTree root parent children isRoot isInternal isExternal PositionContainer swapElement replaceElement Tree