Algorithm
Algorithm
Greedy Algorithm
Kruskal’s Algorithm
Perfect Graph Theorem
MD.FAZLAY MD.ABDUL
RABBY BASET
Roll:21
Batch:28 Associate Prof.
Dept. of CSE
Dhaka International
University
GREEDY ALGORITHM
A greedy Algorithm always makes the choice that looks best at that moment.
* optimization problem:
Bus 32minute
Car 15minute
Train 40minute
Walk 1 hour
Optimal solution
Feasible Solution:
A solution which are satisfying the condition given in the problem that called
Feasible solution thaw there are given problem there are many solution.
It is used for finding the minimum Spanning Tree of the given graph.
*Spanning Tree:
A spanning Tree of a graph is just a sub graph that contain all the
vertices and is a Tree.
*Tree:
Acyclic graph where have no cycle.
To apply Kruskal’s Algorithm the given graph must be -
Weight
Connected
Undirected
Step 1: Sort the all edge from low weight to high weight.
Step 2: # Take the edge with the lower weight and use it to connect the
Vertices of graph.
#If adding an edge create a cycle then reject that edge and
go for the next least weight edge.
Step 3: Keep adding edges until all the vertices are connected and a
Minimum spanning tree is obtained.
Problem:
Construct the minimum spanning tree for the given graph using Kruskal’s Algorithm-:
28
D E
10 16
14
A B C
24 18
25 12
F G
22
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:1
D E
A B C
F G
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:2
D E
10
A B C
F G
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:3
D E
10
A B C
12
F G
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:4
D E
10
14
A B C
12
F G
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:5
D E
10 16
14
A B C
12
F G
28
D E
10 16
14
A B C
24 18
25 12
F G
22
Avoiding Cycle Matters..
D E
10 16
14
A B C
18
12
F G
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:6
D E
10 16
14
A B C
12
F G
22
D E
10 16
14
A B C
24 18
25 12
F G
22
D E
10 16
14
A B C
24
12
F G
22
28
D E
10 16
14
A B C
24 18
25 12
F G
22
STEP
:7
D E
10 16
14
A B C
25 12
F G
22
D E
10 16
14
A B C
25 12
F G
22
Here,
W(H)=3
X((H)=3
W(H)=X(H)
*clique number:
Color (red,yellow,blue,black)=4