Skip to content

Commit d8c2cc8

Browse files
committed
Extra info for graph traversal algorithms
1 parent 8ca8f05 commit d8c2cc8

File tree

7 files changed

+100
-14
lines changed

7 files changed

+100
-14
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,3 @@
9696
"run-script-os": "^1.1.6"
9797
}
9898
}
99-

src/algorithms/extra-info/ASTInfo.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,34 @@ a:hover{
1313

1414
## Extra Info
1515

16-
-----
1716

1817
Geeks for Geeks Link: [**Astar Algorithm**][G4GLink]
1918

19+
[G4GLink]: https://www.geeksforgeeks.org/a-search-algorithm/
20+
21+
22+
## Exercises/Exploration
23+
24+
For Graph 1 (or any other graph) what is the longest path (choice of
25+
start and end nodes) for which the algorithm makes no "mistakes", that
26+
is, every node removed from the priority queue is on the shortest path?
27+
What are the characteristics of such paths?
28+
29+
The background says if Euclidean distance is used for weights and
30+
Manhattan distance is used for the heuristic, it is not admissible
31+
(so the shortest path may not be the one returned) whereas for other
32+
combinations of Manhattan/Euclidean the heuristic is admissible (so the
33+
shortest will be returned). Use the default settings (Graph1, start node
34+
5, end node 12) to explore this. Can you come up with other examples
35+
to illustrate this?
36+
37+
AIA uses integer approximations to Euclidean distances for convenience.
38+
There was a choice of rounding to the closest integer, rounding up
39+
(ceiling) or rounding down (floor). By picking different node positions,
40+
try to determine which of these alternatives is used. Why was that
41+
alternative used? Can you think of an example that would not work so
42+
well if a different alternative was used. Hint: consider a graph in the
43+
shape of a right-angled triangle with edge lengths 10, 10 and 10 root 2
44+
(around 14.142137) with nodes at the corners and several nodes along
45+
the hypotenuse.
2046

21-
[G4GLink]: https://www.geeksforgeeks.org/a-search-algorithm/

src/algorithms/extra-info/DFSInfo.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ a:hover{
1212

1313
## Extra Info
1414

15-
-----
1615

1716
Geeks for Geeks Link: [**Iterative Depth First Search**][G4GLink]
1817

1918

2019
[G4GLink]: https://www.geeksforgeeks.org/iterative-depth-first-traversal/
20+
21+
## Exercises/Exploration
22+
23+
For Graph2 can you find a combination of start and end nodes so the path
24+
found includes all nodes in the graph?
25+
26+
Both the iterative and recursive codings of DFS have the line "for each
27+
node m neighbouring n". For iterative DFS, the neighbours are considered
28+
in increasing node number order whereas for recursive DFS the order is
29+
reversed. Why is this done?
30+
31+
The "frontier" nodes for iterative DFS are fairly easy to determine
32+
from the animation - they are the nodes in the stack that have not
33+
yet been finalised. How does this compare with the animation of the
34+
recursive version?
35+

src/algorithms/extra-info/DFSrecInfo.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ a:hover{
1212

1313
## Extra Info
1414

15-
-----
16-
1715
Geeks for Geeks Link: [**Depth First Search**][G4GLink]
1816

19-
2017
[G4GLink]: https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/
18+
19+
## Exercises/Exploration
20+
21+
For Graph2 can you find a combination of start and end nodes so the path
22+
found includes all nodes in the graph?
23+
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 animation - 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+

src/algorithms/extra-info/KRUSKALInfo.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,21 @@ Geeks for Geeks Link: [**Kruskal's Algorithm**][G4GLink]
2020

2121
[G4GLink]: https://www.geeksforgeeks.org/kruskals-algorithm-simple-implementation-for-adjacency-matrix/
2222

23+
## Exercises/Exploration
24+
25+
Choose Graph 2 and manually delete the edge between nodes 11 and 13,
26+
so the graph has two components. Find minimum spanning forest of the
27+
resulting graph.
28+
29+
Compare and contrast how Prim's algorithm and Kruskal's algorithm operate
30+
to compute minimum spanning trees.
31+
32+
Consider Graph 1 with weights "As input". There are two different minimal
33+
spanning trees and the current coding finds one of them. How could the
34+
coding be changed so the other second one is found instead? Can you
35+
use the existing code to find the second one by re-numbering the graph nodes?
36+
37+
For Graph1 with the other weight options, can you convince yourself that
38+
there is a single minimum spanning tree?
39+
2340

src/algorithms/extra-info/PRIMInfo.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,27 @@ a:hover{
1313

1414
## Extra Info
1515

16-
-----
17-
1816
Geeks for Geeks Link: [**Prim's Algorithm**][G4GLink]
1917

20-
2118
[G4GLink]: https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-algo-5/
2219

20+
## Exercises/Exploration
21+
22+
Consider Graph 1 with weights "As input". Can you find two different
23+
minimal spanning trees using Prim's algorithm, by selecting different
24+
start nodes?
25+
26+
For Graph1 with the other weight options, can you convince yourself that
27+
there is a single minimum spanning tree without running the algorithm
28+
multiple times with different start nodes?
29+
30+
Choose Graph 2 and manually delete the edge between nodes 11 and 13,
31+
so the graph has two components. Find minimum spanning trees for each
32+
component. Prim's algorithm can be adapted to find a minimal spanning
33+
forest for the whole graph. One coding sometimes used is to add an outer
34+
loop that calls Prims() for each node in the graph, ignoring nodes that
35+
have already been visited. Can you think of a different way of coding it?
36+
37+
Compare and contrast how Prim's algorithm and Kruskal's algorithm operate
38+
to compute minimum spanning trees.
2339

0 commit comments

Comments
 (0)