Question: Given any Binary Tree and any integer k , i . ( 5 marks ) Write an algorithm CountPaths to count the number of paths

Given any Binary Tree and any integer k ,
i.(5 marks) Write an algorithm "CountPaths" to count the number of paths from root to leaf that sum to k .
For the below Binary tree when the value of k=5 CountPaths will return 3, when the value of k=2, CountPaths will return 0 and for k=6, CountPaths will return 0.
ii.(1 mark) Calculate the time complexity of the algorithm. (Remember to include the number of operations per node)
Given any Binary Tree and any integer k , i . ( 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!