Professional Documents
Culture Documents
Dijkstrw Algorithmx
Dijkstrw Algorithmx
Dijkstra's algorithm
Dijkstra's algorithm - is a solution to the single-source
shortest path problem in graph theory.
Works on both directed and undirected graphs. However, all
edges must have nonnegative weights.
Approach: Greedy
Input: Weighted graph G={E,V} and source vertex vV, such
that all edge weights are nonnegative
Output: Lengths of shortest paths (or the shortest paths
themselves) from a given source vertex vV to all other
vertices
5. predecessor(u) = v;
Class Work
L0(r) =
19
L0(i) =
25
L0(b) =
16
3
1
36
L0(c) =
21
25
L1(r) =
19
L1(b) =
16
3
1
L1(i) = 9
36
L1(c) =
21
25
L2(r) =
19
L2(b) = 19
16
3
1
L2(i) = 9
36
L2(c) =
21
S3 = {a, i, b, r}
L3(a) = 0
25
L3(r) = 24
19
9
5
L3(b) = 19
16
3
1
L3(i) = 9
36
L3(c) =
21
S4 = {a, i, b, r, c}
L4(a) = 0
25
L4(r) =
24
19
9
5
L4(b) = 19
16
3
1
L4(i) =
36
L4(c) = 45
21
Class Work
2
B3
C
5
3
E
1
2
3
D
4
Searching
Difference b/w linear search and binary search
The Binary Search is more efficient than the
linear search, but we must pay initially to sort
the array. Once it is sorted, the best case
performance is one comparison (the searched-for
value is the mid-point value in the original
array). The worst-case, where the value is not in
the array, is log2N, where N is the size of the
array. For example if we have 100 values in an
array or link, we need to check only 50 values for
searching required data element in first iteration.