50 min lecture material wrapped in a 7 min video. Honestly amazing!
@yashagarwal82498 ай бұрын
In 6 and a half minutes, you managed to teach me the fundamentals of something I thought would take a lot of time. Amazing, thank you!
@wonton10193 жыл бұрын
This is the greatest visualization of nearest neighbors I've ever seen. You sir, are a blessing beyond words, I'm not religious but I might as well be after watching your video. Thank you.
@stablesort3 жыл бұрын
Thanks for such a great compliment! I am happy to hear that the video resonated with you so much!
@SauravSahu012 жыл бұрын
Same here. I have never seen such teacher. He is GOD level.
@arnavanuj3 жыл бұрын
One of the most useful searching algo in data science
@stablesort3 жыл бұрын
Definitely a good one to know. I have seen it pop up in interviews as well.
@maridavies34254 жыл бұрын
Awesome tutorial on KDtree data structure! The nearest neighbor search algorithm is easy to follow here. Thanks, keep em coming!
@stablesort4 жыл бұрын
Thanks for the compliment! More tutorials are on the way =)
@Aca991002 жыл бұрын
This tutorial was very precise, direct and comprehensive and it really helped me understand how to use kd trees. Thank you so much sir!
@stablesort2 жыл бұрын
You are very welcome!
@1230986666 Жыл бұрын
This video hits all the right notes: short, useful and clear. Keep up the excellent work!
@maxinteltech33213 жыл бұрын
Great visualization of a complex concept
@mukulbhave2 жыл бұрын
simple ,short and precise. Awesome
@omarshawky58592 жыл бұрын
I came to you from 2 independent great courses not understanding a specific scenario where they ignore an entire section without clarifying the reason but you explained it extremely better than both; Well done! Thank you :)
@stablesort2 жыл бұрын
thanks for leaving a few good words!
@NoName-ip4tt2 жыл бұрын
This is an interview question. How to design an algorithm for a flight computer to find closest airport during the flight in an emergency? Well explained along with lucid diagrams... Thanks for sharing your knowledge...
@familytamelo81404 жыл бұрын
Concise and yet very informative. Enjoyed. Thanks!
@stablesort4 жыл бұрын
Thanks for the compliment! Glad to know that it was helpful.
@papayasprout3 жыл бұрын
This cleared up k-d Trees for me. Thanks for putting up the video.
@zafirr14 жыл бұрын
Nice explanation, I have a question though. Since this is not a balanced binary search tree, the worse case is still O(n) right? Or is there a way to use balancing techniques (like in a treap) with kd trees?
@stablesort4 жыл бұрын
Excellent question and you are right on the money - KD-Tree has the potential to be heavily unbalanced, which results in O(n) search. The simplest approach to ensure a balanced (statistically speaking) tree that I could think of, in the case where all of the points are specified at the start, is to just shuffle the points before constructing the tree. But there are more sophisticated techniques that pick a good median value on each insertion. Also check out KDB-Trees (en.wikipedia.org/wiki/K-D-B-tree) they are balanced by design. Alternatively, if you have lots of inserts and deletes to a KD Tree, you could keep track of the number of such operations and then just rebuild the whole tree after some threshold. I am curious if there are better approaches - let me know what you find!
@ChrisOffner3 жыл бұрын
Fantastic explanation and visualisation, thank you so much! :)
@stablesort3 жыл бұрын
Thanks for leaving a compliment!
@卡机不4 жыл бұрын
Wow !new episode updated , i already cannot wait to learn it!thank you so much .
@stablesort4 жыл бұрын
=) I hope you liked it!
@dainel14902 жыл бұрын
Thank you, I think it solved my problems with making kd-tree and searching it.
@omnamahshivaya20543 жыл бұрын
Your code saved me.
@stablesort3 жыл бұрын
Good to hear it!
@br3nto7 ай бұрын
How does this compare to quad-trees? I’ve always wondered why they chose 4 partitions instead of 2. KD-trees seem the closest to this idea, but still a bit different.
@StopHackingMe-mm3bk Жыл бұрын
Thanks for this video. Could we adapt the algorithm to not get only the closest point but rather all points under a certain distance ?
@Fanaindel3 Жыл бұрын
+++
@FlorinGN4 ай бұрын
Really nice explanation, thank you!
@yeetgod50633 жыл бұрын
I love this channel please upload more
@stablesort3 жыл бұрын
Thank you
@KingGJT Жыл бұрын
Great video! Thank you for making math visible :)
@br3nto7 ай бұрын
Nice vid and nice animation! Short and digestible😃
@pietertjeboersma65863 жыл бұрын
Thanks for your clear explanation!
@stablesort3 жыл бұрын
Glad you liked it! Cheers!
@mohammadyahya78 Жыл бұрын
Amazing tutorial. Why the point (2, 6) splits the space into up and bottom and not left and right as the root node (5, 4) did please?
@oren22343 жыл бұрын
so if this was a 3D tree we would have to check potentially all 4 quadrants the neighbour might be in ? and if i had a 10D tree I would have to check 2^9 quadrants ?
@stablesort3 жыл бұрын
Good question. The tree nodes still have only two child nodes, even if you have 10 properties per node. Take a look at the source code - the distSquared(point0, point1) uses all properties (3, 10, whatever) but since there are only two child nodes, the plane is always split into just two. I hope this answers your question but let me know if I can clarify further.
@hanesburger84702 жыл бұрын
Thank you from UC Berkeley!
@TranCao-w8r4 ай бұрын
how come the point (13,3) is closer to (9,4) than (8,7)? and because of that we never traverse to the point (10,2), why does this happen?
@wouttengrootenhuysen51372 жыл бұрын
Thank you very much for making this video !
@volodymyrhavrylov79933 жыл бұрын
Nice and clear explanation, thanks!
@stablesort3 жыл бұрын
Thanks for the compliment! Cheers!
@pawankumarpandit1822 Жыл бұрын
thaks dear i cant believe that what a amazing way to explanation it is a kind of unblievable again thank you sir and a lot of love
@vctorroferz2 жыл бұрын
just an amazing explanation! thanks so much!
@sensiblerazor96663 жыл бұрын
Can you make a video on R-Trees and Multi-Dimensional Indexes?
@stablesort3 жыл бұрын
That's a great topic and it'd definitely fit with the current discussion of KD-Trees. Thanks for suggesting it - adding it to the list!
@panoramibyneel3 жыл бұрын
Did you notice the corn cob in a plastic pot? Some parsley would have worked better. Great video btw
@stablesort3 жыл бұрын
I'll try parsley in my next video =)
@Nick-qd5my3 жыл бұрын
Great explaination. Took my prof 1h and not even half as clear
@stablesort3 жыл бұрын
8-) Thanks!
@АртемСиробаба3 жыл бұрын
Thank you for great explanation !
@stablesort3 жыл бұрын
You are very welcome!
@anshumansharma67583 жыл бұрын
Amazing explanation!!!
@stablesort3 жыл бұрын
Thanks for the compliment! Glad to hear that you enjoyed it!
@jcasteld Жыл бұрын
Hi. Your videos are great. Do you have any other new channel or web page to follow you? Thanks.
@alexanderhess77424 жыл бұрын
Great video. Especially due to explaining r'.
@stablesort4 жыл бұрын
Thanks for the compliment! Yeah, the radius concept is the tricky part.
@sensiblerazor96663 жыл бұрын
Nice explanation. Thanks!
@stablesort3 жыл бұрын
Cheers!
@joshyatharva4 жыл бұрын
Awesome!❤️ Can you please make videos on B and B+ trees?
@stablesort4 жыл бұрын
Thanks for the compliment and a great suggestion. I'll add B and B+ trees to the "to do" list =)
@balu.923 жыл бұрын
Excellent lesson! Thank you!
@stablesort3 жыл бұрын
Thanks!
@AbJadzera3 жыл бұрын
Great video, thank you for doing it!!
@stablesort3 жыл бұрын
Thanks! I am glad to hear it!
@vijaynegi3102 жыл бұрын
Great explanation !! thanks
@maksymchernetskyy6404 Жыл бұрын
nextbranch or otherbranch can be null, then temp will be null, then we put null in the function that gives us the closest point, so we put null instead of the point. seems like a problem of this pseudocode to me. What do we do in this situation? Just output as best the non null one or we go to the other branch?
@SingularityLabsAI Жыл бұрын
0:44 if all coordinate shares same x-coordinate then it becomes easier as we only need to check at most 2 points.
@HH-mf8qz Жыл бұрын
Nice And good visualization with the radius r
@heitorgomes94964 жыл бұрын
Well done, great explanation!
@stablesort4 жыл бұрын
Thanks for the compliment!
@brunasouzadarochasantos99292 жыл бұрын
Excellent! Thank you so much!!
@klausdupont63353 жыл бұрын
Great video! Thanks!
@stablesort3 жыл бұрын
Cheers!
@anshugangwar73442 жыл бұрын
First of all Very nice explanation , Do you have any video or code reference on Designing and implementing a binary space partitioning (BSP) tree with functions for adding nodes, printing the nodes in descending order and searching for the spatially closest node (along the one dimension)?
@brucewernick6542 Жыл бұрын
What about N_Nearest_Neighbors? The logic for Nearest_Neighbor only works for the first.
@maximstepanenko2 жыл бұрын
Beautiful explanation. Thank you. )))
@shivamverma-mt6kp4 жыл бұрын
Great video. Please post the code in c++ or complete pseudo code.
@stablesort4 жыл бұрын
I do have the full source code in Java: bitbucket.org/StableSort/play/src/master/src/com/stablesort/kdtree/KDTree.java
@shivamverma-mt6kp4 жыл бұрын
@@stablesort Data structures in java is another trouble for me. I do data structures in c++ Please give the pseudo code atleast.
@stablesort4 жыл бұрын
@@shivamverma-mt6kp OK, here is a quick rundown: so you have a tree node, with left and right pointers (I called it KDNode). The "value" in that node could be a vector/array of integers, or encapsulated in some other object that just has that array/vector. I went with the second option, calling it KDPoint. class KDNode { KDNode left KDNode right KDPoint point ... } class KDPoint { List props // this could just be an array of int ... } // this is your main class with the algorithm to find the nearest neighbor: class KDTree { // reference to the root is all we need KDNode root // main method, described in the video: private KDNode nearestNeighbor(KDNode root, KDPoint target, int depth) { if (root == null) return null; KDNode nextBranch = null; KDNode otherBranch = null; // compare the property appropriate for the current depth if (target.get(depth) < root.point.get(depth)) { nextBranch = root.left; otherBranch = root.right; } else { nextBranch = root.right; otherBranch = root.left; } // recurse down the branch that's best according to the current depth KDNode temp = nearestNeighbor(nextBranch, target, depth + 1); KDNode best = closest(temp, root, target); long radiusSquared = distSquared(target, best.point); /* * We may need to check the other side of the tree. If the other side is closer than the radius, * then we must recurse to the other side as well. 'dist' is either a horizontal or a vertical line * that goes to an imaginary line that is splitting the plane by the root point. */ long dist = target.get(depth) - root.point.get(depth); if (radiusSquared >= dist * dist) { temp = nearestNeighbor(otherBranch, target, depth + 1); best = closest(temp, best, target); } return best; } // just picks the better option between n0 and n1, but does not traverse anywhere else KDNode closest(KDNode n0, KDNode n1, KDPoint target) { if (n0 == null) return n1; if (n1 == null) return n0; long d1 = distSquared(n0.point, target); long d2 = distSquared(n1.point, target); if (d1 < d2) return n0; else return n1; } ... } I believe this should be very close to C++ code. I hope this helps!
@少年追梦4 жыл бұрын
amazy,thinks~ expect the next
@stablesort4 жыл бұрын
You are very welcome!
@johnvif3 жыл бұрын
awesome video!
@stablesort3 жыл бұрын
Thanks for the compliment!
@karenaguilar2228 Жыл бұрын
que facilito de explicar. so good
@gimmemoreborisbrejcha97944 жыл бұрын
Well, great work.
@stablesort4 жыл бұрын
Cheers!
@franciscoornelas44882 жыл бұрын
Great content!
@ram845-l4k3 жыл бұрын
Great video 👍🏻 could you please upload the code for deleting a node from the tree?
@stablesort3 жыл бұрын
Thanks for the compliment. Deleting a node is not trivial, since you would have to either re-index all of the children nodes recursively or come up with some other scheme. Here are a couple from the top of my head: -just mark the node as deleted but not actually remove it. Then rebuild the tree once there are too many of these fake-deleted nodes. -move one of the leaf nodes in places of the deleted node
@pawtha22382 жыл бұрын
thanks for explanation in video. Please dont add background music, its distracting and annoying.
@avink60743 жыл бұрын
excellent !
@nchm26254 жыл бұрын
hi, thank you! I just ask myself what i need to do if i want to find not only my nearest neighbour but for example 5 or 6 nearest neighbours. Thanks :)
@stablesort4 жыл бұрын
Sure, that would be a natural extension to this problem. I think the most intuitive solution would be to use an additional max-heap into which you keep adding points. Restrict the size of the heap to K (5 or 6 in your example). Whenever you add a point to the heap and the size becomes greater than K, remove the top element. The top element will be the one with the greatest distance. So ultimately you'll end up amassing K points with the shortest distance.
@nchm26254 жыл бұрын
@@stablesort That would be a great addition to this video though :D thank you for that one, now i need to learn about heap maps
@stablesort4 жыл бұрын
@@nchm2625 If you are coding in Java, take a look at PriorityQueue class - it's Java's heap implementation. It can do exactly what you are looking for.
@nchm26254 жыл бұрын
@@stablesort Do you know if there is any literature about this specific problem, because i can't find anything? I'm greatful for every idea!
@stablesort4 жыл бұрын
@@nchm2625 Try searching for "k nearest neighbors using kdtree", such as: stackoverflow.com/questions/34688977/how-do-i-traverse-a-kdtree-to-find-k-nearest-neighbors
@madhuvarun27903 жыл бұрын
what if the data has more than 2 dimensions, let's say 3? in the first layer if the chosen dimension is x what will be the dimension chosen in the second layer and third?
@stablesort3 жыл бұрын
Thanks for posting a question. KD-Tree sequentially goes through each of the dimensions and then loops back. For example, if there are 3 dimensions, then it'd go in this sequence: 1, 2, 3, 1, 2, 3, 1, 2, 3, ... Typically this is easily implemented using MOD operator and the depth of the tree. So as you traverse deeper and deeper into the tree, you pass the 'depth' counter along. Then for a K dimensional tree, you'd pick dimension depth % K. Take a look at the source code linked in description for a sample implementation. Hope this helps!
@smitdumore1064 Жыл бұрын
Beautiful
@vasilispolychronakis5812 Жыл бұрын
why do you have a corn in a flower pot???
@bshsmdshj19386 ай бұрын
thank you!🤞🤞
@letoiiatreides24663 жыл бұрын
we just gonna ignore the corn in the flower pot?
@stablesort3 жыл бұрын
:-p
@twisted_cpp2 жыл бұрын
Is this Mlepnos? Jokes aside, nice explanation.
@frederickhamilton7663 Жыл бұрын
10/10 :-)
@tomgt4283 жыл бұрын
So cool
@stablesort3 жыл бұрын
Cheers!
@simonsheldon17103 жыл бұрын
ty for video
@benripka69772 жыл бұрын
Awesome
@billwang14562 жыл бұрын
3:59 good
@rafaelromeromunhoz98263 жыл бұрын
thankss
@stablesort3 жыл бұрын
cheers!
@adityarajora72192 жыл бұрын
how to search for second nearest neighbor?
@Артем-х7п6с2 жыл бұрын
Have you found a solution? I need to find the 5 closest points, but I can't figure out how to do it
@adityarajora72192 жыл бұрын
@@Артем-х7п6с still not, One stupid method is like delete the first node that you have found from the tree and then go for first node again, it will be your second.