Skip to content

Commit 6c47786

Browse files
committed
Graph alg explanations
1 parent 11f7f69 commit 6c47786

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

src/algorithms/pseudocode/AStar.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ export default parse(`
1111
// on a measure of the distance from each node to e).
1212
\\In{
1313
initialise, with fontier={s}, stored in Nodes \\Ref Init
14-
while Nodes not empty \\B 2
15-
\\Expl{Nodes is the data structure where we store the nodes that are
16-
in the frontier. In the A* algorithm, Nodes is a Priority Queue.
14+
while Nodes is not empty \\B 2
15+
\\Expl{ Nodes is the data structure used to represent the frontier.
16+
For A*, Nodes is a priority queue, ordered on Length (the minumum
17+
found so far) plus the heuristic value. Here we highlight the Min
18+
value. The priority queue also contains nodes that have not been
19+
seen, which have infinite Length. The frontier nodes are those
20+
shown with a finite Length so far. Nodes with no Length shown
21+
have been finalised. The frontier and finalised nodes are also
22+
highlighted in the graph display.
1723
\\Expl}
1824
\\In{
1925
remove next node n from Nodes and finalise it \\Ref Next_node

src/algorithms/pseudocode/BFS.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ export default parse(`
1111
// node i (if one has been found; Parent[i] = 0 otherwise).
1212
\\In{
1313
initialise, with fontier={s}, stored in Nodes \\Ref Init
14-
while Nodes not empty \\B 2
14+
while Nodes is not empty \\B 2
15+
\\Expl{ Nodes is the data structure used to represent the frontier.
16+
For BFS, Nodes is a queue, shown below the arrays. The frontier
17+
nodes are simply those in the queue (they are also marked as
18+
Seen). The Seen nodes that are no longer in the queue are
19+
finalised. The frontier and finalised nodes are also highlighted
20+
in the graph display.
21+
\\Expl}
1522
\\In{
1623
remove next node n from Nodes and finalise it \\Ref Next_node
1724
// The Parent of n has now been determined

src/algorithms/pseudocode/DFS.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ export default parse(`
1111
// node i (if one has been found; Parent[i] = 0 otherwise).
1212
\\In{
1313
initialise, with fontier={s}, stored in Nodes \\Ref Init
14-
while Nodes not empty \\B 2
14+
while Nodes is not empty \\B 2
15+
\\Expl{ Nodes is the data structure used to represent the frontier.
16+
For DFS, Nodes is a stack, shown below the arrays.
17+
The stack can have repeated elements and when we pop a node off
18+
the stack it is ignored if it has already been finalised.
19+
The frontier nodes are those in the stack that are not finalised.
20+
The frontier and finalised nodes are also highlighted in the
21+
graph display.
22+
\\Expl}
1523
\\In{
1624
remove next node n from Nodes and finalise it \\Ref Next_node
1725
// The Parent of n has now been determined

src/algorithms/pseudocode/dijkstra.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ Shortest(G, s) //Given a graph G find a shortest path from start node s \\B 1
1111
// node i (if one has been found; Parent[i] = 0 otherwise).
1212
\\In{
1313
initialise, with fontier={s}, stored in Nodes \\Ref Init
14-
while Nodes not empty \\B 2
14+
while Nodes is not empty \\B 2
15+
\\Expl{ Nodes is the data structure used to represent the frontier.
16+
For Dijkstra's algorithm, Nodes is a priority queue, ordered on
17+
Cost (the minumum path length found so far). Here we highlight the Min
18+
value. The priority queue also contains nodes that have not been
19+
seen, which have infinite Cost. The frontier nodes are those
20+
shown with a finite Cost. Nodes with no Cost shown
21+
have been finalised. The frontier and finalised nodes are also
22+
highlighted in the graph display.
23+
\\Expl}
1524
\\In{
1625
remove next node n from Nodes and finalise it \\Ref Next_node
1726
// The Parent of n has now been determined

src/algorithms/pseudocode/prim.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ Prim(G, s) // Given a weighted graph G, return a minimum spanning tree \\B 1
1212
// the root s (which has 0 as the parent).
1313
\\In{
1414
initialise, with fontier={s}, stored in Nodes \\Ref Init
15-
while Nodes not empty \\B 2
15+
while Nodes is not empty \\B 2
16+
\\Expl{ Nodes is the data structure used to represent the frontier.
17+
For Prim's algorithm, Nodes is a priority queue, ordered on
18+
Cost (the minumum edge weight found so far). Here we highlight the Min
19+
value. The priority queue also contains nodes that have not been
20+
seen, which have infinite Cost. The frontier nodes are those
21+
shown with a finite Cost. Nodes with no Cost shown
22+
have been finalised. The frontier and finalised nodes are also
23+
highlighted in the graph display.
24+
\\Expl}
1625
\\In{
1726
remove next node n from Nodes and finalise it \\Ref Next_node
1827
// The Parent of n has now been determined

0 commit comments

Comments
 (0)