Bhaiya…can you explain what will be the complexity of code when we are calculating the diameter of binary tree without optimized approach.
Also, what will be the complexity of “height” function that we are using here…O(m*n) or O(N) …???
Bhaiya…can you explain what will be the complexity of code when we are calculating the diameter of binary tree without optimized approach.
Also, what will be the complexity of “height” function that we are using here…O(m*n) or O(N) …???
Complexity of finding height is O(N)
Complexity of finding diameter is O(N^N)
can you explain why complexity is O(N^N)…for this code??
bcoz for each node u calculate height… so N*N
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.