# Tag Archives: Algorithms-Graph Traversals

## Paranthesis Theorem

Parenthesis Theorem is used in DFS of graph. It states that the descendants in a depth-first-search tree have an interesting property. If v is a… Read More »

## Count of unique lengths of connected components for an undirected graph using STL

Given an undirected graph, the task is to find the size of each connected component and print the number of unique sizes of connected components… Read More »

## Count total ways to reach destination from source in an undirected Graph

Given an undirected graph, a source vertex ‘s’ and a destination vertex ‘d’, the task is to count total paths from given ‘s’ to ‘d’.… Read More »

## Check if a directed graph is connected or not

Given a directed graph. The task is to check if the given graph is connected or not. Examples: Input: Output: Yes Input: Output: No Recommended:… Read More »

## Print the lexicographically smallest DFS of the graph starting from 1

Given a connected graph with N vertices and M edges. The task is to print the lexicographically smallest DFS traversal of the graph starting from… Read More »

## Print the lexicographically smallest BFS of the graph starting from 1

Given a connected graph with N vertices and M edges. The task is to print the lexicographically smallest BFS traversal of the graph starting from… Read More »

## Minimum number of edges between two vertices of a graph using DFS

Given an undirected graph G(V, E) with N vertices and M edges. We need to find the minimum number of edges between a given pair… Read More »

## Edge Coloring of a Graph

In graph theory, edge coloring of a graph is an assignment of “colors” to the edges of the graph so that no two adjacent edges… Read More »

## Largest connected component on a grid

Given a grid with different colors in a different cell, each color represented by a different number. The task is to find out the largest… Read More »

## Disjoint Set Union on trees | Set 2

Given a tree, and the cost of a subtree is defined as |S|*AND(S) where |S| is the size of the subtree and AND(S) is bitwise… Read More »

## Paths to travel each nodes using each edge (Seven Bridges of Königsberg)

There are n nodes and m bridges in between these nodes. Print the possible path through each node using each edges (if possible), traveling through… Read More »

## Algorithms | Graph Traversals | Question 12

If the DFS finishing time f[u] > f[v] for two vertices u and v in a directed graph G, and u and v are in… Read More »

## Algorithms | Graph Traversals | Question 12

Is following statement true/false? A DFS of a directed graph always produces the same number of tree edges, i.e., independent of the order in which… Read More »

## Algorithms | Graph Traversals | Question 12

Is following statement true/false If a DFS of a directed graph contains a back edge, any other DFS of the same graph will also contain… Read More »

## Algorithms | Graph Traversals | Question 9

Which of the following condition is sufficient to detect cycle in a directed graph? (A) There is an edge from currently being visited node to… Read More »