@@ -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+
2330For Graph2 can you find a combination of start and end nodes so the path
2431found 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+
2638Both the iterative and recursive codings of DFS have the line "for each
2739node m neighbouring n". For iterative DFS, the neighbours are considered
2840in increasing node number order whereas for recursive DFS the order is
2941reversed. Why is this done?
3042
3143The "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
3345yet been finalised. How does this compare with the animation of the
3446recursive 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+
0 commit comments