What is Generic Tree or N-ary Tree

Data Structure and Algorithms Course
Recent articles on N-ary Tree

What is a N-ary Tree?

Generic trees are a collection of nodes where each node is a data structure that consists of records and a list of references to its children(duplicate references are not allowed). Unlike the linked list, each node stores the address of multiple nodes.

Every node stores the address of its children and the very first node’s address will be stored in a separate pointer called root.

The Generic trees are the N-ary trees which have the following properties:

  1. Many children at every node.
  2. The number of nodes for each node is not known in advance.

Example:

Generic Trees(N-array Trees)

Generic Trees(N-array Trees)

Introduction:

Easy Problems

  1. Depth of an N-Ary tree
  2. Number of nodes greater than a given value in n-ary tree
  3. General Tree Level Order Traversal
  4. DFS for a n-ary tree represented as adjacency list
  5. Height of n-ary tree if parent array is given
  6. Number of special nodes in an n-ary tree
  7. Preorder Traversal of N-ary Tree Without Recursion
  8. Print all leaf nodes of an n-ary tree using DFS
  9. Count the nodes in the given tree whose weight is even parity
  10. Difference between sums of odd level and even level nodes in an N-ary Tree
  11. Remove all leaf nodes from a Generic Tree or N-ary Tree
  12. Level Order Traversal of N-ary Tree

Intermediate Problems

  1. Diameter of an N-ary tree
  2. Number of ways to traverse an N-ary tree
  3. Mirror of n-ary Tree
  4. Locking and Unlocking of Resources arranged in the form of n-ary Tree
  5. Height of a generic tree from parent array
  6. Next Larger element in n-ary tree
  7. Second Largest element in n-ary tree
  8. Left-Child Right-Sibling Representation of Tree
  9. Longest path in an undirected tree
  10. DP on Trees | Set-3 ( Diameter of N-ary Tree )
  11. Iterative Preorder Traversal of an N-ary Tree
  12. Immediate Smaller element in an N-ary Tree
  13. Iterative Postorder Traversal of N-ary Tree
  14. Maximum level sum in N-ary Tree
  15. Replace every node with depth in N-ary Generic Tree
  16. Count of subtrees from an N-ary tree consisting of single colored nodes
  17. Find if path length is even or odd between given Tree nodes for Q queries
  18. Maximize sum of path from the Root to a Leaf node in N-ary Tree
  19. Kth Smallest Element in an N-ary Tree
  20. Count of subtrees possible from an N-ary Tree
  21. Convert a Generic Tree(N-array Tree) to Binary Tree
  22. Check if given Generic N-ary Tree is Symmetric horizontally
  23. ZigZag Level Order Traversal of an N-ary Tree

Hard Problems

  1. LCA for n-ary Tree | Constant Query O(1)
  2. Serialize and Deserialize an N-ary Tree
  3. Construct the full k-ary tree from its preorder traversal
  4. GCD from root to leaf path in an N-ary tree
  5. Level with maximum number of nodes using DFS in a N-ary tree
  6. Find distance of nodes from root in a tree for multiple queries
  7. Kth ancestor of all nodes in an N-ary tree using DFS
  8. Find node U containing all nodes from a set V at atmost distance 1 from the path from root to U
  9. Find the node at the center of an N-ary tree
  10. Maximum weighted edge in path between two nodes in an N-ary tree using binary lifting
  11. Minimum distance between two given nodes in an N-ary tree
  12. Minimum time required to color all edges of a Tree
  13. Construct a Complete N-ary Tree from given Postorder Traversal
  14. Number of leaf nodes in a perfect N-ary tree of height K
  15. Count of nodes in a given N-ary tree having distance to all leaf nodes equal in their subtree

If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above


  • Last Updated : 26 Sep, 2023

Share your thoughts in the comments
Similar Reads