SlideShare a Scribd company logo
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

PPTX
Shortest path algorithm
PPTX
Shortest path algorithm
PPTX
7.4 A arc length
PPTX
Networks dijkstra's algorithm- pgsr
PDF
PPT
Unit26 shortest pathalgorithm
PPTX
Shortest path problem
PPT
Spanning trees
Shortest path algorithm
Shortest path algorithm
7.4 A arc length
Networks dijkstra's algorithm- pgsr
Unit26 shortest pathalgorithm
Shortest path problem
Spanning trees

What's hot (18)

PPTX
Dijkstra’s algorithm
PPT
PPT
Perimeter 1
PPT
11.3 Distance Midpoint Formulas
PPTX
Bellman ford Algorithm
PDF
Homework1
PPT
DOCX
Metodo de bairstow
PPTX
Dijkstra's Algorithm
PPTX
Minimum spanning tree
PPT
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
PPTX
Discrete Mathematics Presentation
PPTX
Hamilton Path & Dijkstra's Algorithm
PPTX
Data structure and algorithm
PPTX
Vectors mod-1-part-1
PPT
linear Algebra least squares
PDF
All pairs shortest path algorithm
Dijkstra’s algorithm
Perimeter 1
11.3 Distance Midpoint Formulas
Bellman ford Algorithm
Homework1
Metodo de bairstow
Dijkstra's Algorithm
Minimum spanning tree
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Discrete Mathematics Presentation
Hamilton Path & Dijkstra's Algorithm
Data structure and algorithm
Vectors mod-1-part-1
linear Algebra least squares
All pairs shortest path algorithm
Ad

Similar to Assignment homework 2 (20)

PPT
Dijsktra’s Sortest path algorithm
PPT
Dijesktra 1.ppt
PDF
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
PPTX
routing algorithm
PPTX
Dijkstra's algorithm presentation
PPTX
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
PPTX
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
PDF
Dijkstra algorithm
PPTX
routing alg.pptx
PPT
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
PPT
routing1 1X3 Router (capable of routing the data packets.ppt
PPT
Jaimin chp-5 - network layer- 2011 batch
PPTX
Unit 3 Informed Search Strategies.pptx
PDF
shortestpathalgorithm-180109112405 (1).pdf
PPT
Dijkstra.ppt
PPTX
Floyd warshall algorithm and it's applications
PPT
graph in Data Structures and Algorithm.ppt
PPTX
Shortest path analysis
PPTX
IAP PPT-1.pptx
PPTX
IAP presentation-1.pptx
Dijsktra’s Sortest path algorithm
Dijesktra 1.ppt
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
routing algorithm
Dijkstra's algorithm presentation
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
Dijkstra algorithm
routing alg.pptx
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
routing1 1X3 Router (capable of routing the data packets.ppt
Jaimin chp-5 - network layer- 2011 batch
Unit 3 Informed Search Strategies.pptx
shortestpathalgorithm-180109112405 (1).pdf
Dijkstra.ppt
Floyd warshall algorithm and it's applications
graph in Data Structures and Algorithm.ppt
Shortest path analysis
IAP PPT-1.pptx
IAP presentation-1.pptx
Ad

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

DOCX
PDF
লালমনিরহাট ৩ আসনের ভোট কেন্দ্র সমুহ - LALMONIRHAT 3 SADAR VOTE CENTER ALL
PDF
লালমনিরহাট ৩ আসনের ওয়ার্ড সমূহ - LALMONIRHAT 3 WARD LIST ALL
PDF
ভূমি সংশ্লিষ্ট অপরাধ প্রতিকার ও প্রতিরোধ ৩৬ নং আইন, ২০২৩,
PDF
The Bangladesh Legal Practitioner_s and Bar Council Order, 1972.pdf
PDF
Programming Your Home Automate with Arduino, Android, and Your Computer.pdf
DOCX
বিবিসি রুলেস ও অরডার, ১৯৭২ বেয়ার এক্ট -BBC BARE ACT.docx
লালমনিরহাট ৩ আসনের ভোট কেন্দ্র সমুহ - LALMONIRHAT 3 SADAR VOTE CENTER ALL
লালমনিরহাট ৩ আসনের ওয়ার্ড সমূহ - LALMONIRHAT 3 WARD LIST ALL
ভূমি সংশ্লিষ্ট অপরাধ প্রতিকার ও প্রতিরোধ ৩৬ নং আইন, ২০২৩,
The Bangladesh Legal Practitioner_s and Bar Council Order, 1972.pdf
Programming Your Home Automate with Arduino, Android, and Your Computer.pdf
বিবিসি রুলেস ও অরডার, ১৯৭২ বেয়ার এক্ট -BBC BARE ACT.docx

Recently uploaded (20)

PPT
Total quality management ppt for engineering students
PPTX
Feature types and data preprocessing steps
PPTX
Current and future trends in Computer Vision.pptx
PDF
Design Guidelines and solutions for Plastics parts
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
Software Engineering and software moduleing
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Total quality management ppt for engineering students
Feature types and data preprocessing steps
Current and future trends in Computer Vision.pptx
Design Guidelines and solutions for Plastics parts
Information Storage and Retrieval Techniques Unit III
distributed database system" (DDBS) is often used to refer to both the distri...
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
Module 8- Technological and Communication Skills.pptx
Visual Aids for Exploratory Data Analysis.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Abrasive, erosive and cavitation wear.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Software Engineering and software moduleing
Exploratory_Data_Analysis_Fundamentals.pdf
Soil Improvement Techniques Note - Rabbi
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Fundamentals of Mechanical Engineering.pptx
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf

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