Skip to content

Commit 2f6038c

Browse files
committed
Exercises, mostly
1 parent 32cb2d9 commit 2f6038c

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

src/algorithms/controllers/msort_arr_bup.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function run_msort() {
121121
}, [A, B, runlength]);
122122

123123
chunker.add('runlength', (vis, c_rlength) => {
124-
assignVarToA(vis, "runlength", c_rlength - 1, size);
124+
// assignVarToA(vis, "runlength", c_rlength - 1, size);
125125
set_simple_stack(vis.array, [`runlength = ${c_rlength}`]);
126126
highlightAllRunlengths(vis, c_rlength, runAColor, runBColor, size);
127127
}, [runlength]);
@@ -131,7 +131,7 @@ export function run_msort() {
131131
let left = 0;
132132

133133
chunker.add('MainWhile', (vis) => {
134-
assignVarToA(vis, "size", size, size);
134+
// assignVarToA(vis, "size", size, size);
135135
}, []);
136136

137137
chunker.add('left', (vis, a, c_left, c_rlength) => {
@@ -357,9 +357,9 @@ export function run_msort() {
357357
assignVarToA(vis, 'left', undefined, size);
358358
set_simple_stack(vis.array, [`runlength = ${c_rlength}`]);
359359

360-
if (c_rlength < size) {
361-
assignVarToA(vis, "runlength", c_rlength - 1, size);
362-
}
360+
// if (c_rlength < size) {
361+
// assignVarToA(vis, "runlength", c_rlength - 1, size);
362+
// }
363363

364364

365365
}, [runlength]);

src/algorithms/extra-info/ASTInfo.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Geeks for Geeks Link: [**Astar Algorithm**][G4GLink]
2121

2222
## Exercises/Exploration
2323

24+
Compare heuristic search with Dijkstra's algorithm: can you observe how
25+
the heuristic helps direct the search towards the end node?
26+
2427
For Graph 1 (or any other graph) what is the longest path (choice of
2528
start and end nodes) for which the algorithm makes no "mistakes", that
2629
is, every node removed from the priority queue is on the shortest path?
@@ -44,3 +47,10 @@ shape of a right-angled triangle with edge lengths 10, 10 and 10 root 2
4447
(around 14.142137) with nodes at the corners and several nodes along
4548
the hypotenuse.
4649

50+
In AIA, the coding of various graph algorithms is designed to show
51+
their similarity. Iterative DFS, breadth first search, Dijkstra's
52+
shortest path algorithm, heuristic search and Prim's minimal spanning
53+
tree algorithm all have *identical* top-level pseudocode - check it out!
54+
Can you re-write the code for this and/or for other algorithms to make
55+
it as simple as possible, rather than emphasising similarity?
56+

src/algorithms/extra-info/BFSInfo.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@ a:hover{
1717
Geeks for Geeks Link: [**Breadth First Search**][G4GLink]
1818

1919

20-
[G4GLink]: https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/
20+
[G4GLink]: https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/
21+
22+
## Exercises/Exploration
23+
24+
Compare and contrast the use of the queue of nodes in BFS with the stack
25+
in iterative DFS.
26+
27+
In AIA, the coding of various graph algorithms is designed to show
28+
their similarity. Iterative DFS, breadth first search, Dijkstra's
29+
shortest path algorithm, heuristic search and Prim's minimal spanning
30+
tree algorithm all have *identical* top-level pseudocode - check it out!
31+
Can you re-write the code for this and/or for other algorithms to make
32+
it as simple as possible, rather than emphasising similarity?
33+

src/algorithms/extra-info/DFSInfo.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ Geeks for Geeks Link: [**Iterative Depth First Search**][G4GLink]
2020

2121
## Exercises/Exploration
2222

23-
In AIA, the coding of various graph algorithms is designed to show
24-
their similarity. Iterative DFS, breadth first search, Dijkstra's
25-
shortest path algorithm, heuristic search and Prim's minimal spanning
26-
tree algorithm all have *identical* top-level pseudocode - check it out!
27-
Can you re-write the code for this and/or for other algorithms to make
28-
it as simple as possible, rather than emphasising similarity?
29-
30-
For Graph2 can you find a combination of start and end nodes so the path
23+
For Graph 2 can you find a combination of start and end nodes so the path
3124
found includes all nodes in the graph?
3225

3326
Experiment with the iterative and recursive versions of DFS. Can you
@@ -52,4 +45,10 @@ How can you code iterative DFS so it uses less stack space in the worst
5245
case? Hint: consider what information is on the (implicit) stack for
5346
recursive DFS and how that is coded.
5447

48+
In AIA, the coding of various graph algorithms is designed to show
49+
their similarity. Iterative DFS, breadth first search, Dijkstra's
50+
shortest path algorithm, heuristic search and Prim's minimal spanning
51+
tree algorithm all have *identical* top-level pseudocode - check it out!
52+
Can you re-write the code for this and/or for other algorithms to make
53+
it as simple as possible, rather than emphasising similarity?
5554

src/algorithms/extra-info/DFSrecInfo.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,16 @@ Geeks for Geeks Link: [**Depth First Search**][G4GLink]
1818

1919
## Exercises/Exploration
2020

21-
For Graph2 can you find a combination of start and end nodes so the path
21+
For Graph 2 can you find a combination of start and end nodes so the path
2222
found includes all nodes in the graph?
2323

24-
Both the iterative and recursive codings of DFS have the line "for each
25-
node m neighbouring n". For iterative DFS, the neighbours are considered
26-
in increasing node number order whereas for recursive DFS the order is
27-
reversed. Why is this done?
28-
29-
The "frontier" nodes for iterative DFS are fairly easy to determine
30-
from the data structures - they are the nodes in the stack that have not
31-
yet been finalised. How does this compare with the animation of the
32-
recursive version?
33-
3424
The (implicit) stack shown only includes values for **n** and **p**.
3525
In an actual implemenetation the other argument, **G**, would also
3626
generally be on the stack. What additional value(s) would also be on
3727
the stack?
3828

3929
Given a graph with **N** nodes, what is the maximum height of the stack?
4030

31+
Compare and contrast this DFS coding with the AIA iterative version of
32+
DFS (which has more exercises/exploration).
33+

src/algorithms/extra-info/DIJKInfo.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,19 @@ a:hover{
1818
Geeks for Geeks Link: [**Dijkstra's Algorithm**][G4GLink]
1919

2020

21-
[G4GLink]: https://www.geeksforgeeks.org/introduction-to-dijkstras-shortest-path-algorithm/
21+
[G4GLink]: https://www.geeksforgeeks.org/introduction-to-dijkstras-shortest-path-algorithm/
22+
23+
## Exercises/Exploration
24+
25+
Compare and contrast Dijkstra's algorithm with BFS in the case that all
26+
edges are the same length (edit the "SET EDGES/WEIGHTS" box to change
27+
weights and ensure "Weights" is set to "As input"; run BFS with the
28+
same graph).
29+
30+
In AIA, the coding of various graph algorithms is designed to show
31+
their similarity. Iterative DFS, breadth first search, Dijkstra's
32+
shortest path algorithm, heuristic search and Prim's minimal spanning
33+
tree algorithm all have *identical* top-level pseudocode - check it out!
34+
Can you re-write the code for this and/or for other algorithms to make
35+
it as simple as possible, rather than emphasising similarity?
36+

src/algorithms/extra-info/PRIMInfo.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ forest for the whole graph. One coding sometimes used is to add an outer
3434
loop that calls Prims() for each node in the graph, ignoring nodes that
3535
have already been visited. Can you think of a different way of coding it?
3636

37+
In AIA, the coding of various graph algorithms is designed to show
38+
their similarity. Iterative DFS, breadth first search, Dijkstra's
39+
shortest path algorithm, heuristic search and Prim's minimal spanning
40+
tree algorithm all have *identical* top-level pseudocode - check it out!
41+
Can you re-write the code for this and/or for other algorithms to make
42+
it as simple as possible, rather than emphasising similarity?
43+
3744
Compare and contrast how Prim's algorithm and Kruskal's algorithm operate
3845
to compute minimum spanning trees.
3946

0 commit comments

Comments
 (0)