Playing with Depth First Search

Pynode - Some Backstory

Pynode is this little python graph library, (in the nodes and vertices sense), which was made to be used in the VCE Algorithmic's Subject , a collaboration between Unimelb and Monash to create a high school subject which covered first-year Uni CS content. Now, it is actually a nice library, however it can be a tad slow. And hasn't had a solid update in three years (barring a merge allowing importing code through GitHub Gists on the website.)

Now, as is slowly becoming tradition at my school, someone remade pynode as a wrapper around another graph library made by the original pynode creator. Now this new library is available in both in python and javascript, so I thought:

"Oh, I might be able to use this to make nice little graph animations."

Unfortunately, this newer library, algorithmX, allows you to draw nodes and edges, but the underlying graph has to be modelled yourself if you wish to work with it. For example, you can't actually get information about adjacent nodes and edges from the canvas object, you have to keep track yourself.

This is fine, but when writing my graph scripts, it became somewhat frustrating having to remember to both keep track of the graph model and what I was drawing to the canvas. So naturally, I went down the rabbit hole of remaking pynode myself.

(and by remaking, I mean making a TypeScript wrapper around algorithmX, instead of python)

And now that I have this nice little graph library, I'd thought I'd make some nice little graphs.

Depth First Search

DFS, I think, feels like the dead brain approach. Not that I don't like DFS. Anything with recursion is fun, but

"Just keep going until we reach a dead end, then go back and go the other way", always seems to me unreasonably and ammusingly effective.

void dfs(int & graph[][], bool & visited[], int current) { 
    visited[current] = true; 

    for (int nextNode : graph[current]) {
  	    if (!visited[nextNode]) dfs(graph, visited, nextNode);
    }
}