Find Complete Code at GeeksforGeeks Article: www.geeksforgeeks.org/closest-... This video is contributed by Harshit Verma Please Like, Comment and Share the Video among your friends. Also, Subscribe if you haven't already! :)
Пікірлер: 88
@AhamBrahmosmi4 жыл бұрын
God will understand
@arthurleywin4307Ай бұрын
0:13
@Jack-dx7qb4 жыл бұрын
I'd like to think of the step 6 as follows: Consider a d by d square fully contained in the right strip. Then there can be at most four points in the square, i.e., the four points all lying on the four vertices of the square, since if there are five points or more, then there will be at least one pair of points whose distance is smaller than d, which is a contradiction. This holds similarly for the left strip as well. Now, let P be any point in the strip of width 2d centered at the vertical line shown in the video. For any 2d by 2d square containing P and fully contained in the strip, there exists at most eight points. In this worst case, P is at the center of the 2d by 2d square, and the other eight points lie on vertices and the middle of all edges. Thus, it takes only constant time to verify whether there is a point on the other side of P whose distance from P is smaller than d. The number of points in strip is O(n), and each point takes a constant to verify. So, verifying whether there is a pair of points lying on different sides whose distance is smaller than d takes O(n).
@jaatharsh3 жыл бұрын
thanks for this dude
@adamodimattia4 жыл бұрын
I got lost after 4th minute. The most important part is unintelligible.
@hezkygcs75452 жыл бұрын
I admit that one is so hard to understand. But his explanation is the clearest explanation I've ever found so far.
@dma64815 жыл бұрын
sound quality should be improved
@jaincoral254 жыл бұрын
At least explain the code properly.
@tianchen45223 жыл бұрын
I get confused on 7 points because actually none of the points on your side will be the result because they are all > d. so you only compare to the other 4 points on the other side which is not enough if you try to draw a circle with a radius of d center at your point. It touches more "square" on the other side if you are close to the strip. I think this is very clear to everyone.
@aayushshah84433 жыл бұрын
My right ear enjoyed it xD
@day35ofdebuggingthesamelin562 жыл бұрын
Same, but now I gotta teach my left year wtf I just watched
@amiraliomidfar15125 жыл бұрын
Thanks for your great video. Quick question: According to "Algorithm Design" by Tardos the time complexity is O(nlogn) I didn't get how you derived it to be to O(n(logn)^2). I guess we can't use master theorem in the way you formulated it as the theorem uses big theta and this case we had big O.
@aniketjadhav54734 жыл бұрын
The recurrence relation is T(n) = 2T(n/2) + Cn The nlogn part will not come in recurrence because it is one time sorting (Pre processing) If you solve above recurrence relation you will get O(nlogn)
@adithyapvarma87384 жыл бұрын
@@aniketjadhav5473 What do you mean one-time sorting(pre-processing)?? I don't understand. Please clarify.
@somerandomnoob1004 жыл бұрын
@@adithyapvarma8738 in the videos implementation the time complexity is nlog^2(n) because on every recursive call we sort strip which is an nlogn step. the recurrence is then t(n) = 2t(n/2) + O(nlogn). which is O( nlog^2(n)) clearly if we dont have to sort strip on every call we can get O(nlogn) solution. what aniket is saying is that in order to implement this we have to pre process the points such that we already have a list of the points sorted by y, which we can then use to create strip on every recursive call. Implementation for this can be found on geeks for geeks website
I absolutely love the sound quality , Its just fukin amazing !
@lukasahmed12712 жыл бұрын
i know I am kinda off topic but does anybody know of a good website to watch new series online ?
@guodonghu2864 жыл бұрын
I think you guys should try to implment 1D closet pair which is easier to understand. The basic idea behind these is Devide and Conquer. We understand the idea is the most important. public static int mindist(int[] a, int lo, int hi) { if (lo >= hi) { return Integer.MAX_VALUE; } else if (lo == hi - 1) { return a[hi] - a[lo]; } else { int m = lo + (hi - lo) / 2; int delta_1 = mindist(a, lo, m); // left points set int delta_2 = mindist(a, m + 1, hi); // right points set int delta_3 = a[m + 1] - a[m]; // strip points min distance return _Math.min(delta_1, delta_2, delta_3); } }
@adityasrivastava87903 жыл бұрын
Thanks a lot!! Does it works for 1D ? Please help I have an exam tomorrow.
@futurezing6 жыл бұрын
Isn't the comparison done for all the points in the strip in stripClosest function rather than just looking at only 7 points? What am I missing?
@sourabroy77874 жыл бұрын
In stripClosest() ith loop will run for all the point but jth loop should compare 1 point with next 7 points only and so on. Not very clear how he implemented it in the code.
@uttamrana29044 жыл бұрын
@@sourabroy7787 the j loop will stop when the y- distance becomes greater than d and within that range i.e the starting point and the last point within y distance less than equal to d there can be at most 7 points as explained in the video
@joaquinp51763 жыл бұрын
Why do i need to compare to other 7 points? Isn't it enough to compare to at most the 4 points that are on the other side of the strip? I mean, if the 2 points that yield the minimum distance are at the same side of the strip, i would have found them before making the strip, when comparing all the points at each side... so i only need to compare a point on the left side with the 4 points of the right side that are at most at d distance, or am i missing something?
@lllegend13042 жыл бұрын
what if the points are (-3,-4), (-2,4),(-2,-2) for example? wouldn't this be stuck as strip contains the 3 points then you'd solve them recursively only to be stuck again with the same 3 when u check around midpoint
@santhoshcts57 жыл бұрын
Awesome Harshit , started to see some complex problems being taken care by geeks for geeks team now . kudos , I break my head to understand the strip ( how to calculate only required points not all of them in strip, couple of years ago ) this lucid explanation definitely deserves more likes . first from me :) . Keep doing good work . - Sunny
@RonitJoshi10175 жыл бұрын
Let's say the data set is immense, with over 10^9 values of points. Would it be wise to split the list into 3 instead of 2 and do it accordingly? If so, why can't I split it into 3 parts for smaller data sets as well or even split into 4 or 5?
@mrigendra5 жыл бұрын
As you can see divide and conquer is like creating binary tree. If you search online about how performance differs when instead of using binary tree, we use 3-way/4-way tree, there are calculation to prove that binary tree gives better performance compared to others.
@sankeethganeswaran30243 ай бұрын
the time complexity here isn't optimal. it assumes you're sorting by the y for each recursive call, which is unecessary. you only need to do it once at the start, which makes the recurrence T(n) = 2T(n/2) + O(n) = O(nlogn)
@rishazara4152 жыл бұрын
Very useful contents.thank u👍
@onurcanisler3 жыл бұрын
*Wonderful code, God bless! As my Indian friends say: "Hats off, sir!"*
@randythamrin59763 жыл бұрын
02:38 step number three, confuse me? why 12 and 14 are the closest ones, or 15 and 3 are the closest ones for each side, how we calculate it?
@sauravkumar-gl8wg Жыл бұрын
thanks for creating these videos
@pranav33514 жыл бұрын
Those who didn't get the above explanation, This video might help- kzfaq.info/get/bejne/rs9diqlhnNilgas.html (from 20:00)
@paragggoyal1552 Жыл бұрын
way better explaination thankyou!
@studyonline32364 жыл бұрын
if you are wondering how can there be a finite number of points (8) from which we need to compute distances, here's an explanation in simplest words. I've had way too much free time during this quarantine. Here's the explanation of what you wanted with proof. Once you've found out the LD(minimum distance on the left side of the separator line L) and RD(...........right side of..........), you'd find delta which is the minimum of the aforementioned distances(DELTA=min(LD,RD)). Now, its time for finding the distance b/w the points lying on the EITHER SIDE of the line L. So you'd now construct the strip (of length 2*Delta) across L and search for the points lying within the strip and distanced < DELTA. We will now build a square(assume its either on the left or right side of the line L just for simplicity) with side=DELTA and see how many points fit in it conforming to our requirement that minD
@rubyPWNS1 Жыл бұрын
my right ear enjoyed this.
@martindinaputra86016 жыл бұрын
in the stripClosest() method, the most outer for, shouldn't it be for( int i = 0; i < size - 1; i++) ? because when i = size - 1, J = i + 1 which is equals to size, strip[J] would result an error wouldn't it? please tell me if i'm missing something
@burakmete57596 жыл бұрын
Martin D Putra first condition of the inner loop is j< size, it does not matter wherher j is bigger than i or not, it would not iterate while j is equal to size
@seanwalker25556 жыл бұрын
how did you find dl and dr in step 3? and what time complexity did it take?
@sagartyagi24505 жыл бұрын
With the use of brute force....means as soon as the recursion will have n
@anujdhoot78044 жыл бұрын
I could not understand why 7 points comparison only. How did you use the rectangle geometry also unknown? Request you to stress more on the 7n comparison part as it's not clear. Why you say d/square-root(2) should not be possible. I believe it is less than d and hence minimum. I need more lucid videos on this topic.
@danielmcgee24473 жыл бұрын
code doesnt seem to compile for C++
@parsanoori82174 жыл бұрын
Combine sounds please
@gingerAV5 жыл бұрын
Great video! Pan the sound to the center tho pls
@adithyapvarma87384 жыл бұрын
Yeah. I thought my earphones started malfunctioning in between. It's so much irritating if the sound is on one side only.
@aqilaebrahimi19305 жыл бұрын
what about farthest pair of point???
@mikhailurmich3 жыл бұрын
it would have been found recursively
@AhamBrahmosmi4 жыл бұрын
Where you use |pq| formula
@sourabroy77874 жыл бұрын
dist(p1,p2)
@nirmalbabu95703 жыл бұрын
thankyou. pretty clear explanation
@dewmi440311 ай бұрын
yes guys I am sitting to your right
@zankhanabhatt3 жыл бұрын
How we can arrange the elements on the plane?
@flueesyblueesy62463 жыл бұрын
Guess in terms of x index and then y index using a custom comparator? idk
@kanchanapallirohithraju88306 жыл бұрын
will that points diagram will be given?
@mikhailurmich3 жыл бұрын
DnC solves it in O(n logn) The code is horrible
@oskaerd21822 жыл бұрын
well this is calculating distance between two closest points, not the points themselves. be specific. disappointed
@dmitryWeirdo6 жыл бұрын
Although your channel and videos are great, you have to work hard on your English or at least speak much slower. Or at super-least, add the textual transcription of the text you say. It's very hard to understand the speech now unfortunately. Otherwise you're doing a great teaching work, keep on!
@GeeksforGeeksVideos6 жыл бұрын
Thanks dmitryWeirdo for the appreciation. We almost always add the subtitles to our videos. You can turn them on using the Subtitles/Captions button in the player settings.
@DBCatch22x6 жыл бұрын
For what it's worth, I feel you did a fantastic job explaining and I am a native English speaker. I had no problems understanding you. Great videos!
@ImagoSpectrum5 жыл бұрын
@@DBCatch22x Although most of the video is indeed understandable some sections such as a couple seconds into (7:49) would be hard to decipher.
@Anand-wi4yb5 жыл бұрын
@dmitryWeirdo This video is contributed by an Indian. We are not native English speakers like you. If you are asked to explain something in Hindi, people will probably laugh at you.
@paragggoyal1552 Жыл бұрын
i see all these comments saying that very good explanation but i don't think this explanation is good at all my personal opinion.
@anwarulbashirshuaib56733 жыл бұрын
My left ear: 😐😐
@yashaggarwal50864 жыл бұрын
amazing
@akirablac5 жыл бұрын
Sound in only one ear. Fix It.
@Dopekingg5 жыл бұрын
problrm is there in the balancing otherwise sound is coming from both the earplugs!!
@vikrant_4625 жыл бұрын
😂i thought that some problem occured in my earphone until i saw your comment lol...
@norah68996 жыл бұрын
HER HER HER OMG -_- -_-
@mironabdullah48203 жыл бұрын
I did not understand your English accent. It was wired
@user-ws1ix2ot7o7 ай бұрын
can u please be louder or else use mic please
@ghilmanfatih97513 жыл бұрын
If this problem is an interview problem, I'll be damned