Hacker News new | ask | show | jobs
by nostrademons 362 days ago
Another way I like to think about it is that every graph traversal can be represented as a white set of unknown nodes, a grey set of known but unvisited nodes, and a black set of visited nodes. The data structure used to represent the grey set defines the algorithm:

DFS = queue

BFS = stack

Dijstra's = priority queue keyed by edge weight

A* = priority queue with heuristic function

Beam search = bounded priority queue with heuristic function

Topological sort = priority queue keyed by number of unvisited inbound edges

Copying garbage collector = pointer address

Mark & sweep garbage collector = dirty bit on the object pointed to

Generational garbage collector = multi-level grey set represented by the write barriers between each generation.

2 comments

A* = priority queue with heuristic function _with specific properties_ ... in particular it must be an "admissible" hueristic that never overestimates the true value.
It'll still find a path with an inadmissible heuristic, as the page explains. It's just not guaranteed to be the shortest path in that case. This is commonly done.
This is very insightful and a handy mental model I'll be using thanks. A small nit is that I think you have DFS and BFS swapped?
Oh yeah, I do. Too late to edit the post now.