Was solving this problem but dont know how to comeup with recursive function for this tree problem

Bro just take a graph and dry run.