• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 03, 2022 |1.1K Views

Next Larger element in n-ary tree

  Share   Like
Description
Discussion

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 greater than x. Return NULL if no node is present with value greater than x. 


The idea is maintain a node pointer res, which will contain the final resultant node. 


Traverse the tree and check if root data is greater than x. If so, then compare the root data with res data. 


If root data is greater than n and less than res data update res.
 

Next Larger element in n-ary tree : https://www.geeksforgeeks.org/next-larger-element-n-ary-tree/