Graph Theory
Graph Theory
Graph Algorithm;
Prim; Kruskal
TWO TYPES OF GRAPH
DIRECTEDGRAPH
UNDIRECTED GRAPH
What is a
Directed
Graph?
A graph is a Directed Graph
when the pair of vertices
representing any edge by an
ordered or a direct pair (V1,
V2)
Where V1, is the tail and V2 is
the head of the edge.
Thus, <V1, V2> and <V2,
V1> represent two different
edges.
V1 V2
What is an
Undirected Graph?
A graph is called
Undirected Graph
when the pair of
vertices
representing any
edge is unordered.
Thus <V1,V2> and
<V2,V1> represent
the same.
What is Graph
Algorithm?
A graph algorithm is a step-by-step
method used to solve problems related
to graphs in computer science and
mathematics. A graph is made up of
nodes (vertices) and edges
(connections between nodes). These
algorithms help us find things like the
shortest path between two points,
whether two nodes are connected, or the
best way to visit all nodes.
STEP-BY-STEP of Graph Algorithm
2️⃣Choose the Right
11️⃣ Represent the
Algorithm → Pick BFS (for
Graph → Use an adjacency
level-order search), DFS (for
list or adjacency matrix to
deep search), Dijkstra (for
store connections between
shortest path), or Kruskal/Prim
nodes.
(for minimum spanning tree).
SUBGRAPH
All vertices are connected
No CYCLES
EXAMPLE
Pauline is a gardener and has
created a sprinkler system in
the given diagram. Using
Prim’s algorithm, determine
the network that will connect
all of the sprinklers with the
least amount of piping and
determine the total length of
piping needed. Each vertex
represents a sprinkler and the
weight of each edge represents
the distance in meters.
ACTIVITY 1
The management of a Kerry campsite
wants to connect each mobile home with
running water in the easiest way possible.
Each mobile home is represented by a
letter and the weight on each edge
represents the distance between the
mobile homes in metres.
(i) Determine the Minimum Spanning
Tree so that every mobile home is
connected to running water using the
least length of piping.
(ii) Calculate the total length of pipe
needed.
ACTIVITY 2
3 4
ACTIVITY 5
Create a minimum spanning tree.
KRUSKAL’S
ALGORITHM
What is Kruskal Algorithm?