Data Structure
Java
Python
HTML
Interview Preparation
Interview Prep
Tutorials
Tracks
DSA
Practice Problems
C
C++
Java
Python
JavaScript
Data Science
Machine Learning
Courses
Linux
DevOps
Similar Topics
Web Technologies
32.1K+ articles
DSA
20.0K+ articles
Misc
7.7K+ articles
Tree
911+ articles
Recursion
591+ articles
DFS
360+ articles
BFS
228+ articles
tree-level-order
123+ articles
Tree Traversals
106+ articles
tree-traversal
88+ articles
n-ary-tree
94 posts
Recent Articles
Popular Articles
Find root of n-ary tree from given list of nodes
Last Updated: 16 September 2023
Given an N-ary tree as a list of nodes Node[] tree. Each node has a unique value, the task is to find the root of the tree.N-ary treeExamples:Input: 1 /...
read more
Tree
Picked
DSA
n-ary-tree
Generic Tree meaning & definition in DSA
Last Updated: 23 July 2025
A generic tree (or N-ary Tree) is a type of tree data structure where each node can have at most N number of children where N can be any integer.Example of Generic TreeCha...
read more
Tree
Picked
DSA
Definitions and Meanings
n-ary-tree
Count of duplicate Subtrees in an N-ary Tree
Last Updated: 23 July 2025
Given the root of an n-ary tree, the task is to find the number of subtrees that have duplicates in the n-ary tree. Two trees are duplicates if they have the same structur...
read more
Tree
Technical Scripter
Technical Scripter 2022
DSA
n-ary-tree
Maximum Path sum in a N-ary Tree
Last Updated: 23 July 2025
Given an undirected tree with n nodes numbered from 1 to n and an array arr[] where arr[i] denotes the value assigned to (i+1)th node. The connections between the nodes ar...
read more
Tree
Recursion
Picked
DSA
DFS
n-ary-tree
Memoization
Number of leaf nodes in a perfect N-ary tree of height K
Last Updated: 23 July 2025
Find the number of leaf nodes in a perfect N-ary tree of height K.Note: As the answer can be very large, return the answer modulo 109+7.Examples:Input: N = 2, K = 2Output:...
read more
Tree
Mathematical
DSA
n-ary-tree
Level Order Traversal of N-ary Tree
Last Updated: 23 July 2025
Given an N-ary Tree. The task is to print the level order traversal of the tree where each level will be in a new line.Examples:Input:ImageOutput:13 2 45 6Explanation: At ...
read more
Tree
Recursion
DSA
n-ary-tree
tree-level-order
Print List of nodes of given n-ary Tree with number of children in range [0, n]
Last Updated: 23 July 2025
Given an n-ary Tree having N nodes numbered from 1 to N, the task is to print a list of nodes containing 0, 1, 2, 3, . . ., n children.Note: An n-ary Tree is a tree in whi...
read more
Tree
Recursion
DSA
n-ary-tree
tree-level-order
Count of ancestors with smaller value for each node of an N-ary Tree
Last Updated: 23 July 2025
Given an N-ary tree consisting of N nodes with values from 1 to N rooted at 1, for all nodes, print the number of ancestors having a smaller value than the current node.Ex...
read more
DSA
DFS
cpp-set
n-ary-tree
Replace each node in given N-ary Tree with sum of all its subtrees
Last Updated: 23 July 2025
Given an N-ary tree. The task is to replace the values of each node with the sum of all its subtrees and the node itself.ExamplesInput: 1 / | \ 2 3 4...
read more
Tree
Recursion
DSA
n-ary-tree
Count of nodes in a given N-ary tree having distance to all leaf nodes equal in their subtree
Last Updated: 23 July 2025
Given an N-ary tree root, the task is to find the number of non-leaf nodes in the tree such that all the leaf nodes in the subtree of the current node are at an equal dist...
read more
Misc
Tree
DSA
tree-traversal
n-ary-tree
Maximum count of connected duplicate nodes in given N-ary Tree
Last Updated: 23 July 2025
Given a generic tree such that each node has a value associated with it, the task is to find the largest number of connected nodes having the same value in the tree. Two n...
read more
DSA
tree-traversal
n-ary-tree
Count of nodes in given N-ary tree such that their subtree is a Binary Tree
Last Updated: 23 July 2025
Given an N-ary tree root, the task is to find the count of nodes such that their subtree is a binary tree.Example:Input: Tree in the image belowOutput: 11Explanation: The ...
read more
Misc
Tree
DSA
PostOrder Traversal
Binary Tree
tree-traversal
n-ary-tree
Check if given Generic N-ary Tree is Symmetric horizontally
Last Updated: 23 July 2025
Given an N-ary tree root, the task is to check if it is symmetric horizontally (Mirror image of itself).Example:Input: root = 7 / / \ \ ...
read more
Tree
Dynamic Programming
Recursion
DSA
Preorder Traversal
n-ary-tree
Maximize difference between pair of nodes in a given rooted tree such that one node is ancestor of another
Last Updated: 23 July 2025
Given a Generic Tree consisting of N nodes valued from 0 to (N - 1) where P[i]th in the array P[] denotes ith nodes parent(1-based indexing). Each ith node has a weight at...
read more
Tree
Graph
Blogathon
DSA
tree-traversal
BFS
DFS
n-ary-tree
Count the number of common ancestors of given K nodes in a N-ary Tree
Last Updated: 23 July 2025
Given an N-ary tree root and a list of K nodes, the task is to find the number of common ancestors of the given K nodes in the tree.Example:Input: root = 3 / \ ...
read more
Tree
Blogathon
DSA
PostOrder Traversal
n-ary-tree
1
2
3
4
5
6
7