Shubham Singh

Shortest path in an unweighted graph

Problem Statement Given the directed, connected and unweighted graph G, a Source and a Destination and the task to find the shortest path possible between two given vertices in the graph. Note: The path does not contain any cycle which means path have finite number of vertices. Example Input Expected Output Path : 0 3 Implementation in …

Shortest path in an unweighted graph Read More »

Snake and Ladder Problem

Problem statement Given a snake and ladder coordinates which represent the actual snake and ladder board, find the minimum number of dice throws required to reach the destination cell from source cell. This problem can be easily solved bu using 0-1 BFS. Example Input Expected Output Implementation in Python

Topological Sorting

In graph theory, a topological sorting of a directed graph is a linear ordering of vertices of graph such that if there is a directed edge uv from vertex u to vertex v, u comes before v in the ordering. Note: Graph must be directed and acyclic. Example Input Expected Output 0 2 1 3 Pseudocode Implementation in Python

Detect Cycle in a Directed Graph

Problem Statement Given the directed, connected and unweighted graph G and the task to check whether the graph contains a cycle or not. Example Input Expected Output No Approach The approach is to use Depth First Traversal to detect a cycle in a Graph. While traversing through the graph if previous node visited node is encountered again …

Detect Cycle in a Directed Graph Read More »

Depth First Traversal for a Graph

Depth First Search (BFS) is a recursive graph traversal algorithm that is used to traverse all the vertices of a graph in a depthward motion. In other words, it starts the graph traversal from root node and explores all the branches. Example of Depth First Traversal for a Graph Depth First Traversal is used to traverse all the vertices of …

Depth First Traversal for a Graph Read More »

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]