Category Archives: Graph

Check loop in array according to given constraints

Given an array arr[0..n-1] of positive and negative numbers we need to find if there is a cycle in array with given rules of movements. If a number at an i index is positive, then move arr[i]%n forward steps, i.e., next index to visit is (i + arr[i])%n. Conversely, if it’s negative, move backward arr[i]%n… Read More »

Minimum Product Spanning Tree

Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together. A single graph can have many different spanning trees. A minimum product spanning tree for a weighted, connected and undirected graph is a spanning tree with weight product less than… Read More »

Minimum number of operation required to convert number x into y

Given a initial number x and two operations which are given below: Multiply number by 2. Subtract 1 from the number. The task is to find out minimum number of operation required to convert number x into y using only above two operations. We can apply these operations any number of times. Constraints: 1 <=… Read More »