DFS (Graph/Tree)

Poornima K S
Jan 31, 2022

--

Depth first Search or DFS is a way to search recursively into the child nodes of a tree or graph rather than traversing across the breadth or siblings

Complexity: O(number of nodes in the graph) or O(V+E)

Non recursive Method:

Using a stack

Recursive Method:

Points to Note:

  • DFS vs Backtracking : In a DFS , we flag/do not visit the vertices we have already visited whereas in backtracking we do not flag the vertices we have already visited that leads to exponential complexity

Applications:

  • Finding loops /Cycles in a graph

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Poornima K S
Poornima K S

No responses yet

Write a response