1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
-
Upload
paulina-wiggins -
Category
Documents
-
view
225 -
download
0
Transcript of 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
![Page 1: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/1.jpg)
1
Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus
Trees
![Page 2: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/2.jpg)
2
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.
Tree
![Page 3: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/3.jpg)
3
Which graphs are trees?
a) b)
c)
![Page 4: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/4.jpg)
4
Specify a vertex as root
c)
Then, direct each edge away from the root.
ROOT
![Page 5: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/5.jpg)
5
Specify a root.
a)ROOT
Then, direct each edge away from the root.
![Page 6: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/6.jpg)
6
Specify a root.
a)ROOT
Then, direct each edge away from the root.
![Page 7: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/7.jpg)
7
Specify a root.
a)ROOT
Then, direct each edge away from the root.
A directed graph called a rooted tree results.
![Page 8: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/8.jpg)
8
a)ROOT
Then, direct each edge away from the root.
What if a different root is chosen?
![Page 9: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/9.jpg)
9
a)ROOT
Then, direct each edge away from the root.
What if a different root is chosen?
![Page 10: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/10.jpg)
10
a)ROOT
Then, direct each edge away from the root.
What if a different root is chosen?
![Page 11: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/11.jpg)
11
a)
ROOT
Then, direct each edge away from the root.
What if a different root is chosen?
A differentrooted tree results.
![Page 12: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/12.jpg)
12
Jake’s Pizza Shop Tree
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
![Page 13: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/13.jpg)
13
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
A Tree Has a Root
TREE ROOT
![Page 14: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/14.jpg)
14
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
Leaf nodes have no children
LEAF NODES
![Page 15: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/15.jpg)
15
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
A Tree Has Levels
LEVEL 0
![Page 16: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/16.jpg)
16
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
Level One
LEVEL 1
![Page 17: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/17.jpg)
17
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
Level Two
LEVEL 2
![Page 18: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/18.jpg)
18
SIBLINGS
Sibling nodes have same parent
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
![Page 19: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/19.jpg)
19
SIBLINGS
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
Sibling nodes have same parent
![Page 20: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/20.jpg)
20
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
A Subtree
LEFT SUBTREE OF ROOT
ROOT
![Page 21: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/21.jpg)
21
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
Another Subtree
RIGHT SUBTREE OF ROOT
ROOT
![Page 22: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/22.jpg)
22
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.
Internal Vertex
![Page 23: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/23.jpg)
23
Owner Jake
Manager Brad Chef Carol
Waitress Waiter Cook Helper Joyce Chris Max Len
How many internal vertices?
![Page 24: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/24.jpg)
24
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.
Binary Tree
![Page 25: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/25.jpg)
25
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.
Ordered Binary Tree
![Page 26: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/26.jpg)
26
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 = log2 L .
Tree Properties
![Page 27: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/27.jpg)
27
An Ordered Binary Tree
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
![Page 28: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/28.jpg)
28
The parent of a non-root vertex is the
unique vertex u with a directed edge
from u to v.
Parent
![Page 29: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/29.jpg)
29
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
What is the parent of Ed?
![Page 30: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/30.jpg)
30
A vertex is called a leaf if it has no
children.
Leaf
![Page 31: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/31.jpg)
31
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
How many leaves?
![Page 32: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/32.jpg)
32
The ancestors of a non-root vertex are
all the vertices in the path from root to
this vertex.
Ancestors
![Page 33: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/33.jpg)
33
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
How many ancestors of Ken?
![Page 34: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/34.jpg)
34
The descendants of vertex v are all the
vertices that have v as an ancestor.
Descendants
![Page 35: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/35.jpg)
35
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
How many descendants of Hal?
![Page 36: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/36.jpg)
36
The level of vertex v in a rooted tree is
the length of the unique path from the
root to v.
Level
![Page 37: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/37.jpg)
37
What is the level of Ted?
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
![Page 38: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/38.jpg)
38
The height of a rooted tree is the
maximum of the levels of its vertices.
Height
![Page 39: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/39.jpg)
39
What is the height?
Hal
Lou
Ken
Joe Ted
Sue Ed
Max
![Page 40: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/40.jpg)
40
A rooted binary tree of height H is
called balanced if all its leaves are at
levels H or H-1.
Balanced
![Page 41: 1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.](https://reader035.fdocuments.us/reader035/viewer/2022062222/5697c0101a28abf838ccb056/html5/thumbnails/41.jpg)
41
Is this binary tree balanced?
Hal
Lou
Ken
Joe Ted
Sue Ed
Max