top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

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

+3 votes
146 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...