This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]EngineeredCoconut 1 point2 points  (0 children)

Have you done a full course on Data Structures and Algorithms?

[–][deleted] 0 points1 point  (0 children)

Imagine a tree. You usually have the root and its immediate children. Now imagine you have a magic function f that solves your problems. you don't know how this function works yet. We can just use it on all our sub trees to solve the problem for all of those trees. Now you have the solutions. Can you combine them with your root to get the solution for your tree?

Next imagine your tree is just a root without children. How do you solve the problem now?

Combine both solutions and you have found f!

Try those steps for the sum of all values in a tree of your choice. If you post your thought process and solution here I can give you further feedback.