Counting inversions using merge sort

Sdílet
Vložit
  • čas přidán 21. 06. 2017

Komentáře • 8

  • @Kasper-ev3zh
    @Kasper-ev3zh Před 5 lety +2

    Thanks, helped me visualize how this algorithm works!

    • @rambhaktsharma
      @rambhaktsharma  Před 5 lety +1

      Welcome. Please have a look at my other videos too

  • @twahirabasi9765
    @twahirabasi9765 Před 7 lety +1

    Thanks, would you do tree traversals, matrix computations, gausian eliminations Using parallel programming approach?

    • @rambhaktsharma
      @rambhaktsharma  Před 7 lety

      Twahir Abasi appreciate your suggestions .. will try to do in future.

  • @muhammadmuslimsaher7316

    Too much jerks are causing headache

  • @sengao7062
    @sengao7062 Před 6 lety

    may I know why it is n/2-i ,why it isn't just plus 1?

    • @ryashaum
      @ryashaum Před 5 lety

      it's not just a single pair

    • @amirtoliyat3965
      @amirtoliyat3965 Před 5 lety +1

      n is the number of the original list, which we divided by 2. So we have 2 lists. we sort each list recursively by merge sort and the size of each is n/2. Now we compare each member of list A by list B for merge and counting inversions. if ai is smaller than bi then we don't have an inversion but if it is greater then we should swap and we have an inversion. for example, imagine a3(which is ai) is greater than b4, so it means a3,a4,..,an/2 are greater than b4. so the number of inversions(which is related to a3) is (n/2)-3 because until i (which is3), we didn't have any inversion(or we counted before).