File tree Expand file tree Collapse file tree 7 files changed +49
-32
lines changed
src/algorithms/pseudocode Expand file tree Collapse file tree 7 files changed +49
-32
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,17 @@ import parse from '../../pseudocode/parse';
3
3
export default parse ( `
4
4
\\Code{
5
5
Main
6
- Astar(G, s, e) // Given a graph G find a shortest path from start node s \\B 1
7
- // to the end node e. Nodes are numbered 1..nmax. Returns the
8
- // Parent array, which gives the previous node in the path from s
9
- // to the node i (if one has been found; Parent[i] = 0 otherwise).
10
- // A heuristic function is used to guide the search (here it is based
11
- // on a measure of the distance from each node to e).
6
+ Astar(G, s, e) // Heuristic search for node e from node s in graph G \\B 1
7
+ \\Expl{ Given a graph G, find a path from start node s
8
+ to the end node e. Nodes are numbered 1..nmax. Returns the
9
+ Parent array, which gives the previous node in the path from s
10
+ to the node i (if one has been found; Parent[i] = 0 otherwise).
11
+ A heuristic function is used to guide the search (here it is
12
+ a measure of the distance from each node to e, based on
13
+ the Euclidiean coordinates of each node). If the
14
+ heuristic is "admissible", the shortest path will be found.
15
+ \\Expl}
16
+
12
17
\\In{
13
18
initialise, with fontier={s}, stored in Nodes \\Ref Init
14
19
while Nodes is not empty \\B 2
Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import parse from '../../pseudocode/parse';
3
3
export default parse ( `
4
4
\\Code{
5
5
Main
6
- BFS(G, s) // Given a graph G find a path from start node s to an \\B 1
7
- // end node. It is assumed the end node(s) are defined
8
- // separately; if there are no end nodes, paths to all connected
9
- // nodes are found. Nodes are numbered 1..nmax. Returns the Parent
10
- // array, which gives the previous node in the path from s to the
11
- // node i (if one has been found; Parent[i] = 0 otherwise).
6
+ BFS(G, s) // Breadth first search of graph G from start node s \\B 1
7
+ \\Expl{ Given a graph G, find a path from the start node s to an
8
+ end node. It is assumed the end node(s) are defined
9
+ separately; if there are no end nodes, paths to all connected
10
+ nodes are found. Nodes are numbered 1..nmax. Returns the Parent
11
+ array, which gives the previous node in the path from s to the
12
+ node i (if one has been found; Parent[i] = 0 otherwise).
13
+ \\Expl}
12
14
\\In{
13
15
initialise, with fontier={s}, stored in Nodes \\Ref Init
14
16
while Nodes is not empty \\B 2
Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import parse from '../../pseudocode/parse';
3
3
export default parse ( `
4
4
\\Code{
5
5
Main
6
- DFS(G, s) // Given a graph G find a path from start node s to an \\B 1
7
- // end node. It is assumed the end node(s) are defined
8
- // separately; if there are no end nodes, paths to all connected
9
- // nodes are found. Nodes are numbered 1..nmax. Returns the Parent
10
- // array, which gives the previous node in the path from s to the
11
- // node i (if one has been found; Parent[i] = 0 otherwise).
6
+ DFS(G, s) // Depth first search of graph G from start node s \\B 1
7
+ \\Expl{ Given a graph G, find a path from the start node s to an
8
+ end node. It is assumed the end node(s) are defined
9
+ separately; if there are no end nodes, paths to all connected
10
+ nodes are found. Nodes are numbered 1..nmax. Returns the Parent
11
+ array, which gives the previous node in the path from s to the
12
+ node i (if one has been found; Parent[i] = 0 otherwise).
13
+ \\Expl}
12
14
\\In{
13
15
initialise, with fontier={s}, stored in Nodes \\Ref Init
14
16
while Nodes is not empty \\B 2
Original file line number Diff line number Diff line change @@ -26,9 +26,15 @@ made explicit
26
26
27
27
\\Code{
28
28
Main
29
- DFS(G, n) // Given a graph G find a path from start node n to a \\B start
30
- // separately defined end node; if there are no end nodes, paths
31
- // to all connected nodes are found.
29
+ DFS(G, n) // Depth first search of graph G from start node n \\B start
30
+ \\Expl{ Given a graph G, find a path from the start node n to an
31
+ end node. It is assumed the end node(s) are defined
32
+ separately; if there are no end nodes, paths to all connected
33
+ nodes are found. Nodes are numbered 1..nmax. Returns the Parent
34
+ array, which gives the previous node in the path from s to the
35
+ node i (if one has been found; Parent[i] = 0 otherwise).
36
+ \\Expl}
37
+
32
38
\\In{
33
39
initialise all parents to null \\B init
34
40
\\Expl{ We initialise to some special value so we can later check if a
Original file line number Diff line number Diff line change @@ -87,8 +87,7 @@ to the page of the file-system.
87
87
88
88
\\Code{
89
89
Main
90
- T234_Insert(t, k) // return either a node containing key k or \\B T234_Insert(t, k)
91
- // NotFound, if no such node is present
90
+ T234_Insert(t, k) // Insert key k into 234 tree t \\B T234_Insert(t, k)
92
91
\\In{
93
92
if t = Empty \\B if t = Empty
94
93
\\In{
@@ -546,4 +545,4 @@ to the page of the file-system.
546
545
\\In}
547
546
548
547
\\Note}
549
- ` ) ;
548
+ ` ) ;
Original file line number Diff line number Diff line change @@ -3,12 +3,15 @@ import parse from '../../pseudocode/parse';
3
3
export default parse ( `
4
4
\\Code{
5
5
Main
6
- Shortest(G, s) //Given a graph G find a shortest path from start node s \\B 1
7
- // to an end node. It is assumed the end node(s) are defined
8
- // separately; with no end nodes, shortest paths to all connected
9
- // nodes are found. Nodes are numbered 1..nmax. Returns the Parent
10
- // array, which gives the previous node in the path from s to the
11
- // node i (if one has been found; Parent[i] = 0 otherwise).
6
+ Shortest(G, s) // Find shortest path(s) from start node s in graph G \\B 1
7
+ \\Expl{ Given a graph G, find a shortest path from start node s
8
+ to an end node. It is assumed the end node(s) are defined
9
+ separately; with no end nodes, shortest paths to all connected
10
+ nodes are found. Nodes are numbered 1..nmax. Returns the Parent
11
+ array, which gives the previous node in the path from s to the
12
+ node i (if one has been found; Parent[i] = 0 otherwise).
13
+ \\Expl}
14
+
12
15
\\In{
13
16
initialise, with fontier={s}, stored in Nodes \\Ref Init
14
17
while Nodes is not empty \\B 2
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ import parse from '../../pseudocode/parse';
3
3
export default parse ( `
4
4
\\Code{
5
5
Main
6
- Warshall(A, n) \\B 1
7
- \\Expl{ Compute the transitive closure of a directed graph G
6
+ Warshall(A, n) // Compute the transitive closure of a graph \\B 1
7
+ \\Expl{ Compute the transitive closure of a directed graph
8
8
with nodes 1..n, represented by n x n adjacency matrix A
9
9
\\Expl}
10
10
\\In{
You can’t perform that action at this time.
0 commit comments