Download - Merge and Count Algorithm
![Page 1: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/1.jpg)
1
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
auxiliary array
Total:
i = 6
![Page 2: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/2.jpg)
2
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
i = 6
two sorted halves
2 auxiliary array
Total: 6
6
![Page 3: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/3.jpg)
3
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
2 auxiliary array
i = 6
Total: 6
6
![Page 4: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/4.jpg)
4
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
2 3 auxiliary array
i = 6
Total: 6
6
![Page 5: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/5.jpg)
5
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
2 3 auxiliary array
i = 5
Total: 6
6
![Page 6: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/6.jpg)
6
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
72 3 auxiliary array
i = 5
Total: 6
6
![Page 7: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/7.jpg)
7
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
72 3 auxiliary array
i = 4
Total: 6
6
![Page 8: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/8.jpg)
8
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 102 3 auxiliary array
i = 4
Total: 6
6
![Page 9: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/9.jpg)
9
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 102 3 auxiliary array
i = 3
Total: 6
6
![Page 10: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/10.jpg)
10
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 112 3 auxiliary array
i = 3
Total: 6 + 3
6 3
![Page 11: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/11.jpg)
11
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 112 3 auxiliary array
i = 3
Total: 6 + 3
6 3
![Page 12: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/12.jpg)
12
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 auxiliary array
i = 3
Total: 6 + 3
6 3
![Page 13: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/13.jpg)
13
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 auxiliary array
i = 2
Total: 6 + 3
6 3
![Page 14: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/14.jpg)
14
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 16 auxiliary array
i = 2
Total: 6 + 3 + 2
6 3 2
![Page 15: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/15.jpg)
15
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 16 auxiliary array
i = 2
Total: 6 + 3 + 2
6 3 2
![Page 16: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/16.jpg)
16
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 16 17 auxiliary array
i = 2
Total: 6 + 3 + 2 + 2
6 3 2 2
![Page 17: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/17.jpg)
17
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 16 17 auxiliary array
i = 2
Total: 6 + 3 + 2 + 2
6 3 2 2
![Page 18: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/18.jpg)
18
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 1816 17 auxiliary array
i = 2
Total: 6 + 3 + 2 + 2
6 3 2 2
![Page 19: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/19.jpg)
19
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 1816 17 auxiliary array
i = 1
Total: 6 + 3 + 2 + 2
6 3 2 2
![Page 20: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/20.jpg)
20
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 18 1916 17 auxiliary array
i = 1
Total: 6 + 3 + 2 + 2
6 3 2 2
![Page 21: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/21.jpg)
21
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 18 1916 17 auxiliary array
i = 0
Total: 6 + 3 + 2 + 2
first half exhausted
6 3 2 2
![Page 22: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/22.jpg)
22
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 18 19 2316 17 auxiliary array
i = 0
Total: 6 + 3 + 2 + 2 + 0
6 3 2 2 0
![Page 23: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/23.jpg)
23
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 18 19 2316 17 auxiliary array
i = 0
Total: 6 + 3 + 2 + 2 + 0
6 3 2 2 0
![Page 24: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/24.jpg)
24
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 18 19 23 2516 17 auxiliary array
i = 0
Total: 6 + 3 + 2 + 2 + 0 + 0
6 3 2 2 0 0
![Page 25: Merge and Count Algorithm](https://reader033.vdocuments.us/reader033/viewer/2022052619/557037d3d8b42a611e8b4c26/html5/thumbnails/25.jpg)
25
10 14 18 193 7 16 17 23 252 11
Merge and Count
Merge and count step. Given two sorted halves, count number of inversions where ai
and aj are in different halves. Combine two sorted halves into sorted whole.
two sorted halves
7 10 11 142 3 18 19 23 2516 17 auxiliary array
i = 0
Total: 6 + 3 + 2 + 2 + 0 + 0 = 13
6 3 2 2 0 0