1 / 33

Trees

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

finlay
Download Presentation

Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Trees • Ed. 2. and 3.: Chapter 6 • Ed. 4.: Chapter 7

  2. 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

  3. Trees

  4. Example:

  5. 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 .

  6. 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.

  7. The Tree Abstract Data Type

  8. 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 ); }

  9. Construction of Interface Hierarchy

  10. IspectableContainer size isEmpty Elements IspectablePositionContainer positions InspectableTree root parent children isRoot isInternal isExternal PositionContainer swapElement replaceElement Tree

  11. The Binary Tree Abstract Data Type

  12. A Binary Tree Interface in Java

More Related