Complexity issue

PLZ EXPLAIN WHY THE COMPLEXITY OF THIS APPROACH IS O(N)???

Hi @bvidab18, in the bottom up approach notice that we compute for every node only once , since the answer is precomputed. eg , let say we are at node i , if we know the answer for its children then we can compute the answer for node i in O(1) . now this is where bottom up approach gives us the advantage . in bottom up approach we first compute answer for the children before the parent thus each node take O(1) time for computation and since we have n nodes thus taking O(n) time

In case of any doubt feel free to ask :slight_smile:
If you got the answer then mark your doubt as resolved

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.