Sir, This was the best explanation I've ever seen. Please continue doing this great work. Got to know about your channel yesterday and till now I have watched every video of dp in trees playlist. Waiting for more such content.
bhaiya i am also from dtu ,just for god sake ye cses ki problemset me jitne bhi ache questions apko ache lage har topic me se unke upar video zaroor banana
Sir, i implemented a very similar solution using binary lifting and binary search. I did almost the same thing that you did. I just used a single checkancestor function to see if the uplift by y nodes would give a common ancestor or not, and it got accepted. I wanted to ask that if using only one checkancestor function ( which is the very similar and has equal time complexity to getnode function) instead of two getnode function , should it affect the time complexity because it takes O(logn) time only.
I think the only difference here is the constant factor. I feel my code would have also got AC if the time limit was 1.5 secs. What is the time needed for checkancestor() function? If that is O(1) then your algorithm is O(logN) instead of O(log^2N) which I achieve using binary search. Can you share your code, I would like to have a look :)
Actually the idea here is that, what is the time complexity per query. We can preprocess the levels for each node in O(N) and thereafter each query will cost us log^2N or logN time. So yes overall time complexity is O(N + QlogN) where Q is number of queries we need to answer and is more efficient than O(NQ). Also include time taken to build "up" array in preprocess step.
Sir, This was the best explanation I've ever seen. Please continue doing this great work. Got to know about your channel yesterday and till now I have watched every video of dp in trees playlist. Waiting for more such content.
I am happy to know that you are finding it helpful!
It would be great if you could share it with your friends too :)
Definitely...
"The code is quite simple to understand and gives a very good TLE" 😂😂
bhaiya i am also from dtu ,just for god sake ye cses ki problemset me jitne bhi ache questions apko ache lage har topic me se unke upar video zaroor banana
Best video till date!!
Please share the code
Great Explaination !!
Sir, i implemented a very similar solution using binary lifting and binary search. I did almost the same thing that you did. I just used a single checkancestor function to see if the uplift by y nodes would give a common ancestor or not, and it got accepted. I wanted to ask that if using only one checkancestor function ( which is the very similar and has equal time complexity to getnode function) instead of two getnode function , should it affect the time complexity because it takes O(logn) time only.
I think the only difference here is the constant factor. I feel my code would have also got AC if the time limit was 1.5 secs.
What is the time needed for checkancestor() function? If that is O(1) then your algorithm is O(logN) instead of O(log^2N) which I achieve using binary search.
Can you share your code, I would like to have a look :)
@@AlgosWithKartik the checkancestor() function has O(logn) complexity. Here's the code ideone.com/xWKIAU
@@p.adityakumar1762 I guess then your code would have just passed. 0.8 or 0.9 sec in execution time.
Nicely implemented.
can you share your code in replies section? It's not visible now in case you had shared already
Please can you also give the link of code on github.
One doubt only... in order to find the level of each node. Time complexity is O(n) ... So, Shouldn't overall time complexity be O(n)???
Actually the idea here is that, what is the time complexity per query.
We can preprocess the levels for each node in O(N) and thereafter each query will cost us log^2N or logN time.
So yes overall time complexity is O(N + QlogN) where Q is number of queries we need to answer and is more efficient than O(NQ).
Also include time taken to build "up" array in preprocess step.
Thnx sir.. now i got it