Maximum product of a pair of nodes from largest connected component in a Graph
Given an undirected weighted graph G consisting of N vertices and M edges, and two arrays Edges[][2] and Weight[] consisting of M edges of the graph and weights of each edge respectively, the task is to find the maximum product of any two vertices of the largest connected component of the graph, formed by connecting all edges with the same weight....
read more
Make given segments non-overlapping by assigning directions
Given an array arr[][] consisting of N segments of the form {L, R, V} where, [L, R] denotes a segment with velocity V in any direction, the task is to check if it is possible to assign directions as left or right to all the segments such that they do not intersect after a long period of time....
read more
Construct a graph using N vertices whose shortest distance between K pair of vertices is 2
Given two positive integers N and K, the task is to construct a simple and connected graph consisting of N vertices with the length of each edge as 1 unit, such that the shortest distance between exactly K pairs of vertices is 2. If it is not possible to construct the graph, then print -1. Otherwise, print the edges of the graph....
read more
Count all Hamiltonian paths in a given directed graph
Given a directed graph of N vertices valued from 0 to N – 1 and array graph[] of size K represents the Adjacency List of the given graph, the task is to count all Hamiltonian Paths in it which start at the 0th vertex and end at the (N – 1)th vertex....
read more
Maximum GCD of all nodes in a connected component of an Undirected Graph
Given an undirected graph consisting of V vertices and a 2d array E[][2] denoting edges between pairs of nodes. Given another array arr[] representing values assigned to each node, the task is to find the maximum GCD among the GCD of all connected components in the graph....
read more
Finding Astronauts from different countries
Given a positive integer N denoting the number of astronauts(labelled from 0 from (N – 1))and a matrix mat[][] containing the pairs of astronauts that are from the same country, the task is to count the number of ways to choose two astronauts from different countries....
read more
Check if the array can be sorted using swaps between given indices only
Given an array arr[] of size N consisting of distinct integers from range [0, N – 1] arranged in a random order. Also given a few pairs where each pair denotes the indices where the elements of the array can be swapped. There is no limit on the number of swaps allowed. The task is to find if it is possible to arrange the array in ascending order using these swaps. If possible then print Yes else print No.Examples:...
read more
Check if the given graph represents a Ring Topology
Given a graph G, the task is to check if it represents a Ring Topology.A Ring Topology is the one shown in the image below:...
read more
Number of Walks from source to destination
Given a graph and two vertices src and dest, count the total number of paths from src to dest where the length of the path is k (there should be exactly k edges between them). Note that the graph is represented as an adjacency matrix.For example, consider the following graph:...
read more
Adjacency List Generation from Edge Connections
Given a list of undirected edge connections of size E, create an adjacency list for a graph with V nodes and E edges following 0-based indexing and return the adjacency list....
read more
Union and Intersection of two Graphs
Given two graphs G1 and G2, the task is to find the union and intersection of the two given graphs, i.e. (G1 ∪ G2) and (G1 ∩ G2)....
read more
Eulerian Path in undirected graph
Given an adjacency matrix representation of an undirected graph. Find if there is any Eulerian Path in the graph. If there is no path print “No Solution”. If there is any path print the path....
read more