Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trees - Ed. 2. and 3.: Chapter 6 - Ed. 4.: Chapter 7.

Similar presentations


Presentation on theme: "Trees - Ed. 2. and 3.: Chapter 6 - Ed. 4.: Chapter 7."— 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

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

7

8

9

10

11

12

13

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.

16

17

18

19

20

21

22 The Tree Abstract Data Type

23

24

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

27

28

29

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

33


Download ppt "Trees - Ed. 2. and 3.: Chapter 6 - Ed. 4.: Chapter 7."

Similar presentations


Ads by Google