Closest Pair of Points (Divide and Conquer) Explained

Sdílet
Vložit
  • čas přidán 3. 05. 2021
  • This is a recorded presentation for a college course (CMPU241, Spring 2021).
    Algorithm explained: Closest Pair of Points (using the Divide and Conquer method)
    Time & Space complexity: O(nlgn)

Komentáře • 118

  • @softsun2134
    @softsun2134 Před 3 lety +22

    probably the clearest explanation I've seen of this algorithm thanks!

  • @andy0401ify
    @andy0401ify Před rokem +6

    OMG there hasn't been any explanation better than yours ever!!!! couldn't be any clearer!!!!! Thank you so much!!!

  • @aishwaryaramesh4877
    @aishwaryaramesh4877 Před 3 lety +2

    Wow, amazing video! You explained it so well that I finally understood it after breaking my head for sooo many days. Thanks a ton! 🙏🙏

  • @pm_ranj
    @pm_ranj Před 2 lety +1

    That was the nicest video of this algorithm on YT so far, keep it up

  • @AntonKimS
    @AntonKimS Před 2 lety

    Fantastic video! Best explanation I have seen so far. Would be awesome to see more videos on other algorithms. Thank you!

  • @gezhi9420
    @gezhi9420 Před 3 lety +3

    讲得太好了,非常清晰。Visualization is awesome.

  • @berouminum3424
    @berouminum3424 Před 3 lety +31

    Truly an on "point" explanation. Thank you, keep going!

  • @finiteimpulse3765
    @finiteimpulse3765 Před 2 lety +2

    Clear and precise explanation with a lovely voice.

  • @VultureGamerPL
    @VultureGamerPL Před 2 lety

    Simple and to the point. Nicely done.

  • @albertswiecicki395
    @albertswiecicki395 Před rokem

    Quality content, I was looking for. Thank you!

  • @MagicThanos7
    @MagicThanos7 Před měsícem

    we definitely need more of these explanations from you

  • @lujainabdulrahman9572

    Thank you so much, best explanation I’ve come across!

  • @nopesep9123
    @nopesep9123 Před měsícem

    Incredible explanation, the best I have found, thank you very much!!!!!!!!!!!!!!!!!!!!!!!!!

  • @Zinab8850
    @Zinab8850 Před 2 lety

    Amazing explanation 🤩🤩 the animation was extremely helpful in seeing how the algorithm works

  • @balakr231
    @balakr231 Před 2 měsíci

    The only tutorial on the channel had to be the on the topic i was looking for.

  • @la337erf
    @la337erf Před 2 lety +1

    This is amazing. Please make more videos on other algorithms!!

  • @mohammadyahya78
    @mohammadyahya78 Před 5 měsíci

    amazing amazing amazing and the best explanation for this problem. Thank you

  • @bayanassali2339
    @bayanassali2339 Před 2 lety

    Very visual and clear explanation thank you so much!

  • @taivinh1986
    @taivinh1986 Před 2 lety

    the best explanations I've ever seen

  • @leilu5607
    @leilu5607 Před 2 lety

    This is an amazing explanation! 讲得好棒!

  • @JR-vc4gm
    @JR-vc4gm Před 2 lety

    Wow great video! I had a hard time to understand why there was a maximum number of point in the delta region. Thank you

  • @danieloladele1433
    @danieloladele1433 Před 2 lety

    Excellent work and very easy to understand

  • @samoyed_fps
    @samoyed_fps Před 2 lety

    It's really a clear explaination, amazing !

  • @alvjkd
    @alvjkd Před měsícem

    wow this was amazing. thank you so much for this!!

  • @Chellali.A
    @Chellali.A Před 8 měsíci +1

    Thank you so much ,
    I wanted to bring to your attention a concern I have regarding the time complexity of the closestPair function in this algorithm.
    Specifically, when calling the function for all elements of Y in the following lines:
    dl = closestPair(X[1 .. mid], Y);
    dr = closestPair(X[mid+1 ... n], Y);
    I believe this approach increases the time complexity. The search for the strip is performed in Y, which has a length of N. Consequently, the work done by subproblems becomes O(N), where N is the number of all the points of the problem. This happens because Y is not getting smaller through the dividing process.
    I propose a modification where the work by subproblems is O(L), where L is the length of the subproblem. To achieve this, the Y in the call to closestPair(X, Y) should contain the same elements as X, with X being the array that undergoes division.
    Thank you for considering this suggestion.

  • @peterthegreat8464
    @peterthegreat8464 Před rokem

    Beautiful algorithm explained by a beautiful voice

  • @seharpanesar5132
    @seharpanesar5132 Před 2 lety +1

    This is so good. Thank you!!

  • @samanasghari6213
    @samanasghari6213 Před 4 měsíci

    That was awesome
    Keep it going🎉🎉

  • @gsmdfaheem
    @gsmdfaheem Před 2 lety

    This was perfect.....Thank you so much!

  • @sahilverma286
    @sahilverma286 Před 3 lety +28

    You have explained the topic very effectively and you made everything easy. Before I had plenty of doubts but now you made it clear. Keep on posting such videos. I'll be eagerly waiting for your next videos ^_^

    • @ANGEL_GFREENS
      @ANGEL_GFREENS Před 2 lety

      What are best average and worst time complexity of this algorithm called closest pair by divide and conquer

  • @waynej11
    @waynej11 Před 7 měsíci

    so great , that was i am loving version.

  • @Corgamos
    @Corgamos Před 3 lety +1

    Thank you, very nicely explained!

  • @soumitramondal4013
    @soumitramondal4013 Před 3 lety +22

    The way you explained is really awesome. Can we expect more videos like this?

  • @manrajsingh4644
    @manrajsingh4644 Před 2 lety

    Cleanest explanation ❤️

  • @DanielLochner
    @DanielLochner Před 2 lety

    Fantastic presentation! Thanks a bunch! :)

  • @AkashKumar-jl3sw
    @AkashKumar-jl3sw Před 2 lety

    Amazing thank you for your explanation !!!!

  • @squidsword0
    @squidsword0 Před 2 lety

    amazing work. helped me a lot

  • @guolongli5524
    @guolongli5524 Před rokem

    Thank you! Great explanation!

  • @nipplesniper
    @nipplesniper Před 2 lety +1

    wouldn't it throw an error if there are only less than 7 points within the strip? The program would be accessing a an array index greater than its length

  • @AgeOfNerds
    @AgeOfNerds Před 2 lety

    thank you! Very well explained!

  • @soyei
    @soyei Před 2 měsíci

    great explanation, thank you

  • @kenz7788
    @kenz7788 Před 2 lety

    the best explanation ever

  • @storiesshubham4145
    @storiesshubham4145 Před 8 měsíci

    Great explanation mam.

  • @ghostwar9103
    @ghostwar9103 Před 7 měsíci

    how did you find delta in 6,8 do you brute force the left and the right with out divide it ?

  • @l501l501l
    @l501l501l Před rokem

    Pretty clear. Thank you.

  • @potzko2552
    @potzko2552 Před rokem

    this is such a good and clear explanation, do you mind if I use it for teaching?

  • @shubhbhalla3850
    @shubhbhalla3850 Před rokem

    Great explanation !

  • @Gintoki.Sakata918
    @Gintoki.Sakata918 Před 2 lety

    Please make more videos🥲
    If possible please create a whole series of your lectures.

  • @Japo0po0
    @Japo0po0 Před 2 měsíci

    Best explanation, bar none

  • @onurbaran4016
    @onurbaran4016 Před 4 měsíci

    For split pairs why we iterating 1 to 7?

  • @kirby0918
    @kirby0918 Před 2 lety +4

    Great explanation, thank you! But I think the time complexity of pseudo code provided isn't obviously O(n log n) due to the step of selecting S from whole Y. Since you pass the whole Y in each call, the "n" isn't split into halves when recursion, but n -> 2n -> 4n -> ... where n is the length of X. I think it could be done in O(n) by merging the Y-sorted sub-arrays from divided problems.

    • @skarasavvidis
      @skarasavvidis Před 8 měsíci

      yes, this is correct. The recursive calls must be made with 2 modified Ys. One for the left points and one for the right. Or, as you suggest, by merging the points. To merge them, you would need to return not only d, but also the points merged by y coordinate

  • @jonathanguzman8584
    @jonathanguzman8584 Před rokem

    God Bless you, you are great

  • @1arpaxad
    @1arpaxad Před 3 měsíci

    I think it's enough to iterate j from 1 to 4 because in each side the maximum number of points is 4

  • @JoeBaloney
    @JoeBaloney Před 9 měsíci +1

    5:57 Why for j=1 to 7? what's the 7 about?

  • @Zaznobable
    @Zaznobable Před rokem

    thanks a lot for your explanation

  • @MoreCRNonYT
    @MoreCRNonYT Před 9 měsíci

    Thank you! :D

  • @filz4461
    @filz4461 Před 2 lety

    Can you do more videos, please?

  • @alihsanelmas
    @alihsanelmas Před 2 lety

    Well explained!

  • @ngchongpeng
    @ngchongpeng Před měsícem

    i have a question. does the question assume there are coincident points? if coincident points arent allowed, then when checking in the 2d * d rectangle, can we just check for the next 5 points instead of 7? since coincident points will not happen. thanks.

  • @tanvirtanvir6435
    @tanvirtanvir6435 Před rokem

    3:35 2-delta distance
    4:08 2d*d O(1) for each point

  • @KaranDoshicool
    @KaranDoshicool Před 2 lety

    best explanation

  • @alanye7542
    @alanye7542 Před rokem

    Thank you!

  • @user-pq2ui9mf5v
    @user-pq2ui9mf5v Před 7 měsíci

    講的很好!😊

  • @hashirkz
    @hashirkz Před 2 lety

    tysm it makes so much more sense now lol

  • @MayankKumar03
    @MayankKumar03 Před 2 lety +10

    Thank you so much for such a nice explanation :))

  • @VikashKumar-tr9cq
    @VikashKumar-tr9cq Před rokem

    Code in c++ :
    #include
    #include
    using namespace std;
    bool compare(paira , pairb)
    {
    return a.second=e)return LONG_MAX;
    if(e-s+1==2)
    {
    long d = dis(x[e],x[s] ) ;
    return d ;
    }

    int mid = (s+e)/2 ;

    long l = fun(x, s, mid) ;
    long r = fun(x,mid+1 , e ) ;
    long d = min(l,r) ;
    vector arr ;
    for(int i =s ; i= x[mid].first-d and x[i].first n;

    pair* arr = new pair[n];
    for(int i = 0; i < n; ++i)
    {
    cin >> arr[i].first >> arr[i].second;
    }
    cout

  • @rezachitsaz4923
    @rezachitsaz4923 Před 2 lety

    thanks. useful.

  • @varaprasad10
    @varaprasad10 Před rokem

    thank you

  • @vatg2001
    @vatg2001 Před 2 lety

    Thanks

  • @spiridiant
    @spiridiant Před 5 měsíci

    感恩

  • @advaitanand2524
    @advaitanand2524 Před 3 lety +2

    Can we expect some more videos?

  • @darshanbhaiya8711
    @darshanbhaiya8711 Před 3 měsíci

    Great Explanation but i have not understood clearly

  • @ammaralmarzooq5764
    @ammaralmarzooq5764 Před rokem

    الله يدخلش الجنة يارب

  • @MahdeeMushfiqueKamal
    @MahdeeMushfiqueKamal Před 3 lety +6

    Peeps who are here for BUET-18's offline-8 comment here

  • @azmainfaiak8111
    @azmainfaiak8111 Před 7 měsíci

    3:55
    7 points explanation

  • @averagestanduser6967
    @averagestanduser6967 Před 4 měsíci

    W vid

  • @udaykiran1390
    @udaykiran1390 Před 3 lety +1

    First of all i was on a thought she will definitely waste my time but u nailed it 🔥

  • @Adityarm.08
    @Adityarm.08 Před rokem

    8:00 Y sorted points also need to be halved before recursion to ensure optimal complexity, right? This can be done via (id) based filtering of Y into Y_left & Y_right based on a HashSet representation of what goes into X_left & X_right.
    Am I missing something? Great explanation otherwise :)

  • @joelwillis2043
    @joelwillis2043 Před 3 měsíci

    now find the optimal solution for N-dimensional Euclidean space.

  • @ZihanLiu-vq2lt
    @ZihanLiu-vq2lt Před měsícem

    牛逼 上课没听懂在你这里听懂了

  • @wizrom3046
    @wizrom3046 Před rokem

    Who told you the brute force solution was n squared?
    Once a test has been performed, it can be tagged as done. Then that pair test does not need to be done again.
    Consider 4 points; 1,2 3,4
    1 needs to test 2,3,4
    2 only needs to test 3,4 (because 1,2 test is already done))
    3 only needs to test 4
    That is only 6 tests need to be performed, not 16 (n squared)
    Formula is probably factorial n...
    Please get gour facts right!

    • @iDeer70
      @iDeer70  Před rokem

      Consider 5 points, 100 points, 10000 points, and let me know if you still think the formula is factorial n (hint: sum of arithmetic sequence).
      Then please get your fact right about Big O Notation! Keep in mind that constants are dropped when calculating time complexity.

    • @marceloenciso6665
      @marceloenciso6665 Před rokem

      In that case the running time would be something like n(n-1) + (n-1)(n-2) + ... + (n-k+1)(n-k) = (n^2-n) + (n^2-3n+2) + (n^2+(1-2k)n+(k^2-k)) = kn^2 + a. Where a is the sum of other lower power terms. Since big O notation drops those lower terms and constants we get that big o notation is n^2.

    • @wizrom3046
      @wizrom3046 Před rokem

      @@marceloenciso6665 agreed, sorry its not factorial, the formula for total number of tests is;
      (n squared -n) /2
      So the total number of tests will always be less than HALF of n squared
      Anyway this divide and conquer method it still a poor way of solving the problem.
      Doing all those square roots is a real mess. This is how I would do it for least amount of CPU cycles;
      1. Brute force all points but only testing points AFTER the point. (N squared -n) /2 tests;
      1a. Get the x dist and y dist (very fast, just 2 subtractions needed)
      1b. keep the larger of the two, very fast (we will call this the simple distance)
      1c. Put the simple distance in a list, ordered by size (very fast)
      TRICK; The actual distance can never be more than the simple distance *1.41 so only need to test those list entries that are LESS then the smallest entry *1.41
      Now we are only needeing to do the mults and sq roots on a tiny percentage of the point pairs;
      2. Process down the ranked list;
      2a. Do the pythag mult mult sq root etc to get real dist
      2b. If less than prev best, save that as best
      2c. If the list entry is >top entry *1.41 then job is done!
      Ive been coding high perf algorithms for 30 years and mostly had to do it on low perf 8bit systems with no math processor etc. The algorithm I outlined above is just my first attempt but would be far quicker than the divide and conquer system provided that n is not excessively large.

    • @wizrom3046
      @wizrom3046 Před rokem

      Ok, i just wrote some quick c code to test my algorithm.
      n = 100 points, randomly distributed x and y values using; random(1024)
      Brute force ranked point distances by my "simple distance" ie the largest of x1-x2 or y1-y2 (4950 tests)
      Then ONLY needed to do the pythag mult sqroot etc on ANY points where; simple dist

    • @dontplsgx7934
      @dontplsgx7934 Před rokem

      @@wizrom3046
      You should really learn about big O notation before saying anything.
      (n squared - n) / 2 -> (n^2) /2 - n/2 -> n^2*1/2 - n*1/2
      When we calculate big O notation, we only care about the *dominant terms* and we do not care about the coefficients. Thus we take the n squared as our final big O (in this case n^2 is the dominant term and you can eliminate all the other parts in the big O notation).