4 ms·
It depends on exactly what you're trying to optimize and what the requirements are. While it's not necessarily the best solution for a Facebook style problem (w
by k4st 16y ago
It depends on exactly what you're trying to optimize and what the requirements are. While it's not necessarily the best solution for a Facebook style problem (where you actually want to aggregate the results, where other concerns would be pagination of said results, permissions, etc.), an interesting algorithm to look at when you want to traverse a graph up to a certain depth looking for some specific "target" is iterative deepening. In basic terms, it is a depth-first search up to depth N inside a loop that increments N on each iteration.