0
Upcoming SlideShare
×

# Merge and Count Algorithm

288

Published on

Demonstration of Merge and Count algorithm by an example

Published in: Technology, Art & Photos
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
288
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript of "Merge and Count Algorithm"

1. 1. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves auxiliary array Total: i = 6
2. 2. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 i = 6 two sorted halves 2 auxiliary array Total: 6 6
3. 3. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 2 auxiliary array i = 6 Total: 6 6
4. 4. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 2 3 auxiliary array i = 6 Total: 6 6
5. 5. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 2 3 auxiliary array i = 5 Total: 6 6
6. 6. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 2 3 auxiliary array i = 5 Total: 6 6
7. 7. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 2 3 auxiliary array i = 4 Total: 6 6
8. 8. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 2 3 auxiliary array i = 4 Total: 6 6
9. 9. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 2 3 auxiliary array i = 3 Total: 6 6
10. 10. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 2 3 auxiliary array i = 3 Total: 6 + 3 6 3
11. 11. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 2 3 auxiliary array i = 3 Total: 6 + 3 6 3
12. 12. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 auxiliary array i = 3 Total: 6 + 3 6 3
13. 13. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 auxiliary array i = 2 Total: 6 + 3 6 3
14. 14. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 16 auxiliary array i = 2 Total: 6 + 3 + 2 6 3 2
15. 15. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 16 auxiliary array i = 2 Total: 6 + 3 + 2 6 3 2
16. 16. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 16 17 auxiliary array i = 2 Total: 6 + 3 + 2 + 2 6 3 2 2
17. 17. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 16 17 auxiliary array i = 2 Total: 6 + 3 + 2 + 2 6 3 2 2
18. 18. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 16 17 auxiliary array i = 2 Total: 6 + 3 + 2 + 2 6 3 2 2
19. 19. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 16 17 auxiliary array i = 1 Total: 6 + 3 + 2 + 2 6 3 2 2
20. 20. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 19 16 17 auxiliary array i = 1 Total: 6 + 3 + 2 + 2 6 3 2 2
21. 21. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 19 16 17 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 first half exhausted 6 3 2 2
22. 22. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 19 23 16 17 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 6 3 2 2 0
23. 23. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 19 23 16 17 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 6 3 2 2 0
24. 24. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 19 23 25 16 17 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 + 0 6 3 2 2 0 0
25. 25. Merge and Count <ul><li>Merge and count step. </li></ul><ul><ul><li>Given two sorted halves, count number of inversions where a i and a j are in different halves. </li></ul></ul><ul><ul><li>Combine two sorted halves into sorted whole. </li></ul></ul>10 14 18 19 3 7 16 17 23 25 2 11 two sorted halves 7 10 11 14 2 3 18 19 23 25 16 17 auxiliary array i = 0 Total: 6 + 3 + 2 + 2 + 0 + 0 = 13 6 3 2 2 0 0
1. #### A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.