## Disjoint Set Union on trees | Set 2

Given a tree, and the cost of a subtree is defined as |S|*AND(S) where |S| is the size of the subtree and AND(S) is bitwise… Read More »

Given a tree, and the cost of a subtree is defined as |S|*AND(S) where |S| is the size of the subtree and AND(S) is bitwise… Read More »

Given a tree and weights of nodes. Weights are non-negative integers. Task is to find maximum size of a subtree of a given tree such… Read More »

Check whether a given graph contains a cycle or not. Example 1: Input: Output: Graph contains Cycle. Example 2: Input: Output: Graph does not contain… Read More »

Given a connected acyclic graph and a source vertex and a destination vertex, your task is to count the number of vertices between the given… Read More »

Dynamic connectivity is a data structure that dynamically maintains the information about thee connected components of graph. In simple words suppose there is a graph… Read More »

I recently got interviewed for MakeMyTrip for the Software Engineer full time position. There were in a total of 5 rounds. First Round (Online Coding… Read More »

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5… Read More »

Given a set of n jobs where each job i has a deadline di >=1 and profit pi>=0. Only one job can be scheduled at… Read More »

Consider a situation with a number of persons and following tasks to be performed on them. Add a new friendship relation, i.e., a person x… Read More »

Prerequisite : LCA basics, Disjoint Set Union by Rank and Path Compression We are given a tree(can be extended to a DAG) and we have… Read More »

Given an undirected, connected and weighted graph, find Minimum Spanning Tree (MST) of the graph using Kruskal’s algorithm. Input : Graph as an array of… Read More »

Given an undirected graph, how to check if there is a cycle in the graph? For example, the following graph has a cycle 1-0-2-1. My… Read More »

In the previous post, we introduced union find algorithm and used it to detect cycle in a graph. My Personal Notes arrow_drop_up Save

A disjoint-set data structure is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. My… Read More »