Dynamic Programming on Trees: LCA using Binary Search

  Рет қаралды 10,422

Kartik Arora

Kartik Arora

Күн бұрын

Пікірлер: 17
@Newgen123Blogspotawaytosuccess
@Newgen123Blogspotawaytosuccess 4 жыл бұрын
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.
@AlgosWithKartik
@AlgosWithKartik 4 жыл бұрын
I am happy to know that you are finding it helpful! It would be great if you could share it with your friends too :)
@Newgen123Blogspotawaytosuccess
@Newgen123Blogspotawaytosuccess 4 жыл бұрын
Definitely...
@KaranYadav-gr5xj
@KaranYadav-gr5xj 2 жыл бұрын
"The code is quite simple to understand and gives a very good TLE" 😂😂
@ankitbhardwaj9566
@ankitbhardwaj9566 4 жыл бұрын
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
@pranshunayak1792
@pranshunayak1792 Жыл бұрын
Best video till date!!
@adarshkumar6876
@adarshkumar6876 2 жыл бұрын
Please share the code
@princhipawansaikia
@princhipawansaikia Жыл бұрын
Great Explaination !!
@p.adityakumar1762
@p.adityakumar1762 4 жыл бұрын
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.
@AlgosWithKartik
@AlgosWithKartik 4 жыл бұрын
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 :)
@p.adityakumar1762
@p.adityakumar1762 4 жыл бұрын
@@AlgosWithKartik the checkancestor() function has O(logn) complexity. Here's the code ideone.com/xWKIAU
@AlgosWithKartik
@AlgosWithKartik 4 жыл бұрын
@@p.adityakumar1762 I guess then your code would have just passed. 0.8 or 0.9 sec in execution time. Nicely implemented.
@khanakpatwari2587
@khanakpatwari2587 8 ай бұрын
can you share your code in replies section? It's not visible now in case you had shared already
@aadarshktofficial
@aadarshktofficial Жыл бұрын
Please can you also give the link of code on github.
@Newgen123Blogspotawaytosuccess
@Newgen123Blogspotawaytosuccess 4 жыл бұрын
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)???
@AlgosWithKartik
@AlgosWithKartik 4 жыл бұрын
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.
@Newgen123Blogspotawaytosuccess
@Newgen123Blogspotawaytosuccess 4 жыл бұрын
Thnx sir.. now i got it
Dynamic Programming on Trees: LCA in O(logN)
11:02
Kartik Arora
Рет қаралды 9 М.
Binary Lifting (Kth Ancestor of a Tree Node)
18:01
Errichto Algorithms
Рет қаралды 100 М.
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
Dynamic Programming Explained (Practical Examples)
29:00
Tech With Tim
Рет қаралды 108 М.
Binary lifting: Dynamic Programming on Trees
21:39
Kartik Arora
Рет қаралды 26 М.
DP with Bitmasking #1
19:19
Kartik Arora
Рет қаралды 42 М.
Lowest Common Ancestor  - O(logN) | Binary Lifting
15:11
Fluent Algorithms
Рет қаралды 9 М.
DP on Trees: Distance in Tree
17:16
Kartik Arora
Рет қаралды 11 М.
Sparse Table & RMQ (Range Minimum Query)
18:42
Errichto Algorithms
Рет қаралды 78 М.
Longest Increasing Subsequence in O(NlogN)
27:51
Kartik Arora
Рет қаралды 17 М.
L27. Lowest Common Ancestor in Binary Tree | LCA | C++ | Java
14:09
take U forward
Рет қаралды 328 М.
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН