SlideShare a Scribd company logo
1 of 13
Download to read offline
Data Structure & Algorithm
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’
Fig : 1 .given graph for longest path find
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:
 First Source ‘A’ is ‘0’ & others vertex is ∞
 We have picked highest distance for unvisited vertex & calculated through it to each unvisited neighbor
and updated the neighbor distance for greater.
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
∞∞
∞
∞
∞
ALGORITHM FOR THAT GRAPH TO FIND LONGEST PATH
STEP1:
Distance(B)=6
Distance(C)=5
Fig: 2Pick vertex in List with maximum distance, i.e., B
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
56
∞
∞
∞
STEP2:
Distance(C)=6+5=11
Fig: 3
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
116
3
∞
2
STEP3:
Distance(F)=11+3=14
Distance(D)=11+2=13
Fig: 4
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
116
3
13
14
STEP4:
Distance(E)=14+3=17
Distance(D)=14+1=15
Fig :5
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
116
17
15
14
STEP5:
Distance(D)=17+4=21
Fig: 6
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
116
17
21
14
STEP6:
Longest Path Cost is= 6+11+14+17+21=69
Fig: 7
A
F
CB
DE
56
2
3
2
5
3
3 1
4
0
116
17
21
14
STEP7:
The Final Graph for longest path
Fig: 7 –Longest Path Final for the graph G(V,E)
A
B
F
E D
C
0
116
14
21
17
PSEUDOCODES FOR THAT LONGEST PATH USING DIJKSTRA’S ALGORITHM
Dijkstra():
for each vertex v:
v's distance:=infinity.
v's previous:=none.
v1's distance:=0.
List:={all vertics}
while List is not empty:
v:=remove List vertex with MAXIMUM distance.
Mark v as known.
for each unknown neighbor n of v:
dist:=v's distance+edge(v,n)'s weight.
if dist is GREATER than n's distance:
n's distance:=dist.
n's previous:=v.
Reconstruct path from v2 back to v1, following previous pointers.
IMPLEMENTATIONS CODE
We have assigned that graph which has to be converted as a tree node structure: [input array]
From Step 1-7:
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
Programming Code Using c :
EXECUTION OF PROGRAM IMPLEMENTATION & OUTPUT GRAPH WHERE SOURCE IS ‘A’
Output:
RESULT as Graph
METARIALS
CodeBlocks
Sublime Text Editor
Ms Word To Draw Graph
CONCLUSION
Total Longest Path Graph is: A B C F E D
REFERENCE
Class Lectures
Stack Overflow
Dynamic Programming For Longest Path Solution Sequence
A
B
F
E D
C

More Related Content

What's hot

Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
faisal2204
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
taimurkhan803
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 

What's hot (19)

Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
d
dd
d
 
6 Hiclus
6 Hiclus6 Hiclus
6 Hiclus
 
Perimeter 1
Perimeter 1Perimeter 1
Perimeter 1
 
11.3 Distance Midpoint Formulas
11.3 Distance Midpoint Formulas11.3 Distance Midpoint Formulas
11.3 Distance Midpoint Formulas
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
 
Homework1
Homework1Homework1
Homework1
 
6 Concor
6 Concor6 Concor
6 Concor
 
Metodo de bairstow
Metodo de bairstowMetodo de bairstow
Metodo de bairstow
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics Presentation
 
Hamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's AlgorithmHamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's Algorithm
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Vectors mod-1-part-1
Vectors mod-1-part-1Vectors mod-1-part-1
Vectors mod-1-part-1
 
linear Algebra least squares
linear Algebra least squareslinear Algebra least squares
linear Algebra least squares
 
Least Squares method
Least Squares methodLeast Squares method
Least Squares method
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 

Similar to Assignment homework 2

AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithmAAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
SantoshDood
 
shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
zefergaming
 
IAP presentation-1.pptx
IAP presentation-1.pptxIAP presentation-1.pptx
IAP presentation-1.pptx
HirazNor
 

Similar to Assignment homework 2 (20)

Dijsktra’s Sortest path algorithm
Dijsktra’s Sortest path algorithmDijsktra’s Sortest path algorithm
Dijsktra’s Sortest path algorithm
 
Dijesktra 1.ppt
Dijesktra 1.pptDijesktra 1.ppt
Dijesktra 1.ppt
 
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
 
routing algorithm
routing algorithmrouting algorithm
routing algorithm
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Dijkstra algorithm
Dijkstra algorithmDijkstra algorithm
Dijkstra algorithm
 
routing alg.pptx
routing alg.pptxrouting alg.pptx
routing alg.pptx
 
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithmAAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
 
Jaimin chp-5 - network layer- 2011 batch
Jaimin   chp-5 - network layer- 2011 batchJaimin   chp-5 - network layer- 2011 batch
Jaimin chp-5 - network layer- 2011 batch
 
Unit 3 Informed Search Strategies.pptx
Unit  3 Informed Search Strategies.pptxUnit  3 Informed Search Strategies.pptx
Unit 3 Informed Search Strategies.pptx
 
shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
Shortest path analysis
Shortest path analysis Shortest path analysis
Shortest path analysis
 
IAP PPT-1.pptx
IAP PPT-1.pptxIAP PPT-1.pptx
IAP PPT-1.pptx
 
IAP presentation-1.pptx
IAP presentation-1.pptxIAP presentation-1.pptx
IAP presentation-1.pptx
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in python
 
Comparative Analysis of Distance Vector Routing & Link State Protocols
Comparative Analysis of Distance Vector Routing & Link State ProtocolsComparative Analysis of Distance Vector Routing & Link State Protocols
Comparative Analysis of Distance Vector Routing & Link State Protocols
 
Digital Distance Geometry
Digital Distance GeometryDigital Distance Geometry
Digital Distance Geometry
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
ENHANCEMENT OF TRANSMISSION RANGE ASSIGNMENT FOR CLUSTERED WIRELESS SENSOR NE...
ENHANCEMENT OF TRANSMISSION RANGE ASSIGNMENT FOR CLUSTERED WIRELESS SENSOR NE...ENHANCEMENT OF TRANSMISSION RANGE ASSIGNMENT FOR CLUSTERED WIRELESS SENSOR NE...
ENHANCEMENT OF TRANSMISSION RANGE ASSIGNMENT FOR CLUSTERED WIRELESS SENSOR NE...
 

More from LITS IT Ltd,LASRC.SPACE,SAWDAGOR BD,FREELANCE BD,iREV,BD LAW ACADEMY,SMART AVI,HEA,HFSAC LTD.

More from LITS IT Ltd,LASRC.SPACE,SAWDAGOR BD,FREELANCE BD,iREV,BD LAW ACADEMY,SMART AVI,HEA,HFSAC LTD. (20)

লালমনিরহাট ৩ আসনের ভোট কেন্দ্র সমুহ - LALMONIRHAT 3 SADAR VOTE CENTER ALL
লালমনিরহাট ৩ আসনের ভোট কেন্দ্র সমুহ - LALMONIRHAT 3 SADAR VOTE CENTER ALLলালমনিরহাট ৩ আসনের ভোট কেন্দ্র সমুহ - LALMONIRHAT 3 SADAR VOTE CENTER ALL
লালমনিরহাট ৩ আসনের ভোট কেন্দ্র সমুহ - LALMONIRHAT 3 SADAR VOTE CENTER ALL
 
লালমনিরহাট ৩ আসনের ওয়ার্ড সমূহ - LALMONIRHAT 3 WARD LIST ALL
লালমনিরহাট ৩ আসনের ওয়ার্ড সমূহ - LALMONIRHAT 3 WARD LIST ALLলালমনিরহাট ৩ আসনের ওয়ার্ড সমূহ - LALMONIRHAT 3 WARD LIST ALL
লালমনিরহাট ৩ আসনের ওয়ার্ড সমূহ - LALMONIRHAT 3 WARD LIST ALL
 
ভূমি সংশ্লিষ্ট অপরাধ প্রতিকার ও প্রতিরোধ ৩৬ নং আইন, ২০২৩,
ভূমি সংশ্লিষ্ট অপরাধ প্রতিকার ও প্রতিরোধ  ৩৬ নং আইন, ২০২৩, ভূমি সংশ্লিষ্ট অপরাধ প্রতিকার ও প্রতিরোধ  ৩৬ নং আইন, ২০২৩,
ভূমি সংশ্লিষ্ট অপরাধ প্রতিকার ও প্রতিরোধ ৩৬ নং আইন, ২০২৩,
 
CrPC BARE ACT -1898 BANGLA.pdf
CrPC BARE ACT -1898  BANGLA.pdfCrPC BARE ACT -1898  BANGLA.pdf
CrPC BARE ACT -1898 BANGLA.pdf
 
CPC BARE ACT -1908 BANGLA.pdf
CPC BARE ACT -1908  BANGLA.pdfCPC BARE ACT -1908  BANGLA.pdf
CPC BARE ACT -1908 BANGLA.pdf
 
PC BARE ACT -1860 BANGLA.pdf
PC BARE ACT -1860  BANGLA.pdfPC BARE ACT -1860  BANGLA.pdf
PC BARE ACT -1860 BANGLA.pdf
 
SR BARE ACT -1877 BANGLA.pdf
SR BARE ACT -1877  BANGLA.pdfSR BARE ACT -1877  BANGLA.pdf
SR BARE ACT -1877 BANGLA.pdf
 
The Bangladesh Legal Practitioner_s and Bar Council Order, 1972.pdf
The Bangladesh Legal Practitioner_s and Bar Council Order, 1972.pdfThe Bangladesh Legal Practitioner_s and Bar Council Order, 1972.pdf
The Bangladesh Legal Practitioner_s and Bar Council Order, 1972.pdf
 
LA BARE ACT -1908 BANGLA.pdf
LA BARE ACT -1908  BANGLA.pdfLA BARE ACT -1908  BANGLA.pdf
LA BARE ACT -1908 BANGLA.pdf
 
EA BARE ACT -1872 BANGLA.pdf
EA BARE ACT -1872  BANGLA.pdfEA BARE ACT -1872  BANGLA.pdf
EA BARE ACT -1872 BANGLA.pdf
 
DIGITAL COMMERCE LAWS & RULES 2021.docx
DIGITAL COMMERCE LAWS & RULES 2021.docxDIGITAL COMMERCE LAWS & RULES 2021.docx
DIGITAL COMMERCE LAWS & RULES 2021.docx
 
Programming Your Home Automate with Arduino, Android, and Your Computer.pdf
Programming Your Home Automate with Arduino, Android, and Your Computer.pdfProgramming Your Home Automate with Arduino, Android, and Your Computer.pdf
Programming Your Home Automate with Arduino, Android, and Your Computer.pdf
 
Web site Review & Description by tanbircox.pdf
Web site Review & Description by tanbircox.pdfWeb site Review & Description by tanbircox.pdf
Web site Review & Description by tanbircox.pdf
 
Basic Electronics.pdf
Basic Electronics.pdfBasic Electronics.pdf
Basic Electronics.pdf
 
Circuit book_PP.pdf
Circuit book_PP.pdfCircuit book_PP.pdf
Circuit book_PP.pdf
 
Microcontroller.pdf
Microcontroller.pdfMicrocontroller.pdf
Microcontroller.pdf
 
Digital_electronics_dynamic.pdf
Digital_electronics_dynamic.pdfDigital_electronics_dynamic.pdf
Digital_electronics_dynamic.pdf
 
Project Electronics_Copy.pdf
Project Electronics_Copy.pdfProject Electronics_Copy.pdf
Project Electronics_Copy.pdf
 
বিবিসি রুলেস ও অরডার, ১৯৭২ বেয়ার এক্ট -BBC BARE ACT.docx
বিবিসি রুলেস ও অরডার, ১৯৭২ বেয়ার এক্ট -BBC BARE ACT.docxবিবিসি রুলেস ও অরডার, ১৯৭২ বেয়ার এক্ট -BBC BARE ACT.docx
বিবিসি রুলেস ও অরডার, ১৯৭২ বেয়ার এক্ট -BBC BARE ACT.docx
 
সুঃ প্রতিকার আইন ১৮৭৭ নোট.docx
সুঃ প্রতিকার আইন ১৮৭৭ নোট.docxসুঃ প্রতিকার আইন ১৮৭৭ নোট.docx
সুঃ প্রতিকার আইন ১৮৭৭ নোট.docx
 

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 

Assignment homework 2

  • 1. Data Structure & Algorithm 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
  • 2. TO FIND THE LONGEST PATH FOR THAT GRAPH BY DIJKSTRA ALGORITHM Distance (A)=0 Source=’A’ Fig : 1 .given graph for longest path find 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:  First Source ‘A’ is ‘0’ & others vertex is ∞  We have picked highest distance for unvisited vertex & calculated through it to each unvisited neighbor and updated the neighbor distance for greater. A F CB DE 56 2 3 2 5 3 3 1 4 0 ∞∞ ∞ ∞ ∞
  • 3. ALGORITHM FOR THAT GRAPH TO FIND LONGEST PATH STEP1: Distance(B)=6 Distance(C)=5 Fig: 2Pick vertex in List with maximum distance, i.e., B A F CB DE 56 2 3 2 5 3 3 1 4 0 56 ∞ ∞ ∞
  • 8. STEP6: Longest Path Cost is= 6+11+14+17+21=69 Fig: 7 A F CB DE 56 2 3 2 5 3 3 1 4 0 116 17 21 14
  • 9. STEP7: The Final Graph for longest path Fig: 7 –Longest Path Final for the graph G(V,E) A B F E D C 0 116 14 21 17
  • 10. PSEUDOCODES FOR THAT LONGEST PATH USING DIJKSTRA’S ALGORITHM Dijkstra(): for each vertex v: v's distance:=infinity. v's previous:=none. v1's distance:=0. List:={all vertics} while List is not empty: v:=remove List vertex with MAXIMUM distance. Mark v as known. for each unknown neighbor n of v: dist:=v's distance+edge(v,n)'s weight. if dist is GREATER than n's distance: n's distance:=dist. n's previous:=v. Reconstruct path from v2 back to v1, following previous pointers.
  • 11. IMPLEMENTATIONS CODE We have assigned that graph which has to be converted as a tree node structure: [input array] From Step 1-7: 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 Programming Code Using c :
  • 12. EXECUTION OF PROGRAM IMPLEMENTATION & OUTPUT GRAPH WHERE SOURCE IS ‘A’ Output:
  • 13. RESULT as Graph METARIALS CodeBlocks Sublime Text Editor Ms Word To Draw Graph CONCLUSION Total Longest Path Graph is: A B C F E D REFERENCE Class Lectures Stack Overflow Dynamic Programming For Longest Path Solution Sequence A B F E D C