Download presentation
Presentation is loading. Please wait.
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
5
Example:
6
A formal definition of trees: A treeT is a set ofnodes storing elements in aparent-child relationship with the following properties: T has a special noder, called theroot ofT. Each nodev ofT different fromr has aparent nodeu. r v u T
14
… …
15
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.
22
The Tree Abstract Data Type
25
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 ); } A Tree Interface in Java
26
Construction of Interface Hierarchy
30
IspectableContainer size isEmpty Elements IspectablePositionContainer positions PositionContainer swapElement replaceElement InspectableTree root parent children isRoot isInternal isExternal Tree
31
The Binary Tree Abstract Data Type
32
A Binary Tree Interface in Java
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.