Recursive implementation of algorithms on trees, and their efficiency — exercise

Did you try it yourself yet?האם כבר ניסיתם לפתור בעצמכם?

Trying first, even if it fails, lets the exercise teach you. Show the solution now?לנסות לפני צפייה בפתרון, היא דרך טובה מאד ללמוד. האם להציג את הפתרון?