Docsity

Dijkstra’s Algorithm Example - Object Oriented Programming I | CMSC 132, Study notes of Computer Science

Toggle sidebar
bg1
Dijkstra’s Algorithm Example:
The following example shows how we can run Dijkstra’s algorithm over a
graph. The start vertex is ST.
% → stands for infinity
- → stands for no predecessor
(#) → represents the order the vertices are being processed.
[x,y] → x represents the cost of reaching the node and y the
predecessor.
[0,-] 11 [%,-] 2 [%,-]
ST------->A---------->C<----
| ^4 | | 7
| | | |
| | 5| |
| | v |
--------->B---------->D----
6 [%,-] 3 [%,-]
[0,-] 11 [11,ST] 2 [%,-]
(1)ST------->A---------->C<----
| ^4 | | 7
| | | |
| | 5| | After selecting 1
st
Node
| | v |
--------->B---------->D----
6 [6,ST] 3 [%,-]
[0,-] 11 [10,B] 2 [%,-]
(1)ST------->A---------->C<----
| ^4 | | 7
| | | |
| | 5| | After selecting 2
nd
Node
| (2)| v |
--------->B---------->D----
6 [6,ST] 3 [9,B]
[0,-] 11 [10,B] 2 [16,D]
(1)ST------->A---------->C<----
| ^4 | | 7
| | | | After selecting 3
rd
Node
| | 5| |
| (2)| (3)v |
--------->B---------->D----
6 [6,ST] 3 [9,B]
pf2

Partial preview of the text

Download Dijkstra’s Algorithm Example - Object Oriented Programming I | CMSC 132 and more Study notes Computer Science in PDF only on Docsity!

Dijkstra’s Algorithm Example:

The following example shows how we can run Dijkstra’s algorithm over a graph. The start vertex is ST.

% → stands for infinity

  • → stands for no predecessor (#) → represents the order the vertices are being processed. [x,y] → x represents the cost of reaching the node and y the predecessor.

[0,-] 11 [%,-] 2 [%,-]

ST------->A---------->C<----

| ^4 | | 7

| | v | --------->B---------->D---- 6 [%,-] 3 [%,-]

[0,-] 11 [11,ST] 2 [%,-]

(1)ST------->A---------->C<----

| ^4 | | 7

| | 5| | After selecting 1 st^ Node | | v | --------->B---------->D---- 6 [6,ST] 3 [%,-]

[0,-] 11 [10,B] 2 [%,-]

(1)ST------->A---------->C<----

| ^4 | | 7

| | 5| | After selecting 2 nd^ Node | (2)| v | --------->B---------->D---- 6 [6,ST] 3 [9,B]

[0,-] 11 [10,B] 2 [16,D]

(1)ST------->A---------->C<----

| ^4 | | 7

| | | | After selecting 3 rd^ Node | | 5| | | (2)| (3)v | --------->B---------->D---- 6 [6,ST] 3 [9,B]

[0,-] 11 [10,B] 2 [12,A]

(1)ST------->A---------->C<----

| (4)^4 | | 7

| | 5| | After selecting 4 th^ Node | (2)| (3)v | --------->B---------->D---- 6 [6,ST] 3 [9,B]

[0,-] 11 [10,B] 2 [12,A]

(1)ST------->A---------->C<----

| (4)^4 (5)| | 7

| | 5| | After selecting 5 th^ Node | (2)| (3)v | --------->B---------->D---- 6 [6,ST] 3 [9,B]