Menu

Depth-first search engines without the canonical color array

Reddit r/computerscience·u/Liam_Mercier·6 months ago
#SL3t9hFn
#colors#discovered#finished#numeric#_max
Reading 0:00
15s threshold

Background information

The standard implementation of DFS you will often see in an algorithms textbook or implementation involves arrays for the color (really just a processing state), the discovery time, and the finish time of each node.

Here is a simple source traversal (not global) DFS example in pseudocode for a graph G and source v. Assume colors , discovered , and finished are already allocated for the |V| vertices, colors has every element initialized to white, and timer is zero initialized.

DFS(G, v) discovered[v] = timer++

// Mark this node as "currently in traversal" colors[v] = grey

for u in G.Adjacency[v] // If the node state is "unseen" then // this is a tree edge if colors[u] == white DFS(G, u)

// Once we have gone over every vertex, set // the node state to "processed" and record // the finish time.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.