0% found this document useful (0 votes)
10 views

Week 4

The minimum total length of cable needed is 20 units, using the edges ED, AB, CD, AE, EF in that order.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Week 4

The minimum total length of cable needed is 20 units, using the edges ED, AB, CD, AE, EF in that order.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Week 4: 23/3 – 27/3/2015

Trees and Distance


 Basic Properties
 Distances and centroids
 Spanning Trees and Enumeration.
 Optimization and Trees
Minimum Cost Spanning Tree, Prim’s and
Kruskal’s Algorithms, the Shortest Path Algorithms,
Dijkstra’s algorithm
Basic properties
• The following theorem lists some simple properties of trees.
• THEOREM 3.1 Let T be a graph with n vertices. Then the following
statements are equivalent:
• (i) T is a tree;
• (ii) T contains no cycles, and has n - 1 edges;
• (iii) T is connected, and has n - 1 edges;
• (iv) T is connected, and each edge is a bridge;
• (v) any two vertices of T are connected by exactly one path;
• (vi) T contains no cycles, but the addition of any new edge creates exactly
one cycle.
• Proof.
Pg 62
• Cycle rank
• Cutset rank
• Prove theorem 3.2
Distances and centroids

• Distances: Definition: In a graph, the distance from vertex s to vertex t


is the length of a shortest walk from s to t, or  if there is no walk
from s to t. for digraphs, the directed distance is the length of a
shortest directed walk.
• In a connected graph, how far apart can two vertices be?
• Theorem: (Jordan 1869) A tree has exactly one centre or has two
adjacent centers
A tree T has either one node that is a graph center, in which case it is called a
centered tree, or two adjacent nodes that are graph centers, in which case it
is called a bicentered tree (Harary 1994, p. 35).

When a special node is designated to turn a tree into a rooted tree, it is


called the root (or sometimes "Eve"). In such a tree, each of the nodes that is
one graph edge further away from a given node is called a child, and nodes
connected to the same node that are the same distance from the root vertex
are called siblings.

Note that two branches placed end-to-end are equivalent to a single branch,
which means for example, that there is only one tree of order 3. The number
t(n) of nonisomorphic trees of order n=1, 2, ... (where trees of orders 1, 2, ...,
6 are illustrated above), are 1, 1, 1, 2, 3, 6, 11, 23, 47, 106, 235, 551, 1301,
3159, ... (OEIS A000055).
Spanning Tree
Spanning tree and Enumeration (pg 75 wilson)

• The subject of graph enumeration is concerned with the problem of


determining how many non-isomorphic graphs satisfy a given
property. The subject was initiated in the 1850s by Arthur Cayley, who
later applied it to the problem of enumerating alkanes CnH2n+2
• with a given number of carbon atoms. As he realized, and as you will
see below, this problem is that of counting the number of trees in
which the degree of each vertex is either 4 or 1.

Trees were first studied by Cayley (1857). McKay maintains a database of trees
up to 18 vertices, and Royle maintains one up to 20 vertices.
• THEOREM 3.3 (Cayley, 1889) The complete graph K n for n>0
n2
contains exactly n distinct spanning trees (pg 67: Wilson)
n2
• COROLLARY 3.4 The number of spanning trees of Kn is .n
Optimization and Trees
Definition
• A Minimum Spanning Tree (MST) is a subgraph of an undirected graph
such that the subgraph spans (includes) all nodes, is connected, is
acyclic, and has minimum total edge weight
Algorithm Characteristics
• Both Prim’s and Kruskal’s Algorithms work with
undirected graphs
• Both work with weighted and unweighted graphs but
are more interesting when edges are weighted
• Both are greedy algorithms that produce optimal
solutions
Prim’s Algorithm

• Similar to Dijkstra’s Algorithm except that dv records edge weights, not


path lengths
Minimum spanning trees
Minimum Connector Algorithms

Kruskal’s algorithm Prim’s algorithm

1. Select the shortest edge in a 1. Select any vertex


network
2. Select the shortest edge
2. Select the next shortest edge connected to that vertex
which does not create a cycle
3. Select the shortest edge
3. Repeat step 2 until all vertices connected to any vertex
have been connected already connected

4. Repeat step 3 until all


vertices have been
connected
Example
A cable company want to connect five villages to their network which
currently extends to the market town of Avonford. What is the minimum
length of cable needed?

Brinleigh 5 Cornwell

3
6 4
8
8
Avonford Fingley Donster
7
5
4 2

Edan
We model the situation as a network, then the
problem is to find the minimum connector for the
network

B 5 C

3
6 4
8
8
A F D
7
5
4 2

E
Kruskal’s Algorithm
List the edges in
order of size:
B 5 C ED 2
AB 3
3 AE 4
4
8 6 CD 4
BC 5
8 EF 5
A F D CF 6
7 AF 7
5 BF 8
4 CF 8
2

E
Kruskal’s Algorithm

Select the shortest


edge in the network
B 5 C
ED 2
3
4
8 6
8
A F D
7
5
4 2

E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle

ED 2
3 AB 3
4
8 6
8
A F D
7
5
4 2

E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle

ED 2
3 AB 3
4
8 6 CD 4 (or AE 4)

8
A F D
7
5
4 2

E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle

ED 2
3 AB 3
4
8 6 CD 4
AE 4
8
A F D
7
5
4 2

E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle

ED 2
3 AB 3
4
8 6 CD 4
AE 4
8 BC 5 – forms a cycle
A F D EF 5
7
5
4 2

E
Kruskal’s Algorithm
All vertices have been
connected.
B 5 C The solution is
3 ED 2
4
8 6 AB 3
CD 4
8 AE 4
A F D EF 5
7
5
4 Total weight of tree: 18
2

E
Prim’s Algorithm
Select any vertex

B 5 C
A

Select the shortest


3 edge connected to
4
8 6 that vertex

8 AB 3
A F D
7
5
4 2

E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 AE 4
4
8 6
8
A F D
7
5
4 2

E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 ED 2
4
8 6
8
A F D
7
5
4 2

E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 DC 4
4
8 6
8
A F D
7
5
4 2

E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 EF 5
4
8 6
8
A F D
7
5
4 2

E
Prim’s Algorithm
All vertices have been
connected.
B 5 C The solution is
3 AB 3
4
8 6 AE 4
ED 2
8 DC 4
A F D EF 5
7
5
4 Total weight of tree: 18
2

E
Some points to note

•Both algorithms will always give solutions with the


same length.

•They will usually select edges in a different order


– you must show this in your workings.

•Occasionally they will use different edges – this


may happen when you have to choose between
edges with the same length. In this case there is
more than one minimum connector for the
network.
The Shortest Path Algorithms, Dijkstra’s algorithm
http://interactivepython.org/RkmcZ/courselib/static/pythonds/Graphs/graphshortpath.html

You might also like