We are given a tree of size n as array parent[0..n-1] where every index i in parent[] represents a node and the value at i represents the immediate parent of that nod...

Share

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 it with two colors such that al...

Share

A tree consisting of n nodes is given, we need to print its DFS.
Examples :
Input : Edges of graph
1 2
1 3
2 4
3 5
Output : 1 2 4 3 5
...

Share

Given an undirected connected tree with N nodes (and N-1 edges), we need to find two paths in this tree such that they are non-intersecting and the product of their l...

Share

Given an undirected tree whose each node is associated with a weight. We need to delete an edge in such a way that difference between sum of weight in one subtree to ...

Share

Given an undirected graph, which has tree characteristics. It is possible to choose any node as root, the task is to find those nodes only which minimize the height o...

Share

Given a tree (not necessarily a binary tree) and a number of queries such that every query takes two nodes of tree as parameters. For every query pair, find if two no...

Share

Minimum Spanning Tree (MST) problem: Given connected graph G with positive edge weights, find a min weight set of edges that connects all of the vertices.
MST is fund...

Share

What is Steiner Tree?
Given a graph and a subset of vertices in the graph, a steiner tree spans though the given subset. The Steiner Tree may contain some vertices wh...

Share

We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm...

Share