Professional Documents
Culture Documents
Week 3
B
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Week 03: Graph Algorithms CSE506
14
C 6
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Week 03: Graph Algorithms CSE506
The number
of subsets of
an n-element
set is 2n .
26 7
267 - 26*25*24*23*22*21*20
Sometimes it is easiest
to count something by
counting its opposite.
7
2) C choices o f positions for the S's
3
4 choices for the Y
3 choices for the T
2 choices for the E
1 choice for the M
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Week 03: Graph Algorithms CSE506
SYSTEMS
7! 7!
4 321 = = 840
3!4 ! 3!
7!
= 840
3 !
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Week 03: Graph Algorithms CSE506
Work SMART
not
HARD
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Week 03: Graph Algorithms CSE506
Graph Algorithms
Graph Definitions
A graph G is denoted by G = (V, E) where
V is the set of vertices or nodes of the graph
E is the set of edges or arcs connecting the vertices in V
Each edge E is denoted as a pair (v,w) where v,w V
For example in the graph below
2 V = {1, 2, 3, 4, 5, 6}
E = {(1, 2) (2, 5) (3, 6) (4, 6) (5, 6)}
1 3 This is an example of an unordered
or undirected graph
6 4
1 3 Here,
V = {1, 2, 3, 4, 5, 6}
E = {(1, 2) (2, 5) (5, 6) (6, 3) (6, 4)}
6 4
5
Vertex v is adjacent to w iff (v,w) E
Sometimes an edge has another component called a weight or
cost. If the weight is absent it is assumed to be 1
Applications of Graphs
Driving Map
Edge = Road
Vertex = Intersection
Edge weight = Time required to cover the road
Airline Traffic
Vertex = Cities serviced by the airline
Edge = Flight exists between two cities
Edge weight = Flight time or flight cost or both
Computer networks
Vertex = Server nodes
Edge = Data link
Edge weight = Connection speed
CAD/VLSI
Spanning Tree
Motivation
For an electrical circuit certain pins have to be grounded. Finding the
arrangement of wires (connecting those pins) that uses the least amount of
wire.
Let a G(V,E) be a graph such that (u, v) E and a weight w(u,v)
corresponding to wire needed to join u and v.
We are looking for an acyclic subset T E that connects all vertices and
whose total weight w(T) is minimized.
w(T ) = (u ,v )T w(u , v)
6 4
5 9
14 2
10
15
3 8
Prims Algorithm
Prims Algorithm
Prims Algorithm
O(|V|2) if matrix