Professional Documents
Culture Documents
Assignmenthomework
ICT-5102
Homework Assignment 2
To Honorable:
Dr. Hussain Asiful Mustafa
Assistant Professor
IICT-BUET.
Submitted By:
Md.Dedarul Hasan
Reg.Id: 0417311011
PGD in IT, IICT-BUET.
4/9/2019
IICT, BUET
TO FIND THE LONGEST PATH FOR THAT GRAPH BY DIJKSTRA ALGORITHM
Distance (A)=0
Source=’A’
A
6 5
5
∞ B C
∞
2 3
3
F 2
3 1
∞
D
E ∞
∞ 4
Dijkstra’s algorithm to find the Longest path between A and B. It picks the unvisited vertex with the
lowest distance, calculates the distance through it to each unvisited neighbor and updates the neighbors
distance if smaller. Mark visited when done with neighbors.
But for that requirement of Dijkstra’s algorithm to find out the longest path we will find pick the
unvisited vertex with the highest distance & calculate the distance through it to each unvisited neighbor &
updates the neighbors distance if greater. Mark visited when done with the neighbors.
Modification of that graph by Dijkstra Algorithm- step by step for longest path:
STEP1:
Distance(B)=6
Distance(C)=5
A
6 5
5
6 B C
5
2 3
3
F 2
3 1
∞
D
E ∞
∞ 4
Distance(C)=6+5=11
A
6 5
5
6 B C
11
2 3
3
F 2
3 1
2
D
E ∞
3 4
Fig: 3
STEP3:
Distance(F)=11+3=14
Distance(D)=11+2=13
A
6 5
5
6 B C
11
2 3
3
F 2
3 1
14
E D
13
3 4
Fig: 4
STEP4:
Distance(E)=14+3=17
Distance(D)=14+1=15
A
6 5
5
6 B C
11
2 3
3
F 2
3 1
14
E D
15
17 4
Fig :5
STEP5:
Distance(D)=17+4=21
A
6 5
5
6 B C
11
2 3
3
F 2
3 1
14
E D
21
17 4
Fig: 6
STEP6:
A
6 5
5
6 B C
11
2 3
3
F 2
3 1
14
E D
21
17 4
Fig: 7
STEP7:
6 B C 11
14 F
21
17 E D
Dijkstra():
v's distance:=infinity.
v's previous:=none.
v1's distance:=0.
List:={all vertics}
Mark v as known.
n's distance:=dist.
n's previous:=v.
We have assigned that graph which has to be converted as a tree node structure: [input array]
A B C D E F
A 0 6 5 0 0 0
B 0 0 5 0 3 2
C 0 5 0 2 0 3
D 0 0 0 0 0 1
E 0 0 0 4 0 0
F 0 0 0 0 3 0
Output:
RESULT as Graph
C
B
E D
METARIALS
CodeBlocks
Sublime Text Editor
Ms Word To Draw Graph
CONCLUSION
REFERENCE
Class Lectures
Stack Overflow
Dynamic Programming For Longest Path Solution Sequence