# Tag Archives: DFS

## Iterative Depth First Traversal of GraphOctober 23, 2015

Depth First Traversal (or Search) for a graph is similar to Depth First Traversal (DFS) of a tree. The only catch here is, unlike trees,… Read More »

## Print all Jumping Numbers smaller than or equal to a given valueOctober 16, 2015

A number is called as a Jumping Number if all adjacent digits in it differ by 1. The difference between ‘9’ and ‘0’ is not… Read More »

## Find same contacts in a list of contactsAugust 24, 2015

Given a list of contacts containing username, email and phone number in any order. Identify the same contacts (i.e., same person having many different contacts)… Read More »

## Connected Components in an undirected graphJune 12, 2015

Given an undirected graph, print all connected components line by line. For example consider the following graph.

## Recursively print all sentences that can be formed from list of word listsApril 12, 2015

Given a list of word lists How to print all sentences possible taking one word from a list at a time via recursion?

## Print all paths from a given source to a destinationJanuary 15, 2015

Given a directed graph, a source vertex ‘s’ and a destination vertex ‘d’, print all paths from given ‘s’ to ‘d’.

## Boggle (Find all possible words in a board of characters) | Set 1January 2, 2015

Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible… Read More »

## Check if a given graph is tree or notOctober 20, 2014

Write a function that returns true if a given undirected graph is tree and false otherwise. For example, the following graph is a tree.

## Detect cycle in an undirected graphOctober 11, 2013

Given an undirected graph, how to check if there is a cycle in the graph? For example, the following graph has a cycle 1-0-2-1.

## Check if a graph is strongly connected | Set 1 (Kosaraju using DFS)June 2, 2013

Given a directed graph, find out whether the graph is strongly connected or not. A directed graph is strongly connected if

## Articulation Points (or Cut Vertices) in a GraphMay 21, 2013

A vertex in an undirected connected graph is an articulation point (or cut vertex) iff removing it (and edges through it) disconnects the graph.

## Strongly Connected ComponentsMay 16, 2013

A directed graph is strongly connected if there is a path between all pairs of vertices.

## Topological SortingMay 12, 2013

Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v… Read More »

## Find the number of islands | Set 1 (Using DFS)October 17, 2012

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5… Read More »

## Detect Cycle in a Directed GraphApril 3, 2012

Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least… Read More »