# Tag Archives: shortest path

## Shortest path to reach one prime to other by changing single digit at a timeNovember 19, 2017

Given two four digit prime numbers, suppose 1033 and 8179, we need to find the shortest path from 1033 to 8179 by altering only single… Read More »

## Comparison of Dijkstra’s and Floyd–Warshall algorithmsOctober 19, 2017

Main Purposes: Dijkstra’s Algorithm is one example of a single-source shortest or SSSP algorithm, i.e., given a source vertex it finds shortest path from source… Read More »

## Shortest distance between two cells in a matrix or gridOctober 13, 2017

Given a matrix of N*M order. Find the shortest distance from a source cell to a destination cell, traversing through limited cells only. Also you… Read More »

## Karp’s minimum mean (or average) weight cycle algorithmMay 17, 2017

Given a directed and strongly connected graph with non negative edge weighs. We define mean weight of a cycle as the summation of all the… Read More »

## 0-1 BFS (Shortest Path in a Binary Weight Graph)April 23, 2017

Given a graph where every edge has weight as either 0 or 1. A source vertex is also given in the graph. Find the shortest… Read More »

## Find minimum weight cycle in an undirected graphFebruary 28, 2017

Given positive weighted undirected graph, find minimum weight cycle in it. Examples: Minimum weighted cycle is : Minimum weighed cycle : 7 + 1 +… Read More »

## Find the minimum number of moves needed to move from one cell of matrix to anotherFebruary 27, 2017

Given a N X N matrix (M) filled with 1 , 0 , 2 , 3 . Find the minimum numbers of moves needed to… Read More »

## Minimum Cost Path with Left, Right, Bottom and Up moves allowedDecember 9, 2016

Given a two dimensional grid, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find… Read More »

## Longest Path in a Directed Acyclic Graph | Set 2August 28, 2016

Given a Weighted Directed Acyclic Graph (DAG) and a source vertex in it, find the longest distances from source vertex to all other vertices in… Read More »

## Find Shortest distance from a guard in a BankAugust 26, 2016

Given a matrix that is filled with ‘O’, ‘G’, and ‘W’ where ‘O’ represents open space, ‘G’ represents guards and ‘W’ represents walls in a… Read More »

## Find shortest safe route in a path with landminesAugust 14, 2016

Given a path in the form of a rectangular matrix having few landmines arbitrarily placed (marked as 0), calculate length of the shortest safe route… Read More »

## Print shortest path to print a string on screenJune 24, 2016

Given a screen containing alphabets from A-Z, we can go from one character to another characters using a remote. The remote contains left, right, top… Read More »

## Shortest path in a Binary MazeMay 16, 2016

Given a MxN matrix where each element can either be 0 or 1. We need to find the shortest path between a given source cell… Read More »

## Dial’s Algorithm (Optimized Dijkstra for small range weights)April 11, 2016

Dijkstra’s shortest path algorithm runs in O(Elog V) time when implemented with adjacency list representation (See C implementation and STL based C++ implementations for details).… Read More »

## Dijkstra’s Shortest Path Algorithm using priority_queue of STLMarch 21, 2016

Given a graph and a source vertex in graph, find shortest paths from source to all vertices in the given graph. Input : Source =… Read More »