top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

DS: Write a program to find the sum of nodes present at the kth level of a binary tree ?

+3 votes
648 views
DS: Write a program to find the sum of nodes present at the kth level of a binary tree ?
posted Jan 12, 2017 by Rupam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

we can follow two approach to solve this problem.

1> If you ae following in/pre/post order then in each node you can check the level of the node and update the sum where level of the node is equal to the given level.

2> Otherwise you can store the node in level order traversal using queue and do a level order traversal to go to a specific level and find the sum of all these nodes.

answer Jan 12, 2017 by Sachidananda Sahu
...