Largest element in an N-ary Tree
Given an N-ary tree consisting of N nodes, the task is to find the node having the largest value in the given N-ary Tree.
Examples:
Input:
Output: 90
Explanation: The node with the largest value in the tree is 90.Input:
Output: 95
Explanation: The node with the largest value in the tree is 95.
Approach: The given problem can be solved by traversing the given N-ary tree and keeping track of the maximum value of nodes that occurred. After completing the traversal, print the maximum value obtained.
Below is the implementation of the above approach:
C++
|
90
Time Complexity: O(N)
Auxiliary Space: O(1)
Original page link
Best Cool Tech Gadgets
Top favorite technology gadgets
0 comments:
Post a Comment