Dijkstra graph search algorithm

8
PASSAPORN KANCHANASRI NANYANG TECHNOLOGICAL UNIVERSITY Dijkstra Graph Search Algorithm

description

Graph Search Algorithm

Transcript of Dijkstra graph search algorithm

Page 1: Dijkstra graph search algorithm

PASSAPORN KANCHANASRINANYANG TECHNOLOGICAL UNIVERSITY

Dijkstra Graph Search Algorithm

Page 2: Dijkstra graph search algorithm

SHORTEST PATH?

Page 3: Dijkstra graph search algorithm

Lesson Outline

Topic: Dijkstra's Graph Search AlgorithmInstructor: Passaporn Kanchanasri

Aim:The aim of this course is to develop students’ abilities to solve the shortest path problem by using Dijkstra's Graph Search Algorithm. The method of Dijkstra's Graph Search Algorithm is to be examined and demonstrated through an example.

Outcomes:If you successfully complete this course you will be able to:- Explain Dijkstra’s algorithm about its methodology, how it works and how it is used to find the shortest path. - Solve the shortest path problem.

Page 4: Dijkstra graph search algorithm

Outline Time (minutes)

Introducing Dijkstra's Graph Search AlgorithmDijkstra’s Graph Search Algorithm fundamental concept is introduced by instructor.  

3

Solving the shortest path problem Students are randomly assigned a number either A or B. A student who get A will be paired up with a student who get B. They in pairs then solve the given single source shortest path problem on the whiteboard.  

3

Explaining methodologyStudents explain the methodology how to find an answer.  

3

Concluding a lessonStudents conclude what they learn. Finally the instructor does a wrap up.  

1

Page 5: Dijkstra graph search algorithm

QI:Find the shortest path from A to F

A

F

B

C

DE

12

3

1

3

7

6

Page 6: Dijkstra graph search algorithm

Dijkstra Graph Search Algorithm

Dijkstra(Graph,source){dist[source] = 0;for each vertex v in Graph

if v !=sourcedist[v] = infinity;previous[v] = undefined;

end ifadd v to Q;

end forwhile Q is not empty

u = vertex in Q with minimum dist[u];remove u from Q;

for each neighbor v of ualt = dist[u] + length(u,v);if alt < dist[v]

dist[v] = alt;previous[v] = u;

enf ifend for

end whilereturn dist[], previous[];

}

Page 7: Dijkstra graph search algorithm

QI:Find the shortest path from A to F

A

F

B

C

DE

12

3

1

3

7

6

Page 8: Dijkstra graph search algorithm

QII:Find the shortest path from A to F

A

F

B

C

DE

42

3

2

6

3

8

15

3

3