Count Inversions in an array | Set 1 (Using Merge Sort) | GeeksforGeeks

Sdílet
Vložit
  • čas přidán 7. 03. 2017
  • Explanation for the article: www.geeksforgeeks.org/counting...
    This video is contributed by Harshit Jain.

Komentáře • 47

  • @AnhTu-en9gk
    @AnhTu-en9gk Před 3 lety +8

    This is awesome. I come here from an algorithm course from Stanford. Your explanation is clearer.

  • @GeeksforGeeksVideos
    @GeeksforGeeksVideos  Před 7 lety +23

    Correction at 05:58 --> "the index of element 3 is smaller than the index of element 2."
    Correction at 10:53 --> "Time Complexity for Simple Method is O(n^2)." [It can also be written as O(n*n)]

  • @deniz.7200
    @deniz.7200 Před 11 měsíci +1

    Thanks for the video, should we also count the inversion happened before merge started??

  • @goutamkundu6392
    @goutamkundu6392 Před 7 lety +5

    in the video 08.50 it is "we add the inversion count returned by these two respective calls to inversion count variable". But I am seeing only in the last call inv_count += _mergeSort(arr,temp,mid+1,right) is there

    • @GeeksforGeeksVideos
      @GeeksforGeeksVideos  Před 7 lety +4

      Thanks for pointing it out, Goutam. You're right, it's a typo. There should be a plus sign there. The statement should look like this:
      inv_count += _mergeSort(arr, temp, left, mid);

  • @ceciliaw1065
    @ceciliaw1065 Před rokem +1

    Amazing amazing explanation with examples, thank you so much

  • @lovleshbhatt7797
    @lovleshbhatt7797 Před 4 lety +16

    Please increase the volume level, its quite less for hearing & understanding

  • @maximilianoromayfigueroa1815

    thanks for the awesome video, I learned a lot and in a very short period of time ;)

  • @davemustainejigsaw
    @davemustainejigsaw Před 7 lety

    hi,
    the method 1 described in the code , shouldn't the condition be if((arr[i] > arr[j])&&(i

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

    Nice explanation. Liked it.

  • @danielhazel7205
    @danielhazel7205 Před rokem

    does this work for duplicate numbers in an array?

  • @tanishqupadhayay1350
    @tanishqupadhayay1350 Před 4 lety +1

    why do we add mid-i to inv_count??

  • @alieser7770
    @alieser7770 Před 5 lety +2

    you are the best!!!

  • @ariabanazadeh1016
    @ariabanazadeh1016 Před 4 lety +1

    just amazing

  • @kautukraj
    @kautukraj Před 4 lety +1

    Very helpful!

  • @MisterAadj
    @MisterAadj Před 4 lety +5

    geek4geeks u guys awesome

  • @subham-raj
    @subham-raj Před 4 lety +4

    Why did you take "temp" array?

    • @pranavsingh9284
      @pranavsingh9284 Před 2 lety

      Merge karenge to extra , to merged to temp le lete apan kyu ki inplace merging nhi kr sakte

  • @AdeshPaul
    @AdeshPaul Před 4 lety +1

    Samjhane ke liye dhanyavaad.
    kya aap yeh bta sakte hain ki agar merge sort aur enhanced merge sort ki same time complexities hain to dono me se konsi behtar hai?
    Agrim Dhanyavaad.

    • @shubhamlahoti9758
      @shubhamlahoti9758 Před 4 lety +1

      enhanced one is just for the purpose of counting inversions in array

  • @lalithsamanthapuri932
    @lalithsamanthapuri932 Před 7 lety +3

    Thanks a Lot Sir..

  • @abhishek_sengupta
    @abhishek_sengupta Před 4 lety

    Thanks a lot!!!

  • @MadhuKumari-gy7uz
    @MadhuKumari-gy7uz Před 3 lety

    Cleared my concept, thanks brother

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

    I am unable to dry run the following two lines of code
    inv_count += _mergeSort(arr, temp, left, mid);
    inv_count += _mergeSort(arr, temp, mid + 1, right);
    in _mergesort. Pls help

    • @dsadaddy8403
      @dsadaddy8403 Před 2 lety

      share the full code then only we can
      answer

  • @adithyabhat4770
    @adithyabhat4770 Před 4 lety

    Thank you so much for the video!

  • @_-ghost-_711
    @_-ghost-_711 Před 5 lety

    If I want to print the elements in inversion, then what will be the time complexity.....

  • @vineetkothari2839
    @vineetkothari2839 Před 7 lety

    nice

  • @kurdi_x5842
    @kurdi_x5842 Před 2 lety

    thamk you helped me alot

  • @soumelee5661
    @soumelee5661 Před rokem

    4:14 how to get number of inversions ✔✔✅✅
    4:58 examples

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

    I came after seeing today gfg potd question :)

  • @67_ujjwalsolanki78
    @67_ujjwalsolanki78 Před rokem

    number of likes represent the number of times I fell asleep watching this

  • @tingzhao3931
    @tingzhao3931 Před rokem

    nice vid

  • @delyartabatabai9636
    @delyartabatabai9636 Před 2 lety

    This is CLRS problem 2-4

  • @karthikshetty3851
    @karthikshetty3851 Před 2 lety

    It doesnt clear all test Cases

  • @rupakdas7161
    @rupakdas7161 Před 2 měsíci +1

    Worst explanation I have ever seen of an algorithm and just reading the lines of code no dry run how can a beginer understand without doing a dry run

  • @youtube_username_
    @youtube_username_ Před 3 lety +4

    It bothers me that he starts talking about mid as if we're supposed to know what mid is.

    • @FaizaanDatoo
      @FaizaanDatoo Před 3 lety

      For a more thorough description, I recommend consulting Kleinberg and Tardos: Algorithm Design (the PDF is one of the first results on Google). The relevant text is Chapter 5 - Divide and Conquer, and the section is 5.3 - Counting Inversions. This video helped me understand that section, but I wouldn't have been able to figure it out without both the text and the video.

  • @shreyaskulkarni9994
    @shreyaskulkarni9994 Před 3 lety

    Why is he whispering? So annoying

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

    boring