Skip to content

Commit

Permalink
Graph alg explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-naish committed May 9, 2024
1 parent 11f7f69 commit 6c47786
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/algorithms/pseudocode/AStar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ export default parse(`
// on a measure of the distance from each node to e).
\\In{
initialise, with fontier={s}, stored in Nodes \\Ref Init
while Nodes not empty \\B 2
\\Expl{Nodes is the data structure where we store the nodes that are
in the frontier. In the A* algorithm, Nodes is a Priority Queue.
while Nodes is not empty \\B 2
\\Expl{ Nodes is the data structure used to represent the frontier.
For A*, Nodes is a priority queue, ordered on Length (the minumum
found so far) plus the heuristic value. Here we highlight the Min
value. The priority queue also contains nodes that have not been
seen, which have infinite Length. The frontier nodes are those
shown with a finite Length so far. Nodes with no Length shown
have been finalised. The frontier and finalised nodes are also
highlighted in the graph display.
\\Expl}
\\In{
remove next node n from Nodes and finalise it \\Ref Next_node
Expand Down
9 changes: 8 additions & 1 deletion src/algorithms/pseudocode/BFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export default parse(`
// node i (if one has been found; Parent[i] = 0 otherwise).
\\In{
initialise, with fontier={s}, stored in Nodes \\Ref Init
while Nodes not empty \\B 2
while Nodes is not empty \\B 2
\\Expl{ Nodes is the data structure used to represent the frontier.
For BFS, Nodes is a queue, shown below the arrays. The frontier
nodes are simply those in the queue (they are also marked as
Seen). The Seen nodes that are no longer in the queue are
finalised. The frontier and finalised nodes are also highlighted
in the graph display.
\\Expl}
\\In{
remove next node n from Nodes and finalise it \\Ref Next_node
// The Parent of n has now been determined
Expand Down
10 changes: 9 additions & 1 deletion src/algorithms/pseudocode/DFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export default parse(`
// node i (if one has been found; Parent[i] = 0 otherwise).
\\In{
initialise, with fontier={s}, stored in Nodes \\Ref Init
while Nodes not empty \\B 2
while Nodes is not empty \\B 2
\\Expl{ Nodes is the data structure used to represent the frontier.
For DFS, Nodes is a stack, shown below the arrays.
The stack can have repeated elements and when we pop a node off
the stack it is ignored if it has already been finalised.
The frontier nodes are those in the stack that are not finalised.
The frontier and finalised nodes are also highlighted in the
graph display.
\\Expl}
\\In{
remove next node n from Nodes and finalise it \\Ref Next_node
// The Parent of n has now been determined
Expand Down
11 changes: 10 additions & 1 deletion src/algorithms/pseudocode/dijkstra.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ Shortest(G, s) //Given a graph G find a shortest path from start node s \\B 1
// node i (if one has been found; Parent[i] = 0 otherwise).
\\In{
initialise, with fontier={s}, stored in Nodes \\Ref Init
while Nodes not empty \\B 2
while Nodes is not empty \\B 2
\\Expl{ Nodes is the data structure used to represent the frontier.
For Dijkstra's algorithm, Nodes is a priority queue, ordered on
Cost (the minumum path length found so far). Here we highlight the Min
value. The priority queue also contains nodes that have not been
seen, which have infinite Cost. The frontier nodes are those
shown with a finite Cost. Nodes with no Cost shown
have been finalised. The frontier and finalised nodes are also
highlighted in the graph display.
\\Expl}
\\In{
remove next node n from Nodes and finalise it \\Ref Next_node
// The Parent of n has now been determined
Expand Down
11 changes: 10 additions & 1 deletion src/algorithms/pseudocode/prim.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ Prim(G, s) // Given a weighted graph G, return a minimum spanning tree \\B 1
// the root s (which has 0 as the parent).
\\In{
initialise, with fontier={s}, stored in Nodes \\Ref Init
while Nodes not empty \\B 2
while Nodes is not empty \\B 2
\\Expl{ Nodes is the data structure used to represent the frontier.
For Prim's algorithm, Nodes is a priority queue, ordered on
Cost (the minumum edge weight found so far). Here we highlight the Min
value. The priority queue also contains nodes that have not been
seen, which have infinite Cost. The frontier nodes are those
shown with a finite Cost. Nodes with no Cost shown
have been finalised. The frontier and finalised nodes are also
highlighted in the graph display.
\\Expl}
\\In{
remove next node n from Nodes and finalise it \\Ref Next_node
// The Parent of n has now been determined
Expand Down

0 comments on commit 6c47786

Please sign in to comment.