2.5 - Closest Pair of Points using Divide and Conquer algorithm in O(n log n) time.

  Рет қаралды 38,138

Algorithms by Sharma Thankachan

Algorithms by Sharma Thankachan

3 жыл бұрын

Given a set of n points in 2 dimension, find the pair of points, such that the euclidean distance between them is the minimum. The trivial algorithm takes O(n^2) time, however, we can solve this in O(n log n) time using Divide and Conquer strategy.

Пікірлер: 70
@currently.unavailable
@currently.unavailable 3 жыл бұрын
Thank you, this is the first explanation I've seen for why we choose the 7 points in this algorithm. All others I've seen simply take that as an obvious truth, which to me it was not.
@illyushen9856
@illyushen9856 Жыл бұрын
this is underrated! the only video by which i could understand the 7 points saga!! thanks a ton!
@explorersagnik8522
@explorersagnik8522 3 жыл бұрын
wow i was not understanding this a whole day......after seeing your video, i understood it thank you so much sir
@flashdude64
@flashdude64 8 ай бұрын
holy shit I was looking for an understanding of why its 7 points. you are the most clear an concise. thank you
@doodle_Goose
@doodle_Goose 3 жыл бұрын
i really appreciate to you!!!!!!!! nobody explain why we can calculate only 7 times when the case 3(in your lecture), but you.... so thank you!!
@kelstonkkk
@kelstonkkk 2 ай бұрын
Thanks you, best explanation of this I have seen so far
@xdragonflame6563
@xdragonflame6563 3 жыл бұрын
Wow! That was a clear and easy to understand explanation. Thank you.
@prabhatrai1244
@prabhatrai1244 2 жыл бұрын
Finally, I got best explanation . Great Explanation Sir!
@ethanz584
@ethanz584 2 жыл бұрын
You are the only one makes me understand!Thank you!
@abubakursait4193
@abubakursait4193 Жыл бұрын
You just saved me a lot of time reading the notebook and listening to our prof. Thank you so much.. Please keep going.
@IWasBoredSo
@IWasBoredSo 2 жыл бұрын
Great explanation of this problem. Thank you for your work :)
@ramazanyel5979
@ramazanyel5979 3 жыл бұрын
great explanation. simple and understandable. thanks a lot
@pikachu-rk8sp
@pikachu-rk8sp 3 жыл бұрын
Really nice explanation! Thank You!
@kms8320
@kms8320 3 жыл бұрын
Thank you sir very nice explanation !!! lockdown ka bharpur fayda uthaya he sir ne
@ashiquddinpranto4275
@ashiquddinpranto4275 3 жыл бұрын
very very well explanation....
@ananya_sinha050
@ananya_sinha050 3 жыл бұрын
Ur explanation is better than gfg.... Looking forward for more explanations
@adityasherawat1697
@adityasherawat1697 3 жыл бұрын
really nice explanation
@18sp01
@18sp01 Жыл бұрын
Thank you, this video helped me fully understand!!
@daisy_haniii
@daisy_haniii Жыл бұрын
Thank you! Great Explanation
@laxmandilliraj7379
@laxmandilliraj7379 2 жыл бұрын
Thank you sir for the lecture. 😀
@SandeshPandeyy
@SandeshPandeyy 3 ай бұрын
Very well explained !!
@valeriacarrillo9193
@valeriacarrillo9193 3 ай бұрын
thank you so much this helped a lot!!!
@dallasmilanista8291
@dallasmilanista8291 2 жыл бұрын
Very good explanation
@janapalaswathi4262
@janapalaswathi4262 8 ай бұрын
Well explained.. 👏
@nanayang3736
@nanayang3736 2 жыл бұрын
15:45 Here starts the proof of the next-7 claim. Thank you so much sir, this is beautiful. Plus i think maybe another way of getting rid of the theta(nlgn) of sorting in the recurrence is to do a preprocessing (of y-cor sorting) beforehand (before the main Closest Pair Problem) so that T(n) and theta(nlgn) sorting time can stand independently, and then the final runtime remains theta(nlgn).
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 жыл бұрын
YES, correct !!!
@sandeepnallala48
@sandeepnallala48 2 жыл бұрын
thanks dear, thinking of the same how to get rid of extra logn factor by not redefining the way sir did ..
@user-bw5lp6uj5t
@user-bw5lp6uj5t 15 күн бұрын
good explanation
@merrinj8484
@merrinj8484 2 жыл бұрын
well explained !!
@shaktipratap8200
@shaktipratap8200 3 жыл бұрын
thank u :) nice explain
@ktmi3037
@ktmi3037 2 ай бұрын
this is great! thank you! why don't professors explain in a similar manner instead of showing 20 slides for 40 min...
@anmoldhawan8190
@anmoldhawan8190 3 жыл бұрын
Thank You.
@rizalmuhammed7816
@rizalmuhammed7816 3 жыл бұрын
Thanks a lot
@kirandwivedi7529
@kirandwivedi7529 2 жыл бұрын
Thankyou for such good explanation sir,d/2 approach was awesome.
@kirandwivedi7529
@kirandwivedi7529 2 жыл бұрын
But sir instead of taking 7 points,after visualisation I think only 3 points distance need to be calculated? Where I am going wrong??
@sharmathankachan5403
@sharmathankachan5403 2 жыл бұрын
@@kirandwivedi7529 yea, you can optimize a bit (to 4 instead of 7), like we don’t need to compute the distance if both points are on the same side, but there is an associated cost to examine if both points are on the same side. Therefore, over all asymptotic complexity won’t change with such optimizations
@sandeepnallala48
@sandeepnallala48 2 жыл бұрын
THE BEST EXPLANATION SIR . till O(nlog^2(n)) it was very much clear sir but the redefining of the T(n) itself is somewhat non - intuitive since our T(n) should be telling abt only the Time taken to solve the problem as a whole not taking to consideration the sorting part.
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 жыл бұрын
it is up to us how we want to define T(n). Here, within T(n) = O(n log n), we can solve the original problem + some extra stuffs, which means the complexity of the original problem is also O(n log n).
@yaotingchen
@yaotingchen Жыл бұрын
thank you so much!
@claywrentz3119
@claywrentz3119 4 ай бұрын
Thank you beast
@KaranKumar-by7ko
@KaranKumar-by7ko Жыл бұрын
Dhanyawad guru ji
@felipec06
@felipec06 2 жыл бұрын
Perfect
@merrinj8484
@merrinj8484 2 жыл бұрын
Sir..can you please take a class on Dixon's factorization?
@EdgarTorres-ky3fd
@EdgarTorres-ky3fd 3 жыл бұрын
hi, so when you say we can 8 points, the way you numbered the boxes, is it posible to have a valid pair in box 1,2 or 3,4, since they are in the same region? case 3 mentions that the points have to be one on a side, and one on the other, but not both in one side
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 3 жыл бұрын
You will not find a valid pair (i.e., < d) in 1 and 2, because they are on the same side [from the definition of "d"]. But it is possible to have a valid pair in 3 and 4 (because they are on different sides).
@emilyhuang2759
@emilyhuang2759 3 жыл бұрын
Oh, so is the proof of correctness just saying there won't be a point closer to the point than what we find in the third region?
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 3 жыл бұрын
@@emilyhuang2759 proof of correctness says the following, just sort all points within the strip with respect to y-coordinate. Then if there is a pair with distance < d, then the second point within the pair comes as either the first, or second, or third, ...or 7th point after the first point within the pair. So, our algorithm will find it.
@umairalvi7382
@umairalvi7382 3 жыл бұрын
If there would have been a point in 1,2 boxes then it would have already been the part of shortest pair in left region and same applies to right region.so that is why we will be able to find shortest pair of points from left and right.
@hsuhsu2435
@hsuhsu2435 2 жыл бұрын
The array in case 3 has all of the points within 2d region. One thing I can't catch up is where the points within 2d x d region come from?
@amirghorban2044
@amirghorban2044 2 жыл бұрын
nice thank you
@sukhmanjitsingh2705
@sukhmanjitsingh2705 3 күн бұрын
For correctness of we are comparing points sorted by y axis, what if there are 7 points in the other quadrant more than d distance away and 1 point directly underneath which is super close we missed that point and in end gave inaccurate result
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 3 күн бұрын
Suppose "p" is the current point and "q" is the other point (which is super close and underneath p) and (p,q) is the closest pair. You are right, this pair wont be captured while doing our procedure at "p", but it will be captured when we do our procedure at "q''.
@sukhmanjitsingh2705
@sukhmanjitsingh2705 3 күн бұрын
@@algorithmsbysharmathankach7521 we take a look at next 7 points right and not the ones that are already scanned
@sukhmanjitsingh2705
@sukhmanjitsingh2705 2 күн бұрын
@@algorithmsbysharmathankach7521 the points are sorted by y co ordinate and we check with next 7 points not previous ones
@timeinabottle9155
@timeinabottle9155 3 жыл бұрын
Hi, first of all thank you for the video. I didn't understand why there must be one point each little eight boxes. Why the distance of 2 points must not be less than d over square root of 2? Why is not allowed? What is the definition of d?
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 3 жыл бұрын
"d" is the minimum of d1 and d1, i.e., the shortest distance between all possible pairs, where both points are completely on either the left side or the right side. Now this little boxes are completely within the LEFT or RIGHT side. Note that d/root(2) is the length of the diagonal. Now if there are two points within a square, the distance between them will be at most d/root(2), which is shorter than "d", which contradicts the definition of "d" at the first place.
@timeinabottle9155
@timeinabottle9155 3 жыл бұрын
@@algorithmsbysharmathankach7521 So, if I understand correctly, at first we declared that minimum distance of the two points is d and d/root(2) is less than d thats why 2 points cannot be in the same square boxes. Right? Thank you so much:))
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 3 жыл бұрын
@@timeinabottle9155 The min distance of 2 points that are completely within one side (left or right), which is computed via recursion.
@theappareddy8376
@theappareddy8376 2 жыл бұрын
For every point we take next 7 points yes but 3 of those 7 will be in the same side as starting point so we can ignore them and check with only 4. Because if those 3 are no way can result in closest point as we already found that by recurring for left
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 жыл бұрын
Sure, we can modify the algorithm a bit and reduce the number of distance computations per point to 4 from 7, although the asymptotic complexity remains the same.
@dmitricherleto8234
@dmitricherleto8234 2 ай бұрын
I understand that each box can have at most one point but why do we even need to compare 7 since the distance on the left half or right half region is at most d. Why don't we just compare the points between the two regions?
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 ай бұрын
Yes, we can fix a point (on a side) and just compare it with 4 (instead of 7) points on the other side. But these 4 points can be anyone's among the next 7 points (if we sort with respect to Y). So, we might still need to examine the next 7 points. The answer is yes, we can do a bit of optimization here, but the asymptotic time will be the same.
@suryaram6874
@suryaram6874 7 ай бұрын
❤‍🔥
@MsLittleVenus
@MsLittleVenus 3 жыл бұрын
tşk
@ch0c0_1
@ch0c0_1 2 жыл бұрын
I didn't get how the time complexity is reduced from nlog^2n to nlogn
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 жыл бұрын
Since we are dividing and conquering in the same way as merge-sort, we just interleaved our algorithm with mergesort, so that the sorted list (at every level of merging) comes without extra cost.
@rithanyabalamurali6936
@rithanyabalamurali6936 2 жыл бұрын
why only 7?
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 жыл бұрын
watch from 17:30 to 20:00
@shwetakhanna9039
@shwetakhanna9039 2 жыл бұрын
Hit me like if you also didn't understand after 8 boxes.
2.6 - Counting Inversions in an Array in O(n log n) time via Divide and Conquer
19:27
Algorithms by Sharma Thankachan
Рет қаралды 10 М.
Closest Pair of Points (Divide and Conquer) Explained
8:45
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 4,9 МЛН
Why? 😭 #shorts by Leisi Crazy
00:16
Leisi Crazy
Рет қаралды 47 МЛН
Chips evolution !! 😔😔
00:23
Tibo InShape
Рет қаралды 42 МЛН
15 Sorting Algorithms in 6 Minutes
5:50
Timo Bingmann
Рет қаралды 24 МЛН
2.2 - Linear Time Selection (Median of Medians Algorithm)
32:07
Algorithms by Sharma Thankachan
Рет қаралды 19 М.
P vs. NP and the Computational Complexity Zoo
10:44
hackerdashery
Рет қаралды 3,4 МЛН
The Map of Mathematics
11:06
Domain of Science
Рет қаралды 13 МЛН
Animation vs. Math
14:03
Alan Becker
Рет қаралды 60 МЛН
How to Start a Speech
8:47
Conor Neill
Рет қаралды 19 МЛН
How to Make it Through Calculus (Neil deGrasse Tyson)
3:38
Jonathan Arrington
Рет қаралды 1,5 МЛН
Convex Hull Algorithm - Graham Scan and Jarvis March tutorial
7:24
How to find the closest pair of points in O(nlogn)? - Inside code
12:22
Newton's method (introduction & example)
20:53
blackpenredpen
Рет қаралды 174 М.
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 4,9 МЛН