1

Depth-first search uses LIFO/Stack. Breadth-first search uses FIFO/Queue. What does a recursive algorithm use? A combination of both?

1 Answers1

2

a recursive algorithm always use Depth-first Search (DFS)


Pseudocode

Input: A graph G and a vertex v of G

Output: All vertices reachable from v labeled as discovered

A recursive implementation of DFS:

1  procedure DFS(G,v):
2      label v as discovered
3      for all edges from v to w in G.adjacentEdges(v) do
4          if vertex w is not labeled as discovered then
5              recursively call DFS(G,w)

Wiki source here

Ziggy192
  • 75
  • 6