## DP on Trees | Set-3 ( Diameter of N-ary Tree )

Given an N-ary tree T of N nodes, the task is to calculate the longest path between any two nodes(also known as the diameter of… Read More »

## Determine the count of Leaf nodes in an N-ary tree

Given the value of ‘N’ and ‘I’. Here, represents the number of internal nodes present in an N-ary tree and every node of the N-ary… Read More »

## Level with maximum number of nodes using DFS in a N-ary tree

Given a N-ary tree, the task is to print the level with the maximum number of nodes. Examples: Input : For example, consider the following… Read More »

## Print all the levels with odd and even number of nodes in it | Set-2

Given an N-ary tree, print all the levels with odd and even number of nodes in it. Examples: For example consider the following tree 1… Read More »

## Print levels with odd number of nodes and even number of nodes

Given an N-ary tree, print all the levels with odd and even number of nodes in it. Examples: For example consider the following tree 1… Read More »

## Number of leaf nodes in the subtree of every node of an n-ary tree

Given an N-ary tree, print the number of leaf nodes in the subtree of every node. Examples: Input: 1 / \ 2 3 / |… Read More »

## Preorder Traversal of N-ary Tree Without Recursion

Given an n-ary tree, print preorder traversal of it. Example : Preorder traversal of below tree is A B K N M J F D… Read More »

## Iterative Preorder Traversal of an N-ary Tree

Given a K-ary Tree. The task is to write an iterative program to perform the preorder traversal of the given n-ary tree. Examples: Input: 3-Array… Read More »

## Number of children of given node in n-ary Tree

Given a node x, find the number of children of x(if it exists) in the given n-ary tree. Example : Input : x = 50… Read More »

## Immediate Smaller element in an N-ary Tree

Given an element x, task is to find the value of its immediate smaller element. Example : Input : x = 30 (for above tree)… Read More »

## Sum of all elements of N-ary Tree

Given an N-ary tree, find sum of all elements in it. Example : Input : Above tree Output : Sum is 536 Recommended : Please… Read More »

## Height of a generic tree from parent array

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… Read More »

## Diameter of n-ary tree using BFS

N-ary tree refers to the rooted tree in which each node having atmost k child nodes. The diameter of n-ary tree is the longest path… Read More »

## Number of nodes greater than a given value in n-ary tree

Given a n-ary tree and a number x, find and return the number of nodes which are greater than x. Example: In the given tree,… Read More »

## Next Larger element in n-ary tree

Given a generic tree and a integer x. Find and return the node with next larger element in the tree i.e. find a node just… Read More »