Тёмный

Coding Challenge #65.1: Binary Search Tree 

The Coding Train
Подписаться 1,7 млн
Просмотров 354 тыс.
50% 1

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 401   
@adamoja4295
@adamoja4295 2 года назад
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.
@kosmic000
@kosmic000 7 лет назад
ur just amazing dan,,not just a perfect instructor but also a cheerful , kind human being
@kenhaley4
@kenhaley4 7 лет назад
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 лет назад
AVL Tree
@asubaba123
@asubaba123 5 лет назад
BST isn't balanced, AVL is
@JackFlashTech
@JackFlashTech 4 года назад
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 года назад
It's not a AVL tree! Just a binary tree!
@TTaiiLs
@TTaiiLs 4 года назад
Code for balace is ez (8 Lines), problem is run time
@ali_gaming3190
@ali_gaming3190 7 лет назад
Do a series on data strucrures and algorithms
@Xeronimo74
@Xeronimo74 7 лет назад
please?
@akashakya
@akashakya 6 лет назад
please i beg you shiffman
@ritikkhatri
@ritikkhatri 6 лет назад
PLease!
@MrBuckethead911
@MrBuckethead911 6 лет назад
AMEN TO THAT
@alexi1182
@alexi1182 6 лет назад
It'd be too late, but hell I'd get use of next semester
@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!
@Tordek
@Tordek 7 лет назад
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 :)
@jorgegranada4964
@jorgegranada4964 5 лет назад
Decissions are binary. You can allways resume them as "should i do this or not". Both have consecuencies AND lead to More binary decissiones.
@rushishah8659
@rushishah8659 7 лет назад
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 "
@NinjaKyou
@NinjaKyou 7 лет назад
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 года назад
your name
@user-vx1wt4hb5l
@user-vx1wt4hb5l 4 года назад
@@Tuberex What's wrong with my name?
@user-vx1wt4hb5l
@user-vx1wt4hb5l 4 года назад
jk im not whoosh bait
@corey333p
@corey333p 4 года назад
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
@avatar098
@avatar098 7 лет назад
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 лет назад
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 года назад
All children should be greater than their parents.
@EduAnmoldeep
@EduAnmoldeep 3 года назад
@@robtvogel Same in my case, I was also expecting someone should have pointed this out :D
@kolozubix99
@kolozubix99 7 лет назад
that look of enthusiasm in your eyes at 0:07 is absolutely amazing :D
@foolishsamurai
@foolishsamurai 7 лет назад
I want to know where u buy ur adrenaline from :)))))
@phuong7357
@phuong7357 5 лет назад
@@thcoura You must have a really sad life then.
@cxT9344
@cxT9344 5 лет назад
It is called passion
@manamibhunia7125
@manamibhunia7125 5 лет назад
from Alien in the future
@HettyPatel
@HettyPatel 4 года назад
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.
@benjaminphilippe2810
@benjaminphilippe2810 7 лет назад
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 года назад
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
@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
@mohammedabahussain4562
@mohammedabahussain4562 4 года назад
Dude, I really like your bow tie!
@paclion9345
@paclion9345 7 лет назад
Wow this channel is amazing, just discovered it
@TheCodingTrain
@TheCodingTrain 7 лет назад
Welcome!
@top1percent424
@top1percent424 7 лет назад
I love data structures and algorithms; they are so clever ideas and concepts. Love it!
@FredoCorleone
@FredoCorleone 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.
@nightcoder5k
@nightcoder5k Год назад
I had a lot of fun doing this in college using Pascal on SunOS 3.x.
@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.
@PedroPauloAlmeida0
@PedroPauloAlmeida0 4 года назад
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);`
@realcygnus
@realcygnus 7 лет назад
omg.....some actual computer science 101 / software engineering topics ......how exciting !
@anteconfig5391
@anteconfig5391 5 лет назад
I love learning new algorithms.
@alekmoth
@alekmoth 7 лет назад
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!
@ProBloggerWorld
@ProBloggerWorld Год назад
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! 🙏🏻 😊
@SurrealBackrooms
@SurrealBackrooms 3 года назад
Instructions Unclear: Created a book made of phones
@wyattelliott5200
@wyattelliott5200 6 лет назад
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
@timurabdurasulov7442
@timurabdurasulov7442 7 лет назад
Really awesome video. I like how you explain all these stuff
@vision6D
@vision6D 7 лет назад
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.
@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
@top1percent424
@top1percent424 7 лет назад
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 лет назад
this guy doesnt know what he is doing , lol
@top1percent424
@top1percent424 7 лет назад
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 лет назад
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.
@rob2theworld
@rob2theworld 6 лет назад
Very good job dude!! I just bought that book to
@vontrae
@vontrae 3 года назад
I chuckled at the node.js one hahaha
@micky2be
@micky2be 4 года назад
OMG, I'm telling at the screen "you have to return the result!!!"
@ArvindhMani
@ArvindhMani 7 лет назад
Every time i hear "ting" I laugh like a little kid. LOL!
@yungrolex1992
@yungrolex1992 7 лет назад
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!
@MikeMcRoberts
@MikeMcRoberts 7 лет назад
I challenge you to create a star map based on real star coordinates, converting RA & DEC coordinates to screen coordinates.
@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 года назад
This teacher would be fun to smoke weed with and walk through a mall
@LuisCarlos-zv1wi
@LuisCarlos-zv1wi 5 лет назад
i am from the future, i had to research what a phone is.
@euklidian-space
@euklidian-space 7 лет назад
Watching you struggle through tree algorithms is endless entertainment
@Texplanations
@Texplanations 7 лет назад
32:30 When you solve a 4 page math problem and the solution is 0 :V
@sinyolinuxozy
@sinyolinuxozy 7 лет назад
Nice explanation sir, do a data structures and algorithms series, please :)
@paladin1147
@paladin1147 5 лет назад
This really helps with understanding recurssion more indepth, atleast for me xD. This is awesome. Thank you Mr. Shiffman for this video.
@conwear2544
@conwear2544 7 лет назад
Why do we need to return the function calls in the search function? I don't understand.
@3liflo
@3liflo 7 лет назад
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!
@hortsss
@hortsss 5 лет назад
Amazing! You make me wanna learn js
@charbelsarkis3567
@charbelsarkis3567 7 лет назад
it's hilarious how he speaks to us like we're waaaay in the future
@wesleyjanse6600
@wesleyjanse6600 6 лет назад
very interesting video, love how good you explained it
@Brauhlio
@Brauhlio 5 лет назад
it´s very easy when you give the values to be printed, but for input, delete, or search the node values from a scanned screen is hard to me.
@Eresea
@Eresea 6 лет назад
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 лет назад
Please suggest or upvote here! github.com/CodingTrain/Rainbow-Topics/issues I definitely want to tackle this.
@folkusonme
@folkusonme 2 года назад
omg the bowtieeeee 🥺
@steevenpetit-homme5267
@steevenpetit-homme5267 7 лет назад
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!
@DaveAkumu
@DaveAkumu 7 лет назад
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 лет назад
Hah, thanks for the feedback!
@simon13751
@simon13751 3 года назад
@@TheCodingTrain always happy guy😅
@christoffaloffagus9713
@christoffaloffagus9713 7 лет назад
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.
@WhisperVT
@WhisperVT 7 лет назад
Saw this topic and immediately shivered lol. Not my favorite part of data structures...
@MrBidalos
@MrBidalos 7 лет назад
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!
@victormagalhaes2821
@victormagalhaes2821 7 лет назад
Daniel, do you have a presencial course? regards from Brazil
@elijahlucian
@elijahlucian 5 лет назад
This is like pair programming but with hundreds of people. Horde programming
@eduardohidalgo5260
@eduardohidalgo5260 7 лет назад
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.
@LamezLames
@LamezLames 7 лет назад
You are teaching binary search trees, which is a type of binary tree. I'm sure if you google "binary search trees" the images will display a sorted tree.
@Holobrine
@Holobrine 5 лет назад
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.
@WindImHaar
@WindImHaar 7 лет назад
Hey Daniel, i just started programming a couple of days ago and now I'm wondering which programming language/ environment to learn first. I absolutely love the coding challenges which are mostly done in p5js which I'm feeling more comfortable with atm but I'm planning to read your book and it is all about processing. I'd like to get good with one of the languages and transitioning between them shouldn't be too hard then but which one do you recommend for starting off? Please keep on doing what you are doing, mfg.
@TheCodingTrain
@TheCodingTrain 7 лет назад
Oh, this is such a hard question! It really doesn't have an answer. Does one appeal to you more for one reason or another? If you care about having your stuff on the web then I would say JS, if not then maybe try Processing? I don't know!
@WindImHaar
@WindImHaar 7 лет назад
Yes it is such a hard question, I think I may just try to learn them both at once because I can't decide :D
@sunday-thequant8477
@sunday-thequant8477 2 года назад
Hey Shiffman i have a new coding challenge for you, two words: Symbolic Regressor.
@pucbg2902
@pucbg2902 5 лет назад
Sir Will you please START JS WITH UNITY because I love your teaching skill and programming skill. When Sir you will start unity there will new world appearing
@km-sc4kz
@km-sc4kz 2 года назад
Thanks
@TheCodingTrain
@TheCodingTrain 2 года назад
Thank you for the support!
@paulfarcas4522
@paulfarcas4522 7 лет назад
how did you get that select bar in the google search with different programming languages?
@linashamoon9414
@linashamoon9414 4 года назад
Never understood binary trees until now! This was great!!! Thank you!
@asddsaasdfg2846
@asddsaasdfg2846 4 года назад
Is he changed his ding bell
@jjfattz
@jjfattz 7 лет назад
I think we should name the chat to "Debug Chat"
@paulgirard3093
@paulgirard3093 7 лет назад
Always cool to learn from a good teacher AND from his mistakes^^
@Mezklador
@Mezklador 7 лет назад
Congratulation Mr. Shifman: you've made it! I finally get it about binary trees logic and why it's so useful in sorted algorythm...
@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?
@matthewsnell3789
@matthewsnell3789 7 лет назад
A series or a video on coding a simple Gerrymandering Algorithm would be amazing!
@alfathmuqoddas6986
@alfathmuqoddas6986 2 года назад
I really like your energy man, i wonder what kind of drugs you use lol, jk keep up the good work man!
@MINHHOANG-hl7gp
@MINHHOANG-hl7gp 7 лет назад
you should write books about these, i'll fuckin' buy them
@RM-lw2qi
@RM-lw2qi 7 лет назад
THANK YOU! You would be the perfect teacher for data structures and algorithms, please do more
@Brahvim
@Brahvim 3 года назад
OOH! Here's how to pronounce it (:rofl:, please *don't* waste your time here! xD) Aa-thi- (It is like a mixture of 'd' and 'th'; STRESS a 'th' sound.) -thya- (This one is your normal 'th' sound.) 'Y.' (The letter 'Y') Bhar- (It's pronounced more like "Bh-aaar" with a stretched 'aah' sound.) -gava. (Just like 'guava' but without the 'u', of course!) "Aa-thi-thya Y. Bhar-gava" That's the name! Yep, "Hindi" (The official language here in India. 'd' here has a little bit of the 'th' again ;] ) ..is hard to pronounce for anyone who is not Indian, I agree. Hopefully this wasted everyone's time, ( _then why did I do this!? :rofl:_ ) ..but taught you some pronunciation skills, I would like to imagine? ...aaaaaaand although I am pretty sure everyone did, you probably know that ":rofl:" is a reference to this emoji: "🤣". Ok-uh....before I waste more of your time...I'm outta here :/ v-v-v-v-b-bYE! :D!
@olabodeebiniyi7939
@olabodeebiniyi7939 6 месяцев назад
Thank You for this, I have a question, how can you achieve it, using only HTML, CSS and Javascript?
@tevindavid1185
@tevindavid1185 Год назад
is anyone getting the problem:Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'value') and how did you go about it
@Sanyat100
@Sanyat100 3 года назад
It's 2022, and I don't know what a phone book is
@kaledbrahmi3442
@kaledbrahmi3442 3 года назад
Boomer stuff
@haowie8400
@haowie8400 7 лет назад
Which program do u use? btw i have a windows and now a mac
@gui1542
@gui1542 7 лет назад
Holy crap, Grokking Algorithims is awesome!
@evieeve1571
@evieeve1571 7 лет назад
Guilherme Marthe is it free?
@idkwhatshouldiputhere7395
@idkwhatshouldiputhere7395 Год назад
:| REDO THE VIDEO I cant follow anything!!!! you change stuff and then don't explain it!!
@rowlandekemezie
@rowlandekemezie 6 лет назад
Dan, I'm curious how we can add a value that's equal to the node to the tree
@wwt17
@wwt17 2 года назад
It's probably cos I know little about coding, but watching this guy do his thing (he obviously knows what he's doing) is like watching a schizophrenic converse with himself.
@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
@geoffwagner4935
@geoffwagner4935 10 месяцев назад
that chat can't debug everything you know, unfortunately can do nothing for crazy. unless fun fun function gets in their, he got ahead of the crazy curve, a little. some may say he could be little "late to the chat too"
@BrianFaure1
@BrianFaure1 6 лет назад
Anyone interested in a Python implementation, feel free to check out my recent lesson: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-f5dU3xoE6ms.html
@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.
@JumpCatStudio102
@JumpCatStudio102 6 лет назад
This is my c# translation of this BST challenge incase anyone needs it: github.com/TrongHieu90/Intelligence-AI-and-ML/tree/master/BinaryTree
@GRAHAMAUS
@GRAHAMAUS 4 года назад
anyone else screaming at their computer about the missing returns? Fuckkkk........
@utpalbandyopadhyay1633
@utpalbandyopadhyay1633 4 года назад
Dan has thought about the far future....☺️☺️
@A_Lesser_Man
@A_Lesser_Man 4 года назад
wow. in Node.prototype.visit ... why does the console.log have to be where it is? moving to top or bottom of function wrecks the order of output...
@mmaranta785
@mmaranta785 3 года назад
I know what a phone book is. In the 1980’s I found a surviving member of the 1927 Yankees and called him.
@DroidTsuenik9
@DroidTsuenik9 5 лет назад
16:00 You are looking at normal binary trees which is why they are not sorted. You should have googled "Binary Search Trees"
@edwinfeliz5487
@edwinfeliz5487 3 года назад
whats tree.prototype.addNode doing is creating a Node such as Struct Node { Struct Node *p}
@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.
@RedEyedJedi
@RedEyedJedi 4 года назад
You should use the extension Quokka.js, you will be able to catch all these little errors like forgetting this. as they happen then.
@robertphillips124714
@robertphillips124714 2 года назад
At 5:40 was anyone else shouting at the screen, "you have a whole book of random numbers right there!!"
Далее
Coding Challenge #65.2: Visualizing a Binary Tree
8:53
Coding Challenge #68: Breadth-First Search Part 1
21:19
iPhone 16 & beats 📦
00:30
Просмотров 64 тыс.
Coding Challenge #145: 2D Raycasting
36:02
Просмотров 641 тыс.
Coding Challenge 93: Double Pendulum
31:11
Просмотров 919 тыс.
Coding Challenge #143: Quicksort Visualization
30:06
Просмотров 247 тыс.
Coding Challenge 181: Weighted Voronoi Stippling
28:59
Просмотров 167 тыс.
Coding Challenge 180: Falling Sand
23:00
Просмотров 944 тыс.
Coding Challenge #64.2: Inverse Kinematics
36:45
Просмотров 403 тыс.
Coding Challenge 124: Flocking Simulation
42:27
Просмотров 332 тыс.