Download presentation
Presentation is loading. Please wait.
Published byBonnie Nash Modified over 9 years ago
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 halves. n Combine two sorted halves into sorted whole. two sorted halves auxiliary array Total: i = 6
2
2 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. i = 6 two sorted halves 2 auxiliary array Total: 6 6 Counting Inversions
3
3 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 2 auxiliary array i = 6 Total: 6 6 Counting Inversions
4
4 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 23 auxiliary array i = 6 Total: 6 6 Counting Inversions
5
5 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 23 auxiliary array i = 5 Total: 6 6 Counting Inversions
6
6 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 723 auxiliary array i = 5 Total: 6 6 Counting Inversions
7
7 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 723 auxiliary array i = 4 Total: 6 6 Counting Inversions
8
8 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 71023 auxiliary array i = 4 Total: 6 6 Counting Inversions
9
9 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 71023 auxiliary array i = 3 Total: 6 6 Counting Inversions
10
10 1418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 7101123 auxiliary array i = 3 Total: 6 + 3 63 Counting Inversions
11
11 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 7101123 auxiliary array i = 3 Total: 6 + 3 63 Counting Inversions
12
12 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 710111423 auxiliary array i = 3 Total: 6 + 3 63 Counting Inversions
13
13 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 710111423 auxiliary array i = 2 Total: 6 + 3 63 Counting Inversions
14
14 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 71011142316 auxiliary array i = 2 Total: 6 + 3 + 2 632 Counting Inversions
15
15 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 71011142316 auxiliary array i = 2 Total: 6 + 3 + 2 632 Counting Inversions
16
16 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 7101114231617 auxiliary array i = 2 Total: 6 + 3 + 2 + 2 6322 Counting Inversions
17
17 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 7101114231617 auxiliary array i = 2 Total: 6 + 3 + 2 + 2 6322 Counting Inversions
18
18 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 710111423181617 auxiliary array i = 2 Total: 6 + 3 + 2 + 2 6322 Counting Inversions
19
19 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 710111423181617 auxiliary array i = 1 Total: 6 + 3 + 2 + 2 6322 Counting Inversions
20
20 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 71011142318191617 auxiliary array i = 1 Total: 6 + 3 + 2 + 2 6322 Counting Inversions
21
21 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 71011142318191617 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 first half exhausted 6322 Counting Inversions
22
22 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 7101114231819231617 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 6322 0 Counting Inversions
23
23 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 710111423181923251617 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 + 0 6322 0 0 Counting Inversions
24
24 101418193716172325211 Merge and count step. n Given two sorted halves, count number of inversions where a i and a j are in different halves. n Combine two sorted halves into sorted whole. two sorted halves 710111423181923251617 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 + 0 = 13 6322 0 0 Counting Inversions
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.