Skip to content

Commit 32cb2d9

Browse files
committed
graph input bug, DFS exercises
1 parent 683a047 commit 32cb2d9

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/algorithms/extra-info/DFSInfo.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,36 @@ 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+
2330
For Graph2 can you find a combination of start and end nodes so the path
2431
found includes all nodes in the graph?
2532

33+
Experiment with the iterative and recursive versions of DFS. Can you
34+
convince yourself that, given the same graph input, they both always
35+
produce the same parent array output, and the parent array elements have
36+
their final values assigned in the same order?
37+
2638
Both the iterative and recursive codings of DFS have the line "for each
2739
node m neighbouring n". For iterative DFS, the neighbours are considered
2840
in increasing node number order whereas for recursive DFS the order is
2941
reversed. Why is this done?
3042

3143
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
44+
from the data structures - they are the nodes in the stack that have not
3345
yet been finalised. How does this compare with the animation of the
3446
recursive version?
3547

48+
Given a graph with **N** nodes, what is the maximum size of the stack?
49+
Hint: look at the animation for graphs that have lots of edges.
50+
51+
How can you code iterative DFS so it uses less stack space in the worst
52+
case? Hint: consider what information is on the (implicit) stack for
53+
recursive DFS and how that is coded.
54+
55+

src/algorithms/extra-info/DFSrecInfo.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ in increasing node number order whereas for recursive DFS the order is
2727
reversed. Why is this done?
2828

2929
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
30+
from the data structures - they are the nodes in the stack that have not
3131
yet been finalised. How does this compare with the animation of the
3232
recursive version?
3333

34+
The (implicit) stack shown only includes values for **n** and **p**.
35+
In an actual implemenetation the other argument, **G**, would also
36+
generally be on the stack. What additional value(s) would also be on
37+
the stack?
38+
39+
Given a graph with **N** nodes, what is the maximum height of the stack?
40+

src/algorithms/parameters/helpers/EuclideanMatrixParams.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* eslint-disable react/prop-types */
66

77
// Support for graphs with Euclidean (X-Y) coordinates defined for each
8-
// node. In flux currently. Student version used tables only for input of
8+
// node. Older student version used tables only for input of
99
// graphs - lots of screen real-estate. Also a bunch of other problems
1010
// and annoyances/limitations. Now supports input of X-Y cordinates
1111
// and edges/weights via text boxes, plus having predefined example
@@ -238,8 +238,8 @@ function EuclideanMatrixParams({
238238
const [heurCalc, setHeurCalc] = useState(H_EUCLIDEAN);
239239

240240
// (currSize) affects number of columns.
241-
const columns1 = useMemo(() => makeColumnCoords(currSize), [currSize]);
242-
const columns2 = useMemo(() => makeColumnArray(currSize), [currSize]);
241+
const columns1 = useMemo(() => makeColumnCoords(size), [size]);
242+
const columns2 = useMemo(() => makeColumnArray(size), [size]);
243243
// window.alert(columns.Header);
244244
const { dispatch } = useParam();
245245

src/algorithms/parameters/helpers/Table.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ function Table({
3333
algo,
3434
});
3535

36-
3736
// add the header in left side of table
3837
let counter = 0;
3938
const incrementCounter = () => { counter += 1; };

0 commit comments

Comments
 (0)