Coding Challenge #65.1: Binary Search Tree

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024

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

  • @adamoja4295
    @adamoja4295 2 ปีที่แล้ว +23

    Your not editing out the parts where you get confused (like with the returns in the recursive methods ) is wholesome . It’s what others don’t do . And this is a priceless lesson for everyone who has not been confronted with those kinds of problems before .
    Fan since started to code.

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

    I love the reasoning and unedited display of bloopers. This gives it a human touch and is way more realistic, than pretending to get everything correct the first time. Thanks! 🙏🏻 😊

  • @kenhaley4
    @kenhaley4 7 ปีที่แล้ว +133

    Dan, I think you left out the most important (and hardest) part of binary trees; namely, keeping the tree balanced. Consider, for example building a tree using the numbers from 1 to 100 in ascending order. The root node would be 1, and there would be 100 nodes none of which would have a left node. Nothing but a linked list. Balancing the tree after each insert avoids this.
    I wouldn't expect you to actually do tree balancing in a quick coding challenge, but I think the task should be mentioned, and should perhaps challenge us, the viewers, to work out how to do it. Or.. make it a coding challenge by itself (?)

    • @_javlm_
      @_javlm_ 5 ปีที่แล้ว +15

      AVL Tree

    • @asubaba123
      @asubaba123 5 ปีที่แล้ว +15

      BST isn't balanced, AVL is

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

      Upvote because I agree, but this is the first I’d learned that a BST can be unbalanced (according to Wikipedia). Not nearly as useful without it.

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

      It's not a AVL tree! Just a binary tree!

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

      Code for balace is ez (8 Lines), problem is run time

  • @kosmic000
    @kosmic000 7 ปีที่แล้ว +54

    ur just amazing dan,,not just a perfect instructor but also a cheerful , kind human being

  • @kolozubix99
    @kolozubix99 7 ปีที่แล้ว +23

    that look of enthusiasm in your eyes at 0:07 is absolutely amazing :D

  • @Tordek
    @Tordek 7 ปีที่แล้ว +26

    The pictures you saw in the image search are perfectly fine: they're pictures of binary trees; that is, trees where each node has up to two children. However, not all binary trees are binary SEARCH trees, which are ordered the way you expect. Had you searched for that instead you'd have gotten the expected results :)

  • @yungrolex1992
    @yungrolex1992 7 ปีที่แล้ว +2

    I hopped on the coding train about two weeks ago and I have been binge watching all of your videos man. You are a great, enthusiastic teacher. I looked you up and saw the Swarm project and was amazed. Thanks for teaching all of us!

  • @steevenpetit-homme5267
    @steevenpetit-homme5267 7 ปีที่แล้ว +1

    I like the fact that I have tried to look for the bug with you,
    but I could not see what's wrong.
    I love this man .
    Thks!

  • @ali_gaming3190
    @ali_gaming3190 7 ปีที่แล้ว +542

    Do a series on data strucrures and algorithms

    • @Xeronimo74
      @Xeronimo74 7 ปีที่แล้ว +65

      please?

    • @akashakya
      @akashakya 6 ปีที่แล้ว +11

      please i beg you shiffman

    • @ritikkhatri
      @ritikkhatri 6 ปีที่แล้ว +5

      PLease!

    • @MrBuckethead911
      @MrBuckethead911 6 ปีที่แล้ว +5

      AMEN TO THAT

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

      It'd be too late, but hell I'd get use of next semester

  • @top1percent424
    @top1percent424 7 ปีที่แล้ว +10

    I love data structures and algorithms; they are so clever ideas and concepts. Love it!

  • @BrianFaure1
    @BrianFaure1 6 ปีที่แล้ว

    Anyone interested in a Python implementation, feel free to check out my recent lesson: th-cam.com/video/f5dU3xoE6ms/w-d-xo.html

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

    the recursion in visit() is dope. Only presentation on binary tree search that I've been able to listen to so far. Keep it up man

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

    Finally, I properly understand the concept of Tree from this video. I always appreciate your teaching and your attitude. You're so much helpful. Thanks for you from my heart!

  • @avatar098
    @avatar098 7 ปีที่แล้ว +73

    To clarify, a Binary SEARCH Tree is what he is implementing.
    A Binary Tree in general is just a tree in which all parents have (at most) two children.
    The difference is that a Binary Search Tree is a special kind of Binary Tree in which the the children will either be to the left of the parent or the right depending on if the child is less than or greater than it's parent. :)

    • @robtvogel
      @robtvogel 7 ปีที่แล้ว +5

      I came to the comments for this. I also believe a binary tree is usually built to remain as closely to balanced as possible.

    • @-._.-KRiS-._.-
      @-._.-KRiS-._.- 3 ปีที่แล้ว +1

      All children should be greater than their parents.

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

      @@robtvogel Same in my case, I was also expecting someone should have pointed this out :D

  • @RM-lw2qi
    @RM-lw2qi 7 ปีที่แล้ว +1

    THANK YOU! You would be the perfect teacher for data structures and algorithms, please do more

  • @DogwafflDan
    @DogwafflDan 6 ปีที่แล้ว

    Thanks for the series on binary trees. We used them to sort images according to similarity. Thanks also for opening object oriented programming for me. 20 years of people telling me it was like dogs and cars didn't do the job. Seeing someone do practical examples made it so clear!

  • @mrsecify
    @mrsecify 6 ปีที่แล้ว

    I just love your enthusiasm and happiness. You are one of a few TH-camrs that actually make me giggle, even though you're not trying to be hilarious. Keep being awesome! Oh and you kind of made me come back to programming. I'm an electrical engineering student myself, but I used to code a lot when I was a kid and all the way through high school, but got burned out. So thanks for making a difference in my life! (:

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

    Let's go over to the whiteboard.
    Immediately leaves the shot of the white board. I can't wait to learn from this man.

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

    Decissions are binary. You can allways resume them as "should i do this or not". Both have consecuencies AND lead to More binary decissiones.

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

    Never understood binary trees until now! This was great!!! Thank you!

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

    Congratulation Mr. Shifman: you've made it! I finally get it about binary trees logic and why it's so useful in sorted algorythm...

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

    Inspired by the phone book example.
    In psychiatric hospital a doctor gave a phone book to a patient. After a week the doctor meets the patient again and asks him about the book.
    The patient answered, the story is not really interesting, but the number of characters is really impressive.
    Great job Dan love your work. Greetings from Geneva Switzerland.

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

    The images you were looking at are " binary tree " which represents data structure tree with max 2 degree of nodes... the structure yoy wanna look for is " binary search tree "

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

    Aliens from the future tell you ES2015 introduced classes in JS.
    I really like the fact that you delegated the Node class to visit() and search() as this seems way more reasonable than putting a bunch of code within Tree class, because in the end Tree is just a wrapper while Node is a meaningful representation of a tree. As weird as it may sound.

  • @DaveAkumu
    @DaveAkumu 7 ปีที่แล้ว +9

    When I was watching one of your videos for the first time I thought: "Who is this crazy guy and why is he so happy all the time?" In all honesty I didn't really like you but then I watched some more of your videos and now I'm subscribed. I like to watch your videos when I'm programming because its really relaxing. Keep up the good work! Really looking forward for more videos. :)

    • @TheCodingTrain
      @TheCodingTrain  7 ปีที่แล้ว +3

      Hah, thanks for the feedback!

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

      @@TheCodingTrain always happy guy😅

  • @brunoandradebr
    @brunoandradebr 7 ปีที่แล้ว

    It's important when implementing pathfinding for games. Find the shortest path to a certain point, for example. great explanation! thanks!

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

    Dude, I really like your bow tie!

  • @paladin1147
    @paladin1147 5 ปีที่แล้ว +2

    This really helps with understanding recurssion more indepth, atleast for me xD. This is awesome. Thank you Mr. Shiffman for this video.

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

    I love his enthusiasm

  • @siba2893
    @siba2893 6 ปีที่แล้ว

    Hey Dan, I love your coding tutorials and coding challenges they actually teach a lot. But I believe you left a really important thing outside this binary trees and thats Balancing the trees.

  • @foolishsamurai
    @foolishsamurai 7 ปีที่แล้ว +237

    I want to know where u buy ur adrenaline from :)))))

    • @phuong7357
      @phuong7357 5 ปีที่แล้ว +31

      @@thcoura You must have a really sad life then.

    • @cxT9344
      @cxT9344 5 ปีที่แล้ว +14

      It is called passion

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

      from Alien in the future

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

      Local crack dealer

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

      Yeah this video really needs some editing because it seems he doesn't know what he's talking about (but he does). Overall a good explaination though.

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

    I had to a CS assignment that does math with a binary tree, with number leaves and operator inner nodes. By the way, you don’t need a tree type. When you add a node, if the root is null, you set it to the node, otherwise you recurse to the left or to the right.

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

    Always cool to learn from a good teacher AND from his mistakes^^

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

    Instructions Unclear:
    Created a book made of phones

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

    I like how the BST you randomly made just happened to be balanced. That is, there is no node such that |depth right - depth left| > 1

  • @NinjaKyou
    @NinjaKyou 7 ปีที่แล้ว +181

    Can you do a series on data structures an algorithms?

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

      sorry, What?!!

    • @user-vx1wt4hb5l
      @user-vx1wt4hb5l 4 ปีที่แล้ว

      @@andachain Lol idk either

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

      your name

    • @user-vx1wt4hb5l
      @user-vx1wt4hb5l 4 ปีที่แล้ว

      @@Tuberex What's wrong with my name?

    • @user-vx1wt4hb5l
      @user-vx1wt4hb5l 4 ปีที่แล้ว

      jk im not whoosh bait

  • @loganmahoney2284
    @loganmahoney2284 5 ปีที่แล้ว

    You're like the Bob Villa of programming and I love it

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

    I'm learning C, and this is in JS which I don't know at all. But I understand clearly what he is doing. Also from his videos I started to understand what is OOP!

  • @leeritenour
    @leeritenour 6 ปีที่แล้ว

    Your videos are educational and joyful. Thank you for the lectures.

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

    A series or a video on coding a simple Gerrymandering Algorithm would be amazing!

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

    Why not use a Linter to avoid all those small bugs? Anyway, thank you for your effort.
    PS: you can use "comma" in console log: `console.log('Found', someObject);`

  • @nackyding
    @nackyding 6 ปีที่แล้ว

    Thank you! Excellent! Looking forward to part 2. Thanks again. You teach/explain really well. Can you please do a complete series on data structures and algorithms?

  • @amdreallyfast
    @amdreallyfast 6 ปีที่แล้ว

    I've used a variation on binary trees for collision handling. They have their uses :).
    In early August I finished an ~1.5yr long project for a rough visualization of several thousand particles colliding in real time. It used compute shaders on my graphics card and handled large-scale collisions in O(log(n)) time through a variation of a binary tree called a "bounding volume hierarchy". It was rather cool (after I managed to dig through the academic papers with the algorithms).

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

    The traversal method he is using is the "In order" transversal, which will return the numbers sorted. You can also do a "pre order", "post order", and level order. :)

  • @minecraftermad
    @minecraftermad 5 ปีที่แล้ว

    This can be used for datapacking if instead of smaller or larger numbers use the commodity of the item and the more common it is the higher it is now 1 or 0 will be left or right and boom most efficient datapacking without a separate library

  • @lewisshemery2585
    @lewisshemery2585 7 ปีที่แล้ว

    This what I need!
    I have code that uses A* to solve 8-puzzle. It uses java's built in priority queue to hold node successors and a comparator to keep them sorted. I want to try and write something like that on my own and this seems like a great way to do it!

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

    you make binary search looks easy thankyou so much sir!!!

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

    It's better explained than I ever heard, and I'm kinda happy you struggle yourself at times. No offense, it just makes me feel a bit less stupid.

  • @rozarasinvestments880
    @rozarasinvestments880 6 ปีที่แล้ว

    I love this guy! Better to be entertaining and unpolished

  • @benjaminphilippe2810
    @benjaminphilippe2810 7 ปีที่แล้ว +19

    I know what a phone book is! It's a book full of phones (DUH!). So when you need a new phone, just find in in the phone book! (right?)

    • @xynyde0
      @xynyde0 6 ปีที่แล้ว

      😅

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

      your stupid phone book is a book that contains photos of every phones you cant just pull them out!

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

      @@Tuberex r/woooosh

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

    This was a funny parody of a newbie programmer implementing their first BST. I'm surprised you didn't put it out on April 1st of that year.

  • @ridespirals
    @ridespirals 6 ปีที่แล้ว

    you can pass as many arguments to console log as you want, it'll even put spaces between strings for you and print objects nicely

  • @leeritenour
    @leeritenour 6 ปีที่แล้ว

    An excellent mistake at the end that brings up a very good practice: maintain reliable returns for recursive function calls. Thank you for the lesson!

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

    At 5:40 was anyone else shouting at the screen, "you have a whole book of random numbers right there!!"

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

    I had a lot of fun doing this in college using Pascal on SunOS 3.x.

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

    "Insert one direction music" - i know i have the right idol. More power to you, Dan!

  • @anteconfig5391
    @anteconfig5391 5 ปีที่แล้ว

    I love learning new algorithms.

  • @chungyunlee3832
    @chungyunlee3832 7 ปีที่แล้ว

    Really like the way you talk about programming : )

  • @Egli
    @Egli 6 ปีที่แล้ว

    Duuuuuuuuude u are amazing!!!! Love your work first time ive seeen any of your videos and incan already tell ur an amazing teacher!!

  • @adomasz.3958
    @adomasz.3958 7 ปีที่แล้ว

    I don't know why I love this video so much :D

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

    Please Coding challenge: how to draw binary tree (or ternary or other subtypes), and how to draw graph! It would be amazing learn how it visually looks like graphs and trees. I love your videos (: A viewer from Cancun, Mexico.

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

    Hi, very cool videos it's an awesome way to learn interesting programming concepts.
    On the topic of tree structures I was wondering if you could do a video on a QuadTree implementation to show spacial distribution.
    I'm using QuadTrees on procedural planet generations in games and found it very challenging but interesting.
    Thanks !

    • @TheCodingTrain
      @TheCodingTrain  6 ปีที่แล้ว +2

      Please suggest or upvote here! github.com/CodingTrain/Rainbow-Topics/issues I definitely want to tackle this.

  • @NocturnalCoder
    @NocturnalCoder 5 ปีที่แล้ว

    The first time some ancient video mentions a proper explanation of phone book and phone number!

  • @alekmoth
    @alekmoth 7 ปีที่แล้ว +14

    UP ARROW to repeat commands in the console!!

    • @Kitulous
      @Kitulous 6 ปีที่แล้ว

      alekmoth 36:51 he knows, right? He didn't use that because the numbers are different each time.

    • @Kitulous
      @Kitulous 5 ปีที่แล้ว

      omg I didn't even know I watched that video 11 months ago!

  • @charbelsarkis3567
    @charbelsarkis3567 7 ปีที่แล้ว +3

    it's hilarious how he speaks to us like we're waaaay in the future

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

    OMG, I'm telling at the screen "you have to return the result!!!"

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

    Love you Daniel ❤️

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

    Why do we need to return the function calls in the search function? I don't understand.

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

      from my understanding (hope this make sense lol also I could be completely wrong) every time a value is returned it is returned to whatever directly called it. You can't make indirect returns
      so the solution to returning indirect values is to return the value to its previous call in a chain until its returned to the direct function initialization.
      So when the search function is initially called it checks its value to the root value and if they are the same then THAT value/node is returned
      if not then the value is returned at the node it is found but not to the initial function call instead its returned to the previous one and then that value is returned to the previous one before that and so on but it will never be returned in the console because the final return to the initial call doesn't exist
      as you can probably tell this chain of returns did take place but never completed to the first call which is why he needed the return calls in the "this.left.search(val)" and the "this.right.search(val)' to make the final return call to the variable found in the "tree.prototype.search"
      hope that made sense!

  • @sinyolinuxozy
    @sinyolinuxozy 7 ปีที่แล้ว +2

    Nice explanation sir, do a data structures and algorithms series, please :)

  • @artificialhuman3260
    @artificialhuman3260 6 ปีที่แล้ว

    i love this man so much

  • @ArvindhMani
    @ArvindhMani 7 ปีที่แล้ว +5

    Every time i hear "ting" I laugh like a little kid. LOL!

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

    Holy crap, Grokking Algorithims is awesome!

    • @evieeve1571
      @evieeve1571 7 ปีที่แล้ว

      Guilherme Marthe is it free?

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

    I do have a problem. I need to sort numbers as follows: Let's say there are 10 numbers (322, 456, 423, 412, 513, 123, 432, 321, 254, 253), now I need to kind of "fit" these into another fixed number like 1100. So whatever combination of these 10 numbers comes close as possible to 1100 (could be less but not more) should get selected. Furthermore it can't be more than 4 numbers in one combination. This loop should be running until all numbers are chosen and combined. How could I get this done. Maybe there is already a video out there.

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

    This teacher would be fun to smoke weed with and walk through a mall

  • @cadenricker7475
    @cadenricker7475 6 ปีที่แล้ว

    Yo Daniel try only using one return statement and just assign a variable to what you want to return and return the variable it will make your code simpler and easier to debug and update.

  • @grmmhp
    @grmmhp 7 ปีที่แล้ว

    you have no idea how much you help me :)

  • @Texplanations
    @Texplanations 7 ปีที่แล้ว

    Hey dan! Here's a quick Idea.... Cutout the word rain from paper and then stick it on top of your bow.... It'll be good :3

  • @hamzam9625
    @hamzam9625 6 ปีที่แล้ว

    you are a life saver Sir

  • @heksqer1022
    @heksqer1022 5 ปีที่แล้ว

    Great vid as always Dan !

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

    I was confused about prototype, but now I have translated the binary tree search from your code to python I see it is basically a function inside a class (in python terms anyway).
    I'm still new to coding in general so hopefully someone will correct me if I'm wrong.

  • @zakirsobirov6926
    @zakirsobirov6926 7 ปีที่แล้ว

    Great video! But Can I ask you something? In the next video, are going to only show how it works or you also explain where it used, advantages and disadvantages (like tree degradation if you add sorted sequence)?

  • @timurabdurasulov7442
    @timurabdurasulov7442 7 ปีที่แล้ว

    Really awesome video. I like how you explain all these stuff

  • @jan_harald
    @jan_harald 7 ปีที่แล้ว

    that's so easy and common that I'm 16 and I've already seen that about 5 times and I'm not even doing anything related to it..,not doing anything at all, actually, but kinda learning programming...
    I love phone books and Compact Disks

  • @zid3
    @zid3 5 ปีที่แล้ว

    A little late to the party but thank you for making this video, it helped a lot more than these academic books hah. Into my second year and just started algorithms and data structures, very interesting but mind numbing at times 😊. This video was fun to watch and helped me understand binary search trees. Thank you!

  • @christiantith2843
    @christiantith2843 5 ปีที่แล้ว

    Bill Nye of CS vibe , I dig it

  • @top1percent424
    @top1percent424 7 ปีที่แล้ว +10

    16:10 you were looking at binary trees but you were actually talking about binary search trees. In BSTs, values are stored like the way you explained but binary trees just store values with no special order.

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

      this guy doesnt know what he is doing , lol

    • @top1percent424
      @top1percent424 7 ปีที่แล้ว +3

      sarvagya agarwal I wouldn't say that. Anyone can easily get confused during coding sessions like these. Also, if you haven't then go check out his other videos, he knows his shit.

    • @sarvagyaagarwal2823
      @sarvagyaagarwal2823 7 ปีที่แล้ว

      Oh i know , it just seems like he has forgotten the basics , i mean data structures and algorithms is the first course they teach you in computer science .

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

      And its also what you forget first ;)

    • @DuhBroadcaster
      @DuhBroadcaster 7 ปีที่แล้ว

      What's the point in having a binary tree if it isn't capable of binary search? That doesn't make sense.

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

    the presentation so colorful, guess you are from the unicorn tribe!

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

    I chuckled at the node.js one hahaha

  • @paulfarcas4522
    @paulfarcas4522 7 ปีที่แล้ว +3

    how did you get that select bar in the google search with different programming languages?

  • @matterno
    @matterno 7 ปีที่แล้ว

    I used to code like this back in the student days...
    Nowadays I am developing test driven and produce more reliable code.

  • @chrisw3260
    @chrisw3260 7 ปีที่แล้ว

    First of all, great video, absolutely love your enthusiam!!
    I'm having issues understanding the visit()-function though, to a point where
    it is driving me crazy, maybe someone can enlighten me. Here's how i
    understood the code:
    Taking Dans first tree with the numbers 3,5,6,7, 5 would be the root, 3 & 7 to the left
    and right of 5 and 6 to the left of 7.
    Now tree.traverse() is called, which itself calles the visit()-function on the root-node
    with the value of 5.
    visit() then checks, if a left node is present (which it is, with value 3), calls itself
    again on the node with value 3 (executing this.left.visit()) and checks, whether THIS node
    has another node present to the left, which is NOT the case, so it skips the first if-statement
    and prints the value 3.
    Following the code, the second if-statement is skipped, because there is also no right node
    (this.right != null is false).
    At this point, i would assume, the visit()-function is at its end, how are the
    following nodes visited? Somehow the code must jump to the node containing the value 5
    and then to the ones with 6 and 7, to print them all in order, but i just don't get how.
    Somewhere, my explanation must be horribly wrong.. Any explanation is highly appreciated.

    • @sreeramchittela399
      @sreeramchittela399 6 ปีที่แล้ว

      It's a recursive call dude. it uses stack. So, when it doesn't meet any relevant condition, then it goes back to the previous node.

  • @midnightrizer
    @midnightrizer 5 ปีที่แล้ว

    Can this be used with an Expert System and Rules Structure to teach the computer by giving more and more detail but instead of a Node concept it would be frames Following Marvin Minsky's Idea of Frames and Agents?

  • @Mariovg99
    @Mariovg99 5 ปีที่แล้ว

    You dont need a datatype Node, its easier to assume a BS Tree as a root with a left and right BS Trees, which is the mathemathical definition.

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

    Saw this topic and immediately shivered lol. Not my favorite part of data structures...

  • @rob2theworld
    @rob2theworld 6 ปีที่แล้ว

    Very good job dude!! I just bought that book to

  • @geoffwagner4935
    @geoffwagner4935 10 หลายเดือนก่อน

    wow, i'm pretty sure this is how i failed my a.d.d. test when i was younger, never stopped pushing the button. crazy person test fail # 2

  • @critstixdarkspear5375
    @critstixdarkspear5375 5 ปีที่แล้ว

    All praise this.

  • @olabodeebiniyi7939
    @olabodeebiniyi7939 6 หลายเดือนก่อน

    Thank You for this, I have a question, how can you achieve it, using only HTML, CSS and Javascript?

  • @ThePikachu00200
    @ThePikachu00200 7 ปีที่แล้ว

    In the next video you should also add a function to remove a node! I recently had to implement my own binary search tree for a class and removing can be quite difficult in java, I would like to see if it is just as hard in JavaScript.

  • @kayu971
    @kayu971 6 ปีที่แล้ว

    Hi, could you explain visit function? How would it visit up after we print smallest value because current value will not have right value , jump right visit check and finish the program.