# Category Archives: Graph

## 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 »

## Traveling Salesman Problem (TSP) ImplementationNovember 11, 2017

Travelling Salesman Problem (TSP): Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route… Read More »

## Degree Centrality (Centrality Measure)November 10, 2017

Degree In graph theory, the degree (or valency) of a vertex of a graph is the number of edges incident to the vertex, with loops… Read More »

## Water Jug problem using BFSNovember 7, 2017

You are given a m litre jug and a n litre jug . Both the jugs are initially empty. The jugs don’t have markings to… Read More »

## Number of cyclic elements in an array where we can jump according to valueNovember 5, 2017

Given a array arr[] of n integers. For every value arr[i], we can move to arr[i] + 1 clockwise considering array elements in cycle. We… Read More »

## Mathematics | Graph theory practice questionsOctober 29, 2017

Problem 1 – There are 25 telephones in Geeksland. Is it possible to connect them with wires so that each telephone is connected with exactly… Read More »

## Betweenness Centrality (Centrality Measure)October 25, 2017

In graph theory, betweenness centrality is a measure of centrality in a graph based on shortest paths. For every pair of vertices in a connected… Read More »

## Graph representations using set and hashOctober 23, 2017

We have introduced Graph implementation using array of vectors in Graph implementation using STL for competitive programming | Set 1. In this post, a different… Read More »

## Number of groups formed in a graph of friendsOctober 22, 2017

Given n friends and their friendship relations, find the total number of groups that exist. And the number of ways of new groups that can… Read More »

## BFS using STL for competitive codingOctober 20, 2017

A STL based simple implementation of BFS using queue and vector in STL. The adjacency list is represented using vectors of vector. In BFS, we… 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 »

## Cycles of length n in an undirected and connected graphOctober 15, 2017

Given an undirected and connected graph and a number n, count total number of cycles of length n in the graph. A cycle of length… Read More »

## Minimum cost to connect weighted nodes represented as arrayOctober 13, 2017

Given an array of N elements(nodes), where every element is weight of that node.Connecting two nodes will take a cost of product of their weights.You… Read More »

## Detecting negative cycle using Floyd WarshallOctober 12, 2017

We are given a directed graph. We need compute whether the graph has negative cycle or not. A negative cycle is one in which the… Read More »

## Detect a negative cycle in a Graph | (Bellman Ford)

We are given a directed graph. We need compute whether the graph has negative cycle or not. A negative cycle is one in which the… Read More »