![Page 1: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/1.jpg)
1
10 14 18 193 7 16 17 23 252 11
Counting Inversions
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: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/2.jpg)
2
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 3: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/3.jpg)
3
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 4: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/4.jpg)
4
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 5: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/5.jpg)
5
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 6: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/6.jpg)
6
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 7: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/7.jpg)
7
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 8: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/8.jpg)
8
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 9: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/9.jpg)
9
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 10: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/10.jpg)
10
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 11: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/11.jpg)
11
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 12: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/12.jpg)
12
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 13: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/13.jpg)
13
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 14: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/14.jpg)
14
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 15: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/15.jpg)
15
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 16: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/16.jpg)
16
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 17: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/17.jpg)
17
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 18: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/18.jpg)
18
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 19: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/19.jpg)
19
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 20: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/20.jpg)
20
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 21: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/21.jpg)
21
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 22: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/22.jpg)
22
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 23: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/23.jpg)
23
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions
![Page 24: 1 101418193716172325211 Counting Inversions Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different](https://reader035.vdocuments.site/reader035/viewer/2022062716/56649dda5503460f94acfc45/html5/thumbnails/24.jpg)
24
10 14 18 193 7 16 17 23 252 11
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
Counting Inversions