Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.

Similar presentations


Presentation on theme: "Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University."— Presentation transcript:

1 Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University

2 Outline Graph-Tree –Basic Definition –Rooted Trees –Applications of Trees –Game Tree

3

4

5

6

7

8

9 Basic Definition Tree –a connected graph with no simple circuits –No multiple edges or loops Theorems –a graph is a tree iff a unique simple path between any two of its vertices –A tree with n vertices has n – 1 edges Forest

10

11

12 Rooted Tree Is a directed graph T satisfying –It is a tree when the directions of the edges are ignored. –There is a unique vertex r (called the root) such that the indegree of r is 0 and the indegree of any other vertex is 1. Examples: family tree, position tree Terminology: parent, child, terminal vertex, internal vertex, subtree, ancestor, descendant An m-ary tree, A full m-ary tree, A balanced m- ary tree with height h

13 Order Rooted Tree Is a rooted tree where the children of each internal vertex are ordered. ordered binary tree: two child, left/right

14

15

16

17 Tree Traversal Is a procedure that systematically visits every vertex of an ordered rooted tree Three most commonly used algorithms –Preorder traversal. –Inorder traversal. –Postorder traversal.

18

19

20 Example#1 List three kinds of traversals.

21 Binary Search Trees Is a binary tree in which each vertex is labeled with a key such that –No two vertices have the same key –If vertex u belongs to the left subtree of vertex v, then u  v –If vertex w belongs to the right subtree of vertex v, then v  w construction algorithm

22

23 S=1+2+2 2 +2 3 +s 4 + …… +2 62 +2 63 2S=2+2 2 +2 3 +2 4 + …… +2 62 +2 63 +2 64 2S-S=S=2 64 -1 2 64 =2 4 ×2 60 = 16×10 18 150 years to get this produce

24 Carl Sagan (1934-1996.12.20) A Pale Blue Planet Mourns the Passing of a Passionate Scientist A Pale Blue Planet Mourns the Passing of a Passionate Scientist

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46


Download ppt "Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University."

Similar presentations


Ads by Google