Graph Theory Trees. WHAT YOU WILL LEARN Trees, spanning trees, and minimum-cost spanning trees.
Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees...
-
Upload
ross-harrison -
Category
Documents
-
view
223 -
download
1
Transcript of Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees...
![Page 1: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/1.jpg)
Agenda
• Review:– Planar Graphs
• Lecture Content: Concepts of Trees Spanning Trees Binary Trees
• Exercise
![Page 2: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/2.jpg)
Review:Planar Graphs
![Page 3: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/3.jpg)
Planar Graphs
Definition:
A graph is called planar if it can be drawn in the plane without any edges crossing (where a crossing of edges is the intersection of the lines or arcs representing them at a point other than their common endpoint).
Such a drawing is called a planar representation of the graph
![Page 4: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/4.jpg)
Example: Planar Graph
![Page 5: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/5.jpg)
Example: Non-Planar Graph
![Page 6: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/6.jpg)
Euler’s Formula
A planar representation of a graph splits the plane into regions or faces, including an unbounded region
Euler’s Formula: Let G be a connected planar simple graph with e edges and v vertices. Let r be the number of regions in a planar representation of G, then r = e – v + 2
Boundary is formed by cycle
![Page 7: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/7.jpg)
Some inequalities for planar graphs
Euler’s formula can be used to establish some inequalities that must be satisfied by planar graphs, i.e:
![Page 8: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/8.jpg)
K3,3 dan K5
Last week, we showed that K3,3 and K5 are not planar (using inequalities on previous slide)
If a graph contains K3,3 or K5 as a subgraph, then it cannot be planar The converse of statement above is not true Use concept of homeomorphic graph
![Page 9: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/9.jpg)
Homeomorphic Graph
DefinitionIf a graph G has a vertex v of degree 2 and edges (v,v1) and (v,v2) with v1≠ v2 , edges (v,v1) and (v,v2) are in series
A series reduction consists of deleting vertex v from G and replacing edges (v,v1) and (v,v2) by the edge (v1,v2).
The graph G’ is said to be obtained from G by a series of reduction or elementary subdivision
Graphs G1 and G2 are homeomorphic if G1 and G2 can be reduced to isomorphic graphs by performing a sequence of series reduction
• Any graph is homeomorphic to itself
• Graphs G1 and G2 are homeomorphic if G1 can be reduced to a graph isomorphic to G2 or if G2 can be reduced to a graph isomorphic to G1
![Page 10: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/10.jpg)
Example
![Page 11: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/11.jpg)
Kuratowski’s Theorem
Theorem:
A graph is nonplanar if and only if it contains a subgraph homeomorphic to K3,3 or K5
Example: Determine whether G is planar or nonplanar?
![Page 12: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/12.jpg)
Trees
![Page 13: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/13.jpg)
Trees
Very useful in computer science applications:– File Computer file system– IP Multicast routing
• Multimedia transmission to a group of receivers– To construct efficient algorithm
• E.g.: searching: Depth-first search, breadth-first search– Construct efficient codes for data transmission and
storage– Games– Decision making– Object-oriented programming: parent child relation
![Page 14: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/14.jpg)
Trees
Definition:A (Free) Tree T is a simple graph satisfying the following:
– If v and w are vertices in T, there is a unique simple path from v to w.
A Rooted Tree is a tree in which a particular vertex is designated the root, and every edge is directed away from the root
Note:• The level of a vertex v is the length of the simple path from the root
to v.• The height of a rooted tree is the maximum level number that
occurs
![Page 15: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/15.jpg)
Which Ones are Trees?
![Page 16: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/16.jpg)
Example
Rooted Tree with root vertex = a
Rooted Tree with root vertex = c
![Page 17: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/17.jpg)
Terminology & Characterization of Trees
• Definition: Let T be a tree with root v0.
Suppose that x, y, and z are vertices in T and that (v0, v1, ..., vn) is a simple path in T.
Then
(a) vn-1 is the parent of vn
(b) v0, ... , vn-1 are ancestors of vn
(c) vn is a child of vn-1
(d) If x is an ancestor of y, y is a descendant of x.
(e) If x and y are children of z, x and y are siblings.
(f) If x has no children, x is a terminal vertex (or a leaf).
(g) If x is not a terminal vertex, x is an internal vertex (or branch)
(h) The subtree of T rooted at x is the graph with vertex set V and edge set E, where V is x together with the descendants of x and
E = {e| e is an edge on a simple path from x to some vertex in V}.
![Page 18: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/18.jpg)
Terminology & Characterization of Trees
Theorem: Let T be a graph with n vertices. The following are equivalent.
(a) T is a tree.
(b) T is connected and acyclic (graph with no cycles)
(c) T is connected and has n–1 edges.
(d) T is acyclic and has n–1 edges.
![Page 19: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/19.jpg)
Example
![Page 20: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/20.jpg)
Spanning Trees
![Page 21: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/21.jpg)
Spanning Trees
Definition A tree T is a spanning tree of a graph G if T is a
subgraph of G that contains all of the vertices of G.
Theorem A graph G has a spanning tree if and only if G is
connected.
![Page 22: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/22.jpg)
Find Spanning Tree of G
Graph G
Graph G is connected, but it is not a tree because it contains simple cycles/circuits
![Page 23: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/23.jpg)
Removing edges to eliminate cycle/circuit
A Spanning Tree
![Page 24: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/24.jpg)
Other Spanning Trees of G
![Page 25: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/25.jpg)
Algorithms for Creating Spanning Tree
Depth-First Search Breadth-First Search
![Page 26: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/26.jpg)
Depth-First Search
• Arbitrarily choose a vertex of the graph as the root.• Form a path starting at this vertex by successively
adding vertices and edges, where each new edge is incident with the last vertex in the path and a vertex not already in the path.
• Continue adding vertices and edges to this path as long as possible.
• Move back to the last vertex in the path, and, if possible, form a new path starting at this vertex passing through vertices that were not already visited.
• Move back another vertex in the path (two vertices in the path) and try again.
• Repeat this procedure Backtracking
![Page 27: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/27.jpg)
Example
Arbitrarily choose f as the root
![Page 28: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/28.jpg)
Breadth-First Search
• Arbitrarily choose a vertex of the graph as the root.• Add all edges incident to this vertex.• The new vertices added at this stage become the
vertices at level 1 in the spanning tree.• For each level in level 1, add all edges incident to this
vertex to the tree as long as it does not produce a simple circuit.
• This produce the vertices at level 2 in the tree.• Repeat this procedure
![Page 29: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/29.jpg)
Example
![Page 30: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/30.jpg)
Minimum Spanning Tree
![Page 31: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/31.jpg)
Minimum Spanning Tree
Definition:Let G be a weighted graph. A minimum spanning tree of G is a spanning tree of G with minimum weight.
Algorithms:Prim’s algorithmKruskal’s algorithm
![Page 32: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/32.jpg)
Prim’s Algorithm
![Page 33: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/33.jpg)
Example
![Page 34: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/34.jpg)
Binary Trees
![Page 35: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/35.jpg)
Binary Trees
Definition:A binary tree is a rooted tree in which each vertex has either no children, one child, or two children. If a vertex has a child, that child is designated as either a left child or a right child (but not both). If a vertex has two children, one child is designated a left child and the other child is designated a right child.
Note:A full binary tree is a binary tree in which each vertex has either two children or zero children.
![Page 36: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/36.jpg)
Example
![Page 37: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/37.jpg)
Binary Trees
Theorem:If T is a full binary tree with i internal vertices, then T has i+1 terminal vertices and 2i+1 total vertices.
Theorem:If a binary tree of height h has t terminal vertices, then lg2 t ≤ h
Example
![Page 38: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/38.jpg)
Application: Huffman Coding
Huffman code represents characters by variable-length bit strings alternatives to ASCII or other fixed-length codes Objective to use fewer bits: to save minimize storage and
transmission time The idea is to use short bit strings to represent most
frequently used characters and longer bit strings to represent less frequently used characters
Easily defined by binary tree
![Page 39: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/39.jpg)
Example
• 01010111?• SOTO?
![Page 40: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/40.jpg)
Algorithm to construct an optimal Huffman Code
![Page 41: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/41.jpg)
Example
Construct Huffman code for the following characters, given the frequency of occurrence as follows:
Algorithm begins by repeatedly replacing the smallest two frequencies with the sum until two-element sequence is obtained
2,3,7,8,12 2+3,7,8,12
5,7,8,12 5+7, 8,12
8,12,12 8+12, 12
12, 20
Character Frequency
! 2
@ 3
# 7
$ 8
% 12
Construct tree as follows
![Page 42: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/42.jpg)
Example
![Page 43: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/43.jpg)
Binary Search Tree
How should items in a list be stored so that an item can be easily located?
Definition A binary search tree is a binary tree T in which data are associated with the vertices. The data are arranged so that, for each vertex v in T, each data item in the left subtree of v is less than the data item in v, and each data item in the right subtree of v is greater than the data item in v
ExampleConstruct a binary search tree from the following words:
OLD PROGRAMMERS NEVER DIE
THEY JUST LOSE THEIR MEMORIES
![Page 44: Agenda Review: –Planar Graphs Lecture Content: Concepts of Trees Spanning Trees Binary Trees Exercise.](https://reader036.fdocuments.net/reader036/viewer/2022062421/56649f425503460f94c613b7/html5/thumbnails/44.jpg)
Example