Aalto-LeTech / jsav-exercise-recorder

Records students' solutions to JSAV-based visual algorithm simulation exercises
0 stars 1 forks source link

Fringe & spanning tree in all graph algorithm exercises: design #240

Open atilante opened 5 months ago

atilante commented 5 months ago

Generic idea: how bring the concepts of "fringe" and "spanning" tree into all graph algorithm exercises?

atilante commented 5 months ago

BFS

First whiteboard sketch of Breadth-first search with fringe.

breadth-first-search_unvisited-fringe-spanningtree

 1 BFS-VISIT(G, s)
 2     Initialize empty queue Q
 3     for each u ∈ V[G] do
 4         visited[u] ← false
 5         finished[u] ← false
 6     visited[s] ← true
 7     ENQUEUE(Q, s)
 8     while Q not empty do
 9         u ← DEQUEUE(Q)
10         for each v ∈ Adj[u] do
11             if visited[v] = false then
12                 visited[v] ← true
13                 ENQUEUE(Q, v)
14         finished[u] = true
        State of vertex

Line      visited    finished    queue     color
-------------------------------------------
6, 12     F->T
7, 13                            enqueue   unvisited -> fringe
9                                dequeue   fringe -> spanning tree
14                    F->T

Atomic operations in visualization:

Possible points of confusion

DFS

depth-first-search_unvisited-fringe-spanningtree

atilante commented 5 months ago

Archie needed: a comment on Artturi's sketches.

atilante commented 5 months ago

Konsensus: visited BFS:ssä: tummempi vihreä solmulle.