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

  Рет қаралды 45,450

Algorithms by Sharma Thankachan

Algorithms by Sharma Thankachan

Күн бұрын

Пікірлер
@illyushen9856
@illyushen9856 2 жыл бұрын
this is underrated! the only video by which i could understand the 7 points saga!! thanks a ton!
@flashdude64
@flashdude64 Жыл бұрын
holy shit I was looking for an understanding of why its 7 points. you are the most clear an concise. thank you
@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.
@explorersagnik8522
@explorersagnik8522 4 жыл бұрын
wow i was not understanding this a whole day......after seeing your video, i understood it thank you so much sir
@moorooX2
@moorooX2 4 жыл бұрын
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!!
@nanayang3736
@nanayang3736 3 жыл бұрын
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 3 жыл бұрын
YES, correct !!!
@sandeepnallala48
@sandeepnallala48 3 жыл бұрын
thanks dear, thinking of the same how to get rid of extra logn factor by not redefining the way sir did ..
@kelstonkkk
@kelstonkkk 9 ай бұрын
Thanks you, best explanation of this I have seen so far
@ethanz584
@ethanz584 3 жыл бұрын
You are the only one makes me understand!Thank you!
@ananya_sinha050
@ananya_sinha050 4 жыл бұрын
Ur explanation is better than gfg.... Looking forward for more explanations
@xdragonflame6563
@xdragonflame6563 3 жыл бұрын
Wow! That was a clear and easy to understand explanation. Thank you.
@kms8320
@kms8320 4 жыл бұрын
Thank you sir very nice explanation !!! lockdown ka bharpur fayda uthaya he sir ne
@sandeepnallala48
@sandeepnallala48 3 жыл бұрын
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 3 жыл бұрын
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).
@GitHubertP
@GitHubertP 3 жыл бұрын
Great explanation of this problem. Thank you for your work :)
@mehdiboudour
@mehdiboudour 5 ай бұрын
Thank you sir, finally understood it thanks to you.
@JeetDaiya-d6j
@JeetDaiya-d6j 3 ай бұрын
Amazing Explaination Sir!!
@jtrigoura1
@jtrigoura1 2 ай бұрын
Absolutely goated explanation
@ramazanyel5979
@ramazanyel5979 3 жыл бұрын
great explanation. simple and understandable. thanks a lot
@pikachu-rk8sp
@pikachu-rk8sp 3 жыл бұрын
Really nice explanation! Thank You!
@18sp01
@18sp01 Жыл бұрын
Thank you, this video helped me fully understand!!
@ashiquddinpranto4275
@ashiquddinpranto4275 4 жыл бұрын
very very well explanation....
@valeriacarrillo9193
@valeriacarrillo9193 10 ай бұрын
thank you so much this helped a lot!!!
@janapalaswathi4262
@janapalaswathi4262 Жыл бұрын
Well explained.. 👏
@kirandwivedi7529
@kirandwivedi7529 3 жыл бұрын
Thankyou for such good explanation sir,d/2 approach was awesome.
@kirandwivedi7529
@kirandwivedi7529 3 жыл бұрын
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 3 жыл бұрын
@@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
@ZephyrrCummins
@ZephyrrCummins 10 ай бұрын
Very well explained !!
@dallasmilanista8291
@dallasmilanista8291 2 жыл бұрын
Very good explanation
@daisy_haniii
@daisy_haniii 2 жыл бұрын
Thank you! Great Explanation
@KshitijGupta-r8p
@KshitijGupta-r8p 7 ай бұрын
good explanation
@ktmi3037
@ktmi3037 10 ай бұрын
this is great! thank you! why don't professors explain in a similar manner instead of showing 20 slides for 40 min...
@adityasherawat1697
@adityasherawat1697 3 жыл бұрын
really nice explanation
@laxmandilliraj7379
@laxmandilliraj7379 2 жыл бұрын
Thank you sir for the lecture. 😀
@sukhmanjitsingh2705
@sukhmanjitsingh2705 7 ай бұрын
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 7 ай бұрын
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 7 ай бұрын
@@algorithmsbysharmathankach7521 we take a look at next 7 points right and not the ones that are already scanned
@sukhmanjitsingh2705
@sukhmanjitsingh2705 7 ай бұрын
@@algorithmsbysharmathankach7521 the points are sorted by y co ordinate and we check with next 7 points not previous ones
@merrinj8484
@merrinj8484 2 жыл бұрын
well explained !!
@EdgarTorres-ky3fd
@EdgarTorres-ky3fd 4 жыл бұрын
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 4 жыл бұрын
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 4 жыл бұрын
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 4 жыл бұрын
@@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 3 жыл бұрын
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?
@theappareddy8376
@theappareddy8376 3 жыл бұрын
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 3 жыл бұрын
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.
@shaktipratap8200
@shaktipratap8200 4 жыл бұрын
thank u :) nice explain
@Lack_Of_Enemies
@Lack_Of_Enemies Ай бұрын
made it so clear
@dmitricherleto8234
@dmitricherleto8234 10 ай бұрын
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 10 ай бұрын
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.
@merrinj8484
@merrinj8484 2 жыл бұрын
Sir..can you please take a class on Dixon's factorization?
@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.
@KaranKumar-by7ko
@KaranKumar-by7ko Жыл бұрын
Dhanyawad guru ji
@tashdidrahman8113
@tashdidrahman8113 Ай бұрын
Can anyone explain why the x coordinate was not sorted ?
@claywrentz3119
@claywrentz3119 11 ай бұрын
Thank you beast
@anmoldhawan8190
@anmoldhawan8190 4 жыл бұрын
Thank You.
@yaotingchen
@yaotingchen Жыл бұрын
thank you so much!
@rizalmuhammed7816
@rizalmuhammed7816 4 жыл бұрын
Thanks a lot
@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.
@felipec06
@felipec06 3 жыл бұрын
Perfect
@amirghorban2044
@amirghorban2044 3 жыл бұрын
nice thank you
@shwetakhanna9039
@shwetakhanna9039 3 жыл бұрын
Hit me like if you also didn't understand after 8 boxes.
@rithanyabalamurali6936
@rithanyabalamurali6936 2 жыл бұрын
why only 7?
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 2 жыл бұрын
watch from 17:30 to 20:00
@radhe_krashna
@radhe_krashna 5 ай бұрын
why it is 7
@algorithmsbysharmathankach7521
@algorithmsbysharmathankach7521 5 ай бұрын
its clear in the proof, there are 8 boxes, so if we fix one box for one point, they we have other 7 possible boxes for the other point
@radhe_krashna
@radhe_krashna 5 ай бұрын
@@algorithmsbysharmathankach7521 it should be 4 rather than 7
@suryaram6874
@suryaram6874 Жыл бұрын
❤‍🔥
@MsLittleVenus
@MsLittleVenus 3 жыл бұрын
tşk
2.6 - Counting Inversions in an Array in O(n log n) time via Divide and Conquer
19:27
Algorithms by Sharma Thankachan
Рет қаралды 12 М.
3. Divide & Conquer: FFT
1:20:52
MIT OpenCourseWare
Рет қаралды 323 М.
Почему Катар богатый? #shorts
0:45
Послезавтра
Рет қаралды 2 МЛН
$1 vs $500,000 Plane Ticket!
12:20
MrBeast
Рет қаралды 122 МЛН
Closest Pair of Points (Divide and Conquer) Explained
8:45
2.2 - Linear Time Selection (Median of Medians Algorithm)
32:07
Algorithms by Sharma Thankachan
Рет қаралды 23 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 94 М.
If you're ambitious but lazy, please watch this video...
12:57
Mark Tilbury
Рет қаралды 425 М.
How to find the closest pair of points in O(nlogn)? - Inside code
12:22
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 2,5 МЛН
2. Divide & Conquer: Convex Hull, Median Finding
1:20:35
MIT OpenCourseWare
Рет қаралды 205 М.
Calculus at a Fifth Grade Level
19:06
Lukey B. The Physics G
Рет қаралды 8 МЛН
2.7 - Finding the MIN/MAX slope (of lines connecting points in 2D) and its Counting Version
25:10
Convex Hull Algorithm - Graham Scan and Jarvis March tutorial
7:24