## Count number of trees in a forest

Given n nodes of a forest (collection of trees), find the number of trees in the forest. Examples : Input : edges[] = {0, 1},… Read More »

Given n nodes of a forest (collection of trees), find the number of trees in the forest. Examples : Input : edges[] = {0, 1},… Read More »

Every house in the colony has at most one pipe going into it and at most one pipe going out of it. Tanks and taps… Read More »

Given an undirected graph and a set of vertices, we have to count the number of non reachable nodes from the given head node using… Read More »

Count the total number of ways or paths that exist between two vertices in a directed graph. These paths doesn’t contain a cycle, the simple… Read More »

We are given a matrix that contains different values in its each cell. Our aim is to find the minimal set of positions in the… Read More »

Given a number n. we need to print all N digit pattern formed by mobile Keypad. Note: we can move up, down, left, right from… Read More »

Given Binary matrix. Task is count all zeros which are surrounded by one (may not be immediate neighbor). Note: here we are only taking four… Read More »

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 »

A tree is always a Bipartite Graph as we can always break into two disjoint sets with alternate levels. In other words we always color… Read More »

Given two numbers n and k and you have to find all possible combination of k numbers from 1…n. Examples: Input : n = 4… Read More »

The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree. The… Read More »

Given a tree in form of adjacency list we have to calculate the number of nodes in the subtree of each node, while calculating the… Read More »

Given a string of characters of length less than 10. We need to print all the alpha-numeric abbreviation of the string. The alpha-numeric abbreviation is… Read More »

A directed acyclic graph (DAG) is a graph which doesn’t contain a cycle and has directed edges. We are given a DAG, we need to… Read More »

Given a directed tree with V vertices and V-1 edges, we need to choose such a root (from given nodes from where we can reach… Read More »