# Category Archives: Tree

## Construct an N-ary Tree having no pair of adjacent nodes with same weight from given weights

Given an array weights[] consisting of N positive integer, where weights[i] denotes the weight of ith node, the task is to construct an N-ary tree… Read More »

## Sum of nodes having sum of subtrees of opposite parities

Given a Binary Tree, the task is to find the sum of all such nodes from the given tree whose sum of left and right… Read More »

## Maximize sum of MEX values of each node in an N-ary Tree

Given an N-ary tree rooted at 1, the task is to assign values from the range [0, N – 1] to each node in any… Read More »

## Difference between Min Heap and Max Heap

A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Since a heap is a complete binary tree,… Read More »

## Sum of nodes in the path from root to N-th node in given Tree

Given an integer N which needs to be present as a value in a node in the last level of a Tree rooted at 1… Read More »

## Count nodes having Bitwise XOR of all edges in their path from the root equal to K

Given a Binary Tree consisting of N nodes and two integers R and K. Each edge of the tree has a positive integer associated with… Read More »

## Print siblings of a given Node in N-ary Tree

Given an N-ary tree and an element X, the task is to print the siblings of the node with value X. Two nodes are considered… Read More »

## Count unique paths with given sum in an N-ary Tree

Given an integer X and integer N, the task is to find the number of unique paths starting from the root in N-ary tree such… Read More »

## Largest subtree sum for each vertex of given N-ary Tree

Given an N-array tree of N nodes, rooted at 1, with edges in the form {u, v}, and an array values[] consisting of N integers.… Read More »

## Generate original permutation from given array of inversions

Given an array arr[] of size N, where arr[i] denotes the number of elements on the left that are greater than the ith element in… Read More »

## Convert a Generic Tree(N-array Tree) to Binary Tree

Prerequisite: Generic Trees(N-array Trees)  In this article, we will discuss the conversion of the Generic Tree to a Binary Tree. Following are the rules to… Read More »

## Remove nodes from Binary Tree such that sum of all remaining root-to-leaf paths is atleast K

Given a Binary Tree and an integer K, the task is to delete nodes from the given Tree such that the sum of all nodes… Read More »

## Pair of strings having longest common prefix of maximum length in given array

Given an array of strings arr[], the task is to find the pair of strings from the given array whose length of the longest common… Read More »

## Print all root-to-leaf paths with maximum count of even nodes

Given a Binary tree, the task is to print all possible root-to-leaf paths having a maximum number of even valued nodes. Examples: Input:  2 /… Read More »

## Maximum possible score that can be obtained by constructing a Binary Tree based on given conditions

Given an array arr[] of (N – 1) integers and each value arr[i](1-based indexing) is the score of the nodes having degree i. The task… Read More »