AlgorithmsThread 8: Tree Basics

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

ความคิดเห็น • 148

  • @linzhang9529
    @linzhang9529 4 ปีที่แล้ว +126

    I think this format of mini lecture + practice problem set is the best for beginners, as you mentioned, it is also the most time-consuming for you the content creator :) We beginners can watch lectures after lectures but new concepts will never solidify until we put them into concrete implementations and solve problems with them. And a lot of beginners like me do not necessarily have a solid implementation skill, so practice problems definitely help with this as well.

    • @maxtheking2076
      @maxtheking2076 4 ปีที่แล้ว

      th-cam.com/video/jCHy8PEgIUI/w-d-xo.html

    • @SNX03
      @SNX03 ปีที่แล้ว

      Very true !

  • @lyraforrest3035
    @lyraforrest3035 4 ปีที่แล้ว +29

    Just wanted to say how much I appreciate this ENTIRE channel. Your personality is so infectious ! After every contest I come straight here and use the videos as editorials. You the best !

    • @maxtheking2076
      @maxtheking2076 4 ปีที่แล้ว

      th-cam.com/video/jCHy8PEgIUI/w-d-xo.html

  • @roh9934
    @roh9934 4 ปีที่แล้ว +5

    You have my utmost respect in the community, Knowledge is something you can't repay with anything else.

  • @piyushnaithani7689
    @piyushnaithani7689 4 ปีที่แล้ว +3

    You explained pretty much everything in tree which took me 4-5 months becuz I didn't know we can also do that especially segment one. Those begginers who learn from your videos will definately experience time travel ❤️

  • @deepeshpandey1039
    @deepeshpandey1039 4 ปีที่แล้ว +8

    Loved the new format ! This helps gain much more confidence on the covered concepts instead of just watching a tutorial on some topic and not getting custom problems on that topic.

  • @sohammukherjee8079
    @sohammukherjee8079 4 ปีที่แล้ว +2

    This is by far the most comprehensive tutorial on trees, I've ever come across. Thanks a ton for this one!

  • @mujahidulislam315
    @mujahidulislam315 4 ปีที่แล้ว +2

    I rarely had seen someone like you who helped others like this way. Thanks for this.

  • @utkarshpandey10
    @utkarshpandey10 ปีที่แล้ว

    I really appreciate you devoting a whole week curating these problems, test cases, the video content and recording it and putting it out here for free! god bless you

  • @bunchofiitians5900
    @bunchofiitians5900 3 ปีที่แล้ว

    It's not high quality, its highest quality content. Thank you.

  • @manulgoyal6662
    @manulgoyal6662 4 ปีที่แล้ว +2

    I love this. Very clear explanation. In short, fabulous work. Please keep up the good work🙏

  • @vishnusingh4118
    @vishnusingh4118 4 ปีที่แล้ว +8

    SOOOOOOO Looking forward to this one!! Please go in depth on Trees and solve a lot of problems with common techniques and tricks (with the actual code!). You channel is a blessing! Keep it up! I'll send you money the day I start earning!

    • @RifatulIslam__
      @RifatulIslam__ 4 ปีที่แล้ว

      Me too

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +17

      Thanks guys, I truly appreciate the sentiment, but I don't want to be taking money from people for this, at least not anytime soon :)

  • @fastio8489
    @fastio8489 4 ปีที่แล้ว +14

    Was an intermediate level stuff ig. Very informative. Euler tours concept was very well explained. Being able to solve path queries using this is amazing. Thanks

    • @maxtheking2076
      @maxtheking2076 4 ปีที่แล้ว

      th-cam.com/video/jCHy8PEgIUI/w-d-xo.html

  • @PankajKumarGladiator
    @PankajKumarGladiator 4 ปีที่แล้ว

    Tutorial is really helpful. Please continue creating quality video tutorials like this. Thank you so much for sharing your knowledge here.

  • @showthecode5223
    @showthecode5223 4 ปีที่แล้ว +2

    Hey man please continue this and thanks for this amazing style of teaching
    Everytime after a codeforces round just waiting for u to post the solutions video and all videos are super useful

  • @arujbansal
    @arujbansal 4 ปีที่แล้ว +8

    I see tree flattening in the description. I remember messaging you on cf to cover that. Thanks!

  • @vamsikrishnavalluru611
    @vamsikrishnavalluru611 4 ปีที่แล้ว

    Dude GG. I always thought this stuff was for GMs and never even touched the content on CP-Algorithms. 40 min well spent, I shall get down to the gym now I guess. Also, to answer your final question, yes, I like this format better. You got a like and sub from me.

  • @anubhavkalia5130
    @anubhavkalia5130 4 ปีที่แล้ว +1

    It is a Really helpful way to teach. Please bring more of it. Thanks a lot.

  • @amrosherif203
    @amrosherif203 4 ปีที่แล้ว +22

    just come to hear "goodmorning everyboddy"
    luv man from egypt

    • @maxtheking2076
      @maxtheking2076 4 ปีที่แล้ว

      th-cam.com/video/jCHy8PEgIUI/w-d-xo.html

  • @srikarummineni307
    @srikarummineni307 4 ปีที่แล้ว +2

    Such an awesome initiative and I loved the way you teach.Thank you so much . Could you please include 2 to 3 more problems in gym set please so that we gain more confidence.Thank you once again....!!!

  • @connorcc
    @connorcc 4 ปีที่แล้ว +2

    The gym was especially useful. I don't really want to learn new concepts if there's no problem to submit. Also problem statements are great!

  • @PriyanshAgarwal
    @PriyanshAgarwal 4 ปีที่แล้ว

    You are just awesome. Thanks a lot for this tutorial. The last trick was amazing considering how time-consuming and difficult it is to implement HLD for that thingie.

    • @RomanReigns-ds8hs
      @RomanReigns-ds8hs 4 ปีที่แล้ว

      but that trick works only for mos algorithm isn't it? will that work using segment trees?

  • @Nilesh-xd4ux
    @Nilesh-xd4ux 2 ปีที่แล้ว

    Yeah These tutorials are really helpful, I liked this We get to learn new ideas from this. Thanks for such amazing videos

  • @ritwizsinha1261
    @ritwizsinha1261 4 ปีที่แล้ว +1

    This format is superb!!!

  • @soumyasaurav8388
    @soumyasaurav8388 4 ปีที่แล้ว +1

    Thanks for the great video! Really loved the new format!

  • @muj1003
    @muj1003 4 ปีที่แล้ว

    This format lecture + practice problem is the best !!

  • @shrayammitra6447
    @shrayammitra6447 4 ปีที่แล้ว

    This was so much worth waiting, awesome work bro 🤩

  • @nishkarsharora7482
    @nishkarsharora7482 4 ปีที่แล้ว

    giving problems along with the video was helpful really appreciated

  • @gitlit5489
    @gitlit5489 4 ปีที่แล้ว +44

    Click to Create a new whiteboard... -> gets a blackboard

    • @maxtheking2076
      @maxtheking2076 4 ปีที่แล้ว

      th-cam.com/video/jCHy8PEgIUI/w-d-xo.html

  • @rohitbohra4248
    @rohitbohra4248 4 ปีที่แล้ว

    Amazing content:)
    Thanks for your efforts towards the community💙

  • @codeWithBatta
    @codeWithBatta 4 ปีที่แล้ว

    Thank you for all you have done. I appreciate your efforts.

  • @adityagaur2223
    @adityagaur2223 2 ปีที่แล้ว

    very high quality material ! please bring some on game theory and flow algorithms

  • @537ramu7
    @537ramu7 4 ปีที่แล้ว +2

    Thank you so much sir💗💗🔥🔥 please continue your channel sir

  • @amirh8748
    @amirh8748 4 ปีที่แล้ว +26

    Emmm how it's 9PM and he's still saying good morning everybody xD

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +36

      Good morning!

    • @linzhang9529
      @linzhang9529 4 ปีที่แล้ว

      He is based in Pacific Time that spans the US west coast, which is 8 hours behind UTC. Besides this is a recorded lecture.

    • @amirh8748
      @amirh8748 4 ปีที่แล้ว +4

      @@linzhang9529 yeah I know but look at the time on his screen

    • @linzhang9529
      @linzhang9529 4 ปีที่แล้ว +6

      @@amirh8748 oh, lol. I think it has officially become second thread's catch phrase now.

    • @abhinaysingh637
      @abhinaysingh637 4 ปีที่แล้ว

      Thanks for all efforts

  • @RifatulIslam__
    @RifatulIslam__ 4 ปีที่แล้ว

    very helpful man
    I had a problem on binary lifting but I got it now

  • @scameeer
    @scameeer 4 ปีที่แล้ว +1

    Thanks a lot for this valuable effort!

  • @ashuthe1
    @ashuthe1 ปีที่แล้ว +1

    This is super helpful!

  • @satyamsingh-zo8ex
    @satyamsingh-zo8ex 4 ปีที่แล้ว +1

    This was very helpful. Thanks a lot!

  • @mamtachahal1277
    @mamtachahal1277 4 ปีที่แล้ว

    YOU ARE THE BEST PERIOD.

  • @ziedbrahmi4812
    @ziedbrahmi4812 2 ปีที่แล้ว

    AMAZING STUFF! thank you

  • @kxb6098
    @kxb6098 3 ปีที่แล้ว +1

    this is very helpful

  • @filipbarbaric1960
    @filipbarbaric1960 4 ปีที่แล้ว +3

    Can we use bynari search to find LCA, like if we have two nods on same level and wont to find ancestor.

  • @ankitkumarsingh8295
    @ankitkumarsingh8295 4 ปีที่แล้ว +1

    Hey David! About 2nd problem I find all the leaves that can be a part of diameter and then while printing if it one of these leaves then I increase the diameter by 1 or I just print the original diameter ..is this logic wrong?...it's giving WA verdict on case 14.

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +1

      The general idea is right: if you add an edge onto a leaf of an original diameter, you increase the answer by one, otherwise it doesn’t change. Make sure you’re correctly identifying all leaves of some diameter correctly though. That part is easy to mess up.

    • @ankitkumarsingh8295
      @ankitkumarsingh8295 4 ปีที่แล้ว

      Thank you David I'll check that :)

  • @het314
    @het314 4 ปีที่แล้ว +1

    You deserve more subs.

  • @michalisandreou8469
    @michalisandreou8469 4 ปีที่แล้ว

    Thanks a lot for the lecture. Practise problems are great and key
    Could you please post up such a video on square root decomposition?

  • @shivamkushwah3542
    @shivamkushwah3542 3 ปีที่แล้ว

    Dude u r one of those few who I feel like paying but I can't coz I am broke (lol)...instead my college professors are taking that money for no reason.....thanks a lot

    • @SecondThread
      @SecondThread  3 ปีที่แล้ว +1

      Thanks man, that really means a lot to know this is helpful.

  • @keshavprince1815
    @keshavprince1815 4 ปีที่แล้ว +1

    Great work

  • @harshitagarwal9026
    @harshitagarwal9026 4 ปีที่แล้ว

    It's really helpful.Thanks a lot

  • @abdelrhmansamir1426
    @abdelrhmansamir1426 4 ปีที่แล้ว

    Can i ask which point will we update when we want to modify the segment tree?
    The index in the Euler tour which has the starting time of that node or am i mistaken?
    And for more clarification if we want to assign value v to node x, then i just look for it's start time index in the flatten array and update it in the segment tree?
    31:26

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +1

      Yep, the starting index would correspond to that node in the tree.

    • @abdelrhmansamir1426
      @abdelrhmansamir1426 4 ปีที่แล้ว

      Thank you :).

  • @subhramanya1406
    @subhramanya1406 4 ปีที่แล้ว +1

    Thanks a lot for the tutorial

  • @NISHANTSHARMA-gw4mz
    @NISHANTSHARMA-gw4mz 2 ปีที่แล้ว

    This video is awesome😀.

  • @rishikeshjoshi7786
    @rishikeshjoshi7786 4 ปีที่แล้ว

    I am not able to get AC in tree circumference problem . What to do ? There is no editorial available ..

  • @albertsebastian2880
    @albertsebastian2880 4 ปีที่แล้ว +1

    Can you please do a tutorial on data structures and algorithms for beginners

  • @amjadalhouseini8422
    @amjadalhouseini8422 4 ปีที่แล้ว

    I just love your videos :)

  • @alohanumen4250
    @alohanumen4250 2 ปีที่แล้ว

    very good observation 🧐

  • @candymanmonster4880
    @candymanmonster4880 2 ปีที่แล้ว

    Hey man, is it possible to apply the logic of applying BFS on a random node, and then applying BFS from one of the end points of the diameter to a graph with no cycles? Would a graph with no cycle work the same as a tree in this case?

    • @SecondThread
      @SecondThread  2 ปีที่แล้ว +1

      If the graph is connected, a graph with no cycles is a tree. If the graph has multiple components but no cycles, then that's a "Forrest" of trees, and you'd have to check each component. (Otherwise you might start in the wrong one)

  • @puneetkumarsingh1484
    @puneetkumarsingh1484 4 ปีที่แล้ว

    What is HLD which is continuously referred in the video?

  • @falseee4445
    @falseee4445 4 ปีที่แล้ว

    33:00 wouldnt it be more efficient to go from the down node and go up until the higher node is reached ? No need to precompute since depths values are already needed for lca

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว

      Not quite sure what you mean. Can you explain what the original problem was and your proposed alternative in more detail?

    • @falseee4445
      @falseee4445 4 ปีที่แล้ว

      ​@@SecondThread
      Nvm, i figured it out. What i said was dumb

  • @vikasbhadoriya1466
    @vikasbhadoriya1466 4 ปีที่แล้ว +1

    Please make a playlist on Graph
    Please sir!!

  • @jatin1269
    @jatin1269 4 ปีที่แล้ว +2

    please make a video on BITMASKING with DP

  • @ycryan
    @ycryan ปีที่แล้ว

    I LOVE THIS

  • @Erotemic
    @Erotemic ปีที่แล้ว +1

    Describing Euler as "some guys name". It's true, but he's a pretty important guy.

  • @abhishekagrawal8139
    @abhishekagrawal8139 4 ปีที่แล้ว +1

    That's it for this thread....!!

  • @KAUSHIKAKALI
    @KAUSHIKAKALI 4 ปีที่แล้ว

    What is the editor you are using to draw the diagrams ?

  • @amoghgupta142
    @amoghgupta142 4 ปีที่แล้ว

    hey, isn't your LCA O(logN*logN) per query? logN for binary search and logN for moving up by that much. How do you bring it down to O(logN)?

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว

      Only one log because the “binary search” value only goes down, it never increases.

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว

      That is, if you jump up 2^12, you start checking 2^12 next time, then 2^11... so you only do 20 jumps total, and it amortizes to O(1) per jump

  • @abhishekagrawal8139
    @abhishekagrawal8139 4 ปีที่แล้ว

    Gr8.....quality stuff....thanks a ton....

  • @FinanceMode14
    @FinanceMode14 2 ปีที่แล้ว

    in path isloation idea why the height of 3 subtree is atmost 2 it should be 1 11:10

  • @prabhavagrawal1712
    @prabhavagrawal1712 2 ปีที่แล้ว

    Can't we path tour using binary lifting? just like we processed lift, we could also process operations on path queries. No hating, just asking

    • @SecondThread
      @SecondThread  2 ปีที่แล้ว

      So first of all binary lifting had an extra log factor so it'd be slower.
      Next, paths can do subtrees, but lifting can't.
      Finally, binary lifting can't process things with updates. When you update 1 node, you'll have to update O(n) nodes' lift arrays. So essentially it's just not possible to support non-static trees if the queries and mutations are arbitrary.

    • @prabhavagrawal1712
      @prabhavagrawal1712 2 ปีที่แล้ว

      ​@@SecondThread I got it. Thanks !!!
      Your playlist really helped me a lot in trees

  • @nachiketkanore
    @nachiketkanore 4 ปีที่แล้ว

    Next up : CF DP gym contest like AtCoder ?

  • @dingdong786
    @dingdong786 4 ปีที่แล้ว

    You are doing great job man.....while(true){ respect++;}

  • @nmnsharma007
    @nmnsharma007 4 ปีที่แล้ว

    Hey, sorry for asking this but I am kinda new to your channel . I know the basics about graphs like bfs,dfs,SCC,shortest paths like Dijkstra, Floyd Warshall etc fairly well. Can you please tell if this video and the gym contest on tree basics is suitable for a pupil like me on Codeforces? NO offence but I just don't want to start this only to find out later that it is too hard for me yet. -Please say yes.-

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +2

      I explain the prereqs required for it to be helpful in the beginning of the video

    • @nmnsharma007
      @nmnsharma007 4 ปีที่แล้ว

      @@SecondThreadok. Thanks for reply 😀

    • @thoiteam7706
      @thoiteam7706 4 ปีที่แล้ว

      You shouldn't be a pupil if you know all these fairly well...

  • @adsonsantos6392
    @adsonsantos6392 4 ปีที่แล้ว

    great video

  • @piyushnaithani7689
    @piyushnaithani7689 4 ปีที่แล้ว

    Could plz participate and explain google kickstart solutions also🙏

  • @amoghgupta142
    @amoghgupta142 4 ปีที่แล้ว

    when will you add the tutorial for your cf gymset? waiting for it!

  • @sayanbose6629
    @sayanbose6629 4 ปีที่แล้ว +1

    thank you :)

  • @PANKAJSharma-he4gg
    @PANKAJSharma-he4gg 4 ปีที่แล้ว

    Which laptop model are you using?

  • @randomdude-kr4in
    @randomdude-kr4in 4 ปีที่แล้ว +4

    Good morning. I get TLE on the second problem, even though my complexity is O(n) #90389036

    • @randomdude-kr4in
      @randomdude-kr4in 4 ปีที่แล้ว

      somehow i figured out that one dfs takes 0.3 secs(on the 4th test case), but i run it 4 times :(

  • @adityakumarsingh648
    @adityakumarsingh648 4 ปีที่แล้ว

    Please make the test cases public now, the contest is already over.

  • @mynewnameisbeautiful___4717
    @mynewnameisbeautiful___4717 4 ปีที่แล้ว

    Given some queries on a weighted tree:
    1) U, V: find this value
    max(max weight of an edge which lies on the shortest path between U and V, min weight of an edge which is not a part of the shortest path between U and V)
    How to solve this?

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว

      The max weight of an edge on a path can be done with binary lifting. Min weight of an edge not in the path seems tricky to me. It's possible to do it in n*log^(2) with a persistent segment tree and Version 2 of tree flattening, but it's tricky at least. There might be a better, way that I can't think of right away though.

    • @atishayjain9341
      @atishayjain9341 4 ปีที่แล้ว

      Nice problem flattening wouldn't work bfs will work but time complexity is not good I guess binary lifting will work with some modification

  • @dontony7071
    @dontony7071 4 ปีที่แล้ว

    I am doing cp for 8 months,still,I didn't knew this idea of finding diameter🤭.

  • @annanya6019
    @annanya6019 4 ปีที่แล้ว

    Love You Bro

  • @shivamjalotra7919
    @shivamjalotra7919 4 ปีที่แล้ว +1

    What about Global round stream ?

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +1

      It should be up on my channel already

    • @fastio8489
      @fastio8489 4 ปีที่แล้ว

      @@SecondThread what about round 1 hackercup?

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +5

      @@fastio8489 No hackercup participation from me allowed since I work for Facebook

    • @fastio8489
      @fastio8489 4 ปีที่แล้ว

      @@SecondThread would be really helpful if you could make videos on solution though.

    • @abhishekagrawal8139
      @abhishekagrawal8139 4 ปีที่แล้ว

      @@fastio8489 th-cam.com/video/vW4UbjBs3Jo/w-d-xo.html

  • @indiansoftwareengineer4899
    @indiansoftwareengineer4899 4 ปีที่แล้ว

    please go through your code once, I have stared cp in java and looking at your videos for help. thanks.

  • @manikandanprabhakaran7516
    @manikandanprabhakaran7516 4 ปีที่แล้ว

    why dont you post tutorial video for your contest - It will be useful for beginners

  • @AkshajMusic
    @AkshajMusic 4 ปีที่แล้ว +2

    Will this be helpful in Codeforces, CodeChef, or USACO competitions?

  • @MahendraSingh-ko8le
    @MahendraSingh-ko8le 4 ปีที่แล้ว

    I thought you'd cover all the topics that you made problems on in your gym set :(

    • @SecondThread
      @SecondThread  4 ปีที่แล้ว +1

      The general topics are all there: diameters, binary lifting, and subtree aggregates. For some problems you need to use a little math knowledge, but mostly it’s all just a short extension of this video

    • @MahendraSingh-ko8le
      @MahendraSingh-ko8le 4 ปีที่แล้ว

      @@SecondThread Can't seem to really understand how to actually implement E from your gym set. I tried looking for some good tutorial on the web but couldn't find something. Do you plan to make a solution video too? If not, can you share some resources for the same? Thanks :)

  • @csbro8368
    @csbro8368 4 ปีที่แล้ว

    doing Euler proud

  • @falseee4445
    @falseee4445 4 ปีที่แล้ว +1

    this format is reaaally usefull like so much thanks a lot man ily :orz: :orz: :orz: :orz: but other videos also suits me lol dw

  • @gena8414
    @gena8414 4 ปีที่แล้ว

    26:36 lol so cute :3

  • @vtvtify
    @vtvtify 4 ปีที่แล้ว

    0:00 midnight for me lmao

  • @hiteshkaushik1468
    @hiteshkaushik1468 4 ปีที่แล้ว +4

    Lets take a moment to thank David aka Secondthread for his hard work and time by liking this comment.

    • @maxtheking2076
      @maxtheking2076 4 ปีที่แล้ว

      th-cam.com/video/jCHy8PEgIUI/w-d-xo.html

  • @RudraSingh-pb5ls
    @RudraSingh-pb5ls 3 ปีที่แล้ว

    "I know how to find diameter of a tree, I didn't start programming last week "
    No way ngl, I didn't know that tree's got diameter too, forget finding the diameter. Also, I didn't start programming last week 😭😭

  • @docstyagi7775
    @docstyagi7775 3 ปีที่แล้ว +1

    Second Thread -
    undoable = undo + able , simple guyz
    Linguistics - Are we a joke to you

    • @SecondThread
      @SecondThread  3 ปีที่แล้ว

      Actually, that's really funny. I just now noticed that it could mean "impossible to complete" as well

    • @docstyagi7775
      @docstyagi7775 3 ปีที่แล้ว

      @@SecondThread Ahh you were right, I didn't cross check dictionary and thought you made up your own word. nm : )

  • @thedivineaurora9336
    @thedivineaurora9336 9 หลายเดือนก่อน

    damn ogs really cooked

  • @scottconcertman3423
    @scottconcertman3423 3 ปีที่แล้ว

    1.1k vs 8 dislikes.
    So if one person uses eight different accounts...

  • @shivamjalotra7919
    @shivamjalotra7919 4 ปีที่แล้ว +1

    There is too much knowledge in this lecture.