Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.

Similar presentations


Presentation on theme: "1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and."— Presentation transcript:

1 1 Chapter 10 Trees

2 Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. 2

3 Which graphs are trees? 3 a) b) c)

4 Specify a vertex as root 4 c) Then, direct each edge away from the root. ROOT

5 Specify a root. 5 a) ROOT Then, direct each edge away from the root.

6 Specify a root. 6 a) ROOT Then, direct each edge away from the root.

7 Specify a root. 7 a) ROOT Then, direct each edge away from the root. A directed graph called a rooted tree results.

8 What if a different root is chosen? 8 a) ROOT Then, direct each edge away from the root.

9 What if a different root is chosen? 9 a) ROOT Then, direct each edge away from the root.

10 What if a different root is chosen? 10 a) ROOT Then, direct each edge away from the root.

11 What if a different root is chosen? 11 a) ROOT Then, direct each edge away from the root. A different rooted tree results.

12 12 Jake’s Pizza Shop Tree Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len

13 13 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len A Tree Has a Root TREE ROOT

14 14 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len Leaf nodes have no children LEAF NODES

15 15 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len A Tree Has Levels LEVEL 0

16 16 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len Level One LEVEL 1

17 17 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len Level Two LEVEL 2

18 18 SIBLINGS Sibling nodes have same parent Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len

19 19 SIBLINGS Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len Sibling nodes have same parent

20 20 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len A Subtree LEFT SUBTREE OF ROOT ROOT

21 21 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len Another Subtree RIGHT SUBTREE OF ROOT ROOT

22 Internal Vertex A vertex that has children is called an internal vertex. The subtree at vertex v is the subgraph of the tree consisting of vertex v and its descendants and all edges incident to those descendants. 22

23 23 Owner Jake Manager Brad Chef Carol WaitressWaiter Cook Helper Joyce Chris Max Len How many internal vertices?

24 Binary Tree Definition 2 ’. A rooted tree is called a binary tree if every internal vertex has no more than 2 children. The tree is called a full binary tree if every internal vertex has exactly 2 children. 24

25 Ordered Binary Tree Definition 2 ’’. An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. In an ordered binary tree, the two possible children of a vertex are called the left child and the right child, if they exist. 25

26 Tree Properties Theorem 2. A tree with N vertices has N-1 edges. Theorem 5. There are at most 2 H leaves in a binary tree of height H. Corallary. If a binary tree with L leaves is full and balanced, then its height is H =  log 2 L . 26

27 An Ordered Binary Tree 27 Hal Lou Ken Joe Ted Sue Ed Max

28 Parent The parent of a non-root vertex is the unique vertex u with a directed edge from u to v. 28

29 What is the parent of Ed? 29 Hal Lou Ken Joe Ted Sue Ed Max

30 Leaf A vertex is called a leaf if it has no children. 30

31 How many leaves? 31 Hal Lou Ken Joe Ted Sue Ed Max

32 Ancestors The ancestors of a non-root vertex are all the vertices in the path from root to this vertex. 32

33 How many ancestors of Ken? 33 Hal Lou Ken Joe Ted Sue Ed Max

34 Descendants The descendants of vertex v are all the vertices that have v as an ancestor. 34

35 How many descendants of Hal? 35 Hal Lou Ken Joe Ted Sue Ed Max

36 Level The level of vertex v in a rooted tree is the length of the unique path from the root to v. 36

37 What is the level of Ted? 37 Hal Lou Ken Joe Ted Sue Ed Max

38 Height The height of a rooted tree is the maximum of the levels of its vertices. 38

39 What is the height? 39 Hal Lou Ken Joe Ted Sue Ed Max

40 Balanced A rooted binary tree of height H is called balanced if all its leaves are at levels H or H- 1. 40

41 Is this binary tree balanced? 41 Hal Lou Ken Joe Ted Sue Ed Max


Download ppt "1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and."

Similar presentations


Ads by Google