Data Structures: Trees

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024
  • Learn the basics of trees, data structures. This video is a part of HackerRank's Cracking The Coding Interview Tutorial with Gayle Laakmann McDowell.
    www.hackerrank....

Комментарии • 364

  • @timgoppelsroeder121
    @timgoppelsroeder121 6 лет назад +183

    Finally someone who explains a concept without unnecessarily complicating it thank you

  • @rajsaroj4696
    @rajsaroj4696 4 года назад +409

    2020 but, this playlist saving lives

  • @tochinwa1234
    @tochinwa1234 6 лет назад +45

    Gayle is a living legend ! Makes data structures and algorithm a doddle. Thanks Gayle. 😘

  • @maazbinmustaqeem
    @maazbinmustaqeem 5 лет назад +17

    She just goes through the recursion in a very light way with good animation tool. Loved it. Thanks!

  • @amyp2733
    @amyp2733 5 лет назад +44

    Your data structures videos are so helpful! You’re really good at explaining them quickly

  • @MegaMoses91
    @MegaMoses91 3 года назад +6

    This was the best Tree DS explanation I have watched. She’s amazing!

  • @flacodoom
    @flacodoom 7 лет назад +264

    Very well explained code. Trees always give me problems when asked in tests.

  • @-0-__-0-
    @-0-__-0- Год назад +1

    I've created a JavaFX App that animates a Binary Tree from an array and this video solved most of my problems. Thank you so much!

  • @dashnaidoo8017
    @dashnaidoo8017 3 года назад +4

    in 2021 and this is still the most simple and well explained version. Thanks Gayle

  • @mocao3205
    @mocao3205 2 года назад +3

    This video was so beautifully explained, it's no wonder my lecturer recommended it. Thank you very much for your video.

  • @stewartzayat7526
    @stewartzayat7526 7 лет назад +208

    Recursion is such a powerful tool!

    • @Alex-sg6tz
      @Alex-sg6tz 6 лет назад +83

      It is until ..... stack overflow

    • @petegeorgopoulos1088
      @petegeorgopoulos1088 6 лет назад +55

      be careful tho. A lot of people overuse recursion because they wanna be fancy. But remember, recursion builds a stack in memory and does not release it until it works it's way back to the first call. This could lead to some issues. Most things that people use recursion for can be easily done with a simple loop.

    • @shellgecko
      @shellgecko 6 лет назад +7

      only when you have few data otherwise you'll have to use alternatives like dynamic programming

    • @georgievvladimir
      @georgievvladimir 6 лет назад +1

      and such a exhausting struggle for the stack

    • @niesamain1871
      @niesamain1871 4 года назад

      @@shellgecko dafuq are you talking dynamic programming for stack?

  • @anaibrahim4361
    @anaibrahim4361 5 лет назад +8

    saved me thousands of hours to understand this
    thank you sooo much
    very professional explanation

  • @brendabrownofficial
    @brendabrownofficial 6 лет назад +2

    Never knew HackerRank had a youtube channel, the explanations are so good. Thank you for making these!!!

    • @Wiseman_RSA
      @Wiseman_RSA 5 лет назад +2

      At least you found out 8 months ago, I just found out now

    • @Cfuzion
      @Cfuzion 2 года назад +2

      @@Wiseman_RSA Atleast u found out 3 years ago..

  • @jeremiahgray1017
    @jeremiahgray1017 3 года назад

    Jeez what more could you ask for. Clear, concise, and straight to the point

  • @motezart2867
    @motezart2867 5 лет назад +6

    Best run down of trees I've seen. Code with examples after is very effective.

  • @mikelk124
    @mikelk124 11 месяцев назад

    Very well explained. I found how you visually grouped the "paths" of recursive calls helpful to understand what was happening when "traversing" the tree.

  • @will5525
    @will5525 4 года назад +3

    3 years later and this playlist still getting people jobs😎

  • @tahirrazavi7862
    @tahirrazavi7862 6 лет назад +11

    She is literally amazing !

  • @kicksomeup6998
    @kicksomeup6998 3 года назад +8

    Thanks for the video. But IMO there is an issue with how the code is written since these methods are operations on the tree data structure, not the node data structure, hence they should be located inside the respective ADT. Apart from that, the code looks great and is easy to understand. Great work!

    • @Anon-jz7iw
      @Anon-jz7iw Год назад +1

      That's what I thought too. It really confused me in the beginning till I realized it's not really a code for a node but for a binary search tree.

    • @mikelk124
      @mikelk124 11 месяцев назад

      @kicksomeup6998 you mean that each individual node does not contain a node data instance variable? Or that the contains() method is not written as an instance non static method within the node class?

  • @asyncfilebybibek
    @asyncfilebybibek 4 года назад +1

    In the insert method it would not be val = data

  • @ojazzista
    @ojazzista 2 года назад +1

    Mind-blowing yet extremely simple recursive implementation!

  • @MrSchmidt97
    @MrSchmidt97 2 года назад +3

    Wow, this was precise, easy to follow and I feel I understood what is going on
    Really great stuff!

  • @118andrey
    @118andrey 3 года назад

    Thank you, finally someone who doesn't take an hour to explain a 5 minute topic

  • @zawizarudo7295
    @zawizarudo7295 Год назад +1

    Did she just pull a recursion and I understood it? Damn she's great!

  • @JoseGarcia-lm3qn
    @JoseGarcia-lm3qn 6 лет назад +2

    she is so talented! Learned this right away thanks to her

  • @granturismoautos
    @granturismoautos 7 лет назад +47

    this is AMAZING!! Well explained!

  • @orkhanahmadov9963
    @orkhanahmadov9963 4 года назад +3

    I watched this video and programmed binary tree in python totally it took me 30 mins... Professor could not explain in whole semester: D

  • @shilpaarora8841
    @shilpaarora8841 3 года назад

    Really crisp , clear and easy explanation. DS became so easy to grasp the way you explained.

  • @daleprather3026
    @daleprather3026 3 года назад +3

    Good stuff! Makes me feel dumb when the teacher says "Let's implement this. It's really simple."

  • @elliemay1748
    @elliemay1748 5 лет назад

    Very excellent explanation, clearest one I’ve ever heard. Deleting needs its own video, so I understand why you decided not to include it. On programming tests, I’m always like “can I not write out all the recursion methods? I hate writing all the if statements... we both know what we are talking about, this is a binary search tree ok?” haha.

  • @MrDaryl101114
    @MrDaryl101114 3 года назад +1

    This is gold!! Everything made sense now!

  • @RandyPfohl
    @RandyPfohl 5 лет назад +5

    I would have expected the insert and contains functions to be in a Tree class of some sort, and the node to be an internal implementation operating on a comparable interface. So we can return just the data not the node itself.
    I know it's outside of the scope of this video, but wondering if it's a common practice to put this logic inside of the node class.

  • @samidowu6690
    @samidowu6690 5 лет назад +3

    For the insertion. You have to Check if there’s a root node first of, I think. If data == null, then value = data;

    • @kolhapure
      @kolhapure 5 лет назад

      it is called as,
      public static void main(String[] args) {
      //Say you have a tree with root node being "root"
      int value = 6;
      if(root!=null) {
      root.insert(value);
      }
      }

  • @progtom7585
    @progtom7585 4 года назад

    I love the presentation of code alongside diagrams as im a visual learner, really appreciate it.

  • @wenkaiyang1487
    @wenkaiyang1487 10 месяцев назад +1

    Thank you so much for the explanation!

  • @denniswave95
    @denniswave95 7 лет назад +7

    This was a really clear explanation. Thank you!

  • @tan8067
    @tan8067 4 года назад +6

    Wow! Thank you so much for explaining this, I get it now. Now I just have to practice it.

  • @SuperOneWinged
    @SuperOneWinged 7 лет назад +5

    I love your videos so much, keep it up, you are one of the best

  • @rishabh3952
    @rishabh3952 7 лет назад +4

    short and on point that's wat I wanted.saved my time! thanks.

  • @Phoenix84118
    @Phoenix84118 6 лет назад +26

    Finally, someone who write 5 the same way I do!

  • @KidsCreativeTime
    @KidsCreativeTime 2 года назад

    Thank you very madam. you have explained the Basics of tree traversal very nicely in a simple way..

  • @harshrathee5186
    @harshrathee5186 4 года назад +2

    I think you should have implemented contains method in the Binary Tree class instead of the Node class

  • @vasanthane8425
    @vasanthane8425 4 года назад

    Really Great Video and Explanations within short minutes which we can understand the concept. Kudos!! Team.

  • @bik8353
    @bik8353 6 лет назад

    Thank you for this vivid walkthrough of the code. This is one of the best of this kind

  • @dinamiller2853
    @dinamiller2853 9 месяцев назад

    This was such an easy to understand video. Does anyone know if Gayle Laakmann McDowell has her own channel?

  • @thelambsauce2015
    @thelambsauce2015 3 года назад +1

    Very informative and straight-forward video, thank you!

  • @Ormonix
    @Ormonix 2 года назад

    Very clear explanation and simple understandable code, Thanks a lot

  • @Dizkover
    @Dizkover 5 лет назад

    WOW.... she explained it very well. Once you understand it... it's basically like elementary.

  • @nitinsoni9848
    @nitinsoni9848 4 года назад

    You made it very easy to understand. How simple it is and I always fear with the name trees.

  • @jonnywright8155
    @jonnywright8155 6 лет назад +6

    C# people who copied this and don't get it please read. First, do everything she does in this video exactly the way she did it. It literally works exactly the same in C#. Only difference, also add an empty constructor that takes in no argument. "Public Node( )" This will let you instantiate the node class in your code, without first inserting a value, so "Node testNode = new Node( ). Then create an int[ ] "int array or list whatever" and fill it with a bunch of misordered numbers. Then run a foreach loop filling taking each value from the array and plugging it into the node you created. "testNode.Insert(value)". Then you're good to go. Afterwords you can run the testNode.printInOrder and actually see that it worked. Good luck!!! Reply back if you didn't understand.

    • @bandrefilipe
      @bandrefilipe 5 лет назад

      I haven't touched C# yet, only Java. Why C# needs an empty constructor besides any given alternative?

  • @hritikbansal14
    @hritikbansal14 4 года назад

    More than amazing. Such a simple explanation. Well taught. Thanks HackerRank...

  • @mfaani
    @mfaani 6 лет назад +1

    I was confused as to how 10 gets printed before 5,8.
    But it's more like, if root has something then do printInOrder of left & 'AFTER' left.printInOrder (which is recursive in itself). print the node itself. So basically the ENTIRE tree on the left of every node gets printed first...Then the root of every subtree, then then the right and finally the ENTIRE subtree of the right

  • @tanihakdog1291
    @tanihakdog1291 3 года назад

    i understand your teachings better than my prof. nice video!💜

  • @khalidsleiman231
    @khalidsleiman231 2 года назад

    it's really helpful you are like saving lives appreciate it. thanks ma'am.

  • @muktadirkhan6674
    @muktadirkhan6674 5 лет назад +6

    She always have to bash that she is the author of Cracking the Coding Interview. I know it woman. I have watched tons of your videos.
    Edit: I love your videos

    • @FanVedete
      @FanVedete 5 лет назад

      It is the first time I watch her, so I didn’t know that...

  • @ashishmishra672
    @ashishmishra672 7 лет назад

    Wow. The way you explained it, beautiful!

  • @alicenorman5236
    @alicenorman5236 3 года назад

    She explained this 100x better than my professor could

  • @jamesjohn8397
    @jamesjohn8397 3 года назад

    Excellent explanation !! I can tell you, you have done excellent work, simple clear, and concise well done !! and thank you !!

  • @angelesfigueredo5740
    @angelesfigueredo5740 2 года назад

    Such an amazing explanation!!! Thanks for your video

  • @brentfeathers7004
    @brentfeathers7004 3 года назад

    One such algorithm (2:40 of clip) is the AVL Search Tree, where it prevents the skewed linked list Big O performance issue.

  • @ijustsawthat
    @ijustsawthat 5 месяцев назад

    2:46 Candidate: these algorithms can be very complicated, so we are not going into details here.
    Interviewer: Understandable, have a good day.

  • @upgames1313
    @upgames1313 6 лет назад +3

    this was so well explained and clear! thank you!

  • @darshanvadile1288
    @darshanvadile1288 7 месяцев назад +1

    what a coding skills mam just awesome '

  • @yemaneabrha5902
    @yemaneabrha5902 2 года назад

    Ohh my God what a simple expression u are Wonderfull teacher

  • @moviefanie
    @moviefanie 4 года назад

    I hope you can post a video on how to build a relatively balanced tree. With the example on this video, all the weight goes to the right side of tree. Like you said in the video is not very efficient.

  • @realworldcodingapplications
    @realworldcodingapplications Год назад

    wow this was pretty simple explanation and easy to understan thanks

  • @PriyankaSingh-vm4kv
    @PriyankaSingh-vm4kv 3 года назад

    Amazing explanation!! Can you make more videos on data structures covering all topics plz

  • @obakengmothusi9149
    @obakengmothusi9149 Год назад

    You are phenomenal... Loved your video.💕💕

  • @JoseAlvarez-dl3hm
    @JoseAlvarez-dl3hm 5 лет назад +1

    Very nice little lecture, but I cannot figure it out which would be an example of a good real developer scenario in which a tree would be the more efficient way.

  • @systemdeadlock
    @systemdeadlock 2 года назад

    Great explanation, thanks.
    Sincerely,
    Someone who smokes a lot of trees

  • @jgshanth
    @jgshanth 6 лет назад +33

    "lets add a constructor to make our lives easier" god this developer life

    • @itsajin
      @itsajin 6 лет назад +4

      if only the constructor initialised the left and right to null

    • @Zapanath
      @Zapanath 4 года назад +2

      itsajin why? Node is a reference type....it’ll be implicitly null....

  • @hritikagarwal7676
    @hritikagarwal7676 4 года назад +2

    There must be an implementation of delete function in this video, it will add more value to it.

  • @codeisawesome369
    @codeisawesome369 7 лет назад

    You're awesome Ms. McDowell! Many thanks.

  • @himanshusuthar7158
    @himanshusuthar7158 6 лет назад +1

    Well explained. Exactly what I needed. Thank you.

  • @36nibs
    @36nibs 3 года назад

    Are use the same technique to schedule my priorities and tasks throughout the day.

  • @lokeshchebrolu6878
    @lokeshchebrolu6878 4 года назад

    omg trees are this simple? fantastic explanation that too in this much short time.

  • @wesNeill
    @wesNeill 3 года назад

    Great explanation. My only question is how to implement it such that the node can contain an arbitrary (but homogeneous) data type?

  • @75hilmar
    @75hilmar 2 года назад

    Just what I needed right now.

  • @prestonhall5171
    @prestonhall5171 5 лет назад +1

    I love this explanation, but I’m kind of surprised that you had all of the BST methods in the Node class. It works, I guess, but just seems like an inappropriate place to put them.

  • @CJRH1FILMS
    @CJRH1FILMS 3 года назад +1

    2 Questions: method printInOrder() what is System.out.printIn(data) doing? Also in this in-order example.. why after 5 is the next “in-order” number 8? Shouldn’t it be 10?
    I understand recursively we’re traversing to the Left most depth node in the binary tree ( up until left == null ) - but I’m confused how we’re printing from that point forward.

    • @MUBPHAT
      @MUBPHAT 3 года назад +1

      Similar question here. Once it's on the bottom of the left side of the tree, on either left or right node, how does it jump back up to root node?

  • @vigneshram7464
    @vigneshram7464 7 лет назад +1

    Well explained. Works like charm !! Thanks

  • @Yusifinify
    @Yusifinify 3 года назад

    Fantastic breakdown. You are the truth.

  • @gabriellerosa6453
    @gabriellerosa6453 4 года назад

    Gayle you is amezing!! I love you , ty for being inspiration for all women in cs area.

  • @H3000-v7i
    @H3000-v7i 5 лет назад +1

    I think this is cleaner... but is it better/worse? (Its C++, if any wonder)
    bool contains(int value){
    if(this == nullptr)
    return false;
    else if(value == data)
    return true;
    else if(valuecontains(value);
    else if(value>data)
    return right->contains(value);
    return false;
    }

  • @irayyamathad6838
    @irayyamathad6838 6 лет назад

    Hi, very well explained and I request to you can you make more complete data structure videos on C, C++ and Java.

  • @nakulkorde1619
    @nakulkorde1619 5 лет назад +1

    Honestly, after watching this video I got confused. I am sure that this code works fine, but why is there no Binary Tree structure being created? All the functions which ideally should be written for a BST data structure are written for a node. So if I wanted to construct a BST, do I create a Node object??

  • @hiteshmehta616
    @hiteshmehta616 5 лет назад

    This explanation makes my life simple against Binary Tree Thanks Alot !! :)

  • @Kirwel
    @Kirwel 4 года назад +2

    In the insert method, what if the tree is empty, how it would insert the first node, since the code says left or right

  • @mav474
    @mav474 4 года назад

    Thank you for posting such a useful article!

  • @tedjohnson912
    @tedjohnson912 6 лет назад

    I actually understood binary trees after this video! Wow.

  • @JustSkillGG
    @JustSkillGG 6 лет назад

    Its a very nice and simple way to do all that stuff , but what about the destructor? How would you do it ?

  • @response2u
    @response2u 6 лет назад +1

    Very nicely explained! Well done!

  • @FarizDarari
    @FarizDarari 7 лет назад

    Very clear explanation, and nice drawings!

  • @gabrielpereiramendes3463
    @gabrielpereiramendes3463 5 лет назад

    Awesone. Thanks from Brazil. Excelent explanation!

  • @420thlegioner8
    @420thlegioner8 4 года назад

    10 OUT OF 10.
    IF I UNDERSTOOD, EVERYONE CAN.

  • @ericgadzi7801
    @ericgadzi7801 3 года назад

    Great explanation. Thanks very much.

  • @RePuLseHQKing
    @RePuLseHQKing 2 года назад

    the perfect video on trees

  • @RadostinaChipanova
    @RadostinaChipanova 3 года назад

    You are an amazing educator! Thank you

  • @navzy6211
    @navzy6211 Год назад

    that was more useful than my entire semester

  • @abdallaelmedani8933
    @abdallaelmedani8933 6 лет назад

    Thank you, Gayle. Well explained.