Skip to content

Commit 9a8467f

Browse files
author
Taras Nikulin
committed
Final edits
1 parent 9575a67 commit 9a8467f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Dijkstra Algorithm/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
This [algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) was invented in 1956 by Edsger W. Dijkstra.
44

5-
This algorithm can be used, when you have one source vertex and want to find the shortest paths to all other vertices in the graph.
5+
It can be used, when you have one source vertex and want to find the shortest paths to all other vertices in the graph.
66

77
The best example is road network. If you wnat to find the shortest path from your house to your job, then it is time for the Dijkstra's algorithm.
88

9-
I have created **VisualizedDijkstra.playground** to help you to understand, how this algorithm works. Besides, I have described below step by step how does it works.
9+
I have created **VisualizedDijkstra.playground** to improve your understanding of the algorithm's flow. Besides, below is step by step algorithm's description.
1010

11-
So let's imagine, that your house is "A" vertex and your job is "B" vertex. And you are lucky, you have graph with all possible routes.
11+
Let's imagine, you want to go to the shop. Your house is A vertex and there are 4 possible stores around your house. How to find the closest one/ones? Luckily, you have graph, that connects your house with all these stores. So, you know what to do :)
1212

1313
## Initialization
1414

@@ -30,7 +30,7 @@ The table below represents graph state:
3030
3131
>T states for True
3232
33-
To initialize out graph we have to set source vertex path length from source vertex to 0, and append itself to path vertices ffrom start.
33+
To initialize our graph we have to set source vertex path length from source vertex to 0, and append itself to path vertices from start.
3434

3535
| | A | B | C | D | E |
3636
|:------------------------- |:---:|:---:|:---:|:---:|:---:|
@@ -40,7 +40,7 @@ To initialize out graph we have to set source vertex path length from source ver
4040

4141
Great, now our graph is initialized and we can pass it to the Dijkstra's algorithm.
4242

43-
But before we will go through all process side by side let me explain how algorithm works.
43+
But before we will go through all process side by side read this explanation.
4444
The algorithm repeats following cycle until all vertices are marked as visited.
4545
Cycle:
4646
1. From the non-visited vertices the algorithm picks a vertex with the shortest path length from the start (if there are more than one vertex with the same shortest path value, then algorithm picks any of them)
@@ -50,7 +50,7 @@ When all vertices are marked as visited, the algorithm's job is done. Now, you c
5050

5151
Okay, let's start!
5252
Let's follow the algorithm's cycle and pick the first vertex, which neighbors we want to check.
53-
All our vertices are not visited, but there is only one have the smallest path length from start - A. This vertex is th first one, which neighbors we will check.
53+
All our vertices are not visited, but there is only one has the smallest path length from start - A. This vertex is the first one, which neighbors we will check.
5454
First of all, set this vertex as visited
5555

5656
A.visited = true
@@ -268,7 +268,9 @@ public class Dijkstra {
268268

269269
That's all! Now you can check this algorithm in the playground. On the main page there is a code for creating random graph.
270270

271-
Also there is a **VisualizedDijkstra.playground**. Use it to figure out algorithm flow in real (slowed :)) time.
271+
Also there is a **VisualizedDijkstra.playground**. Use it to figure out algorithm's flow in real (slowed :)) time.
272+
273+
It is up to you how to implement some specific parts of algorithm, you can use Array instead of Set, add _visited_ property to Vertex or you can create some local totalVertices Array/Set inside _func findShortestPaths(from startVertex: Vertex)_ to keep totalVertices Array/Set unchanged. This is a general explanation with one possible implementation :)
272274

273275
## About this repository
274276

0 commit comments

Comments
 (0)