SlideServe
Menu
Préférences
© SlideServe · v2026

Merge and Count

valeriei avatar
24 diapositives · 272 Views · Jan 05, 2020

Merge and Count. Merge and count step. Given two sorted halves, count number of inversions where a i and a j are in different halves. Combine two sorted halves into sorted whole. i = 6. 3. 7. 10. 14. 18. 19. 2. 11. 16. 17. 23. 25. two sorted halves. auxiliary array. Total:.

Merge and Count - slide 1
01 / 24Merge and Count
1 / 17

Télécharger la présentation

Merge and Count
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. 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 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves auxiliary array Total:

  2. 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 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 auxiliary array Total: 6

  3. 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 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 auxiliary array Total: 6

  4. 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 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 3 auxiliary array Total: 6

  5. 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 = 5 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 3 auxiliary array Total: 6

  6. 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 = 5 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 3 7 auxiliary array Total: 6

  7. 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 = 4 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 3 7 auxiliary array Total: 6

  8. 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 = 4 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 3 7 10 auxiliary array Total: 6

  9. 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 = 3 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 2 3 7 10 auxiliary array Total: 6

  10. 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 = 3 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 3 7 10 11 auxiliary array Total: 6 + 3

  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 = 3 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 3 7 10 11 auxiliary array Total: 6 + 3

  12. 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 = 3 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 3 7 10 11 14 auxiliary array Total: 6 + 3

  13. 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 = 2 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 3 7 10 11 14 auxiliary array Total: 6 + 3

  14. 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 = 2 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 3 7 10 11 14 16 auxiliary array Total: 6 + 3 + 2

  15. 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 = 2 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 3 7 10 11 14 16 auxiliary array Total: 6 + 3 + 2

  16. 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 = 2 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 2 3 7 10 11 14 16 17 auxiliary array Total: 6 + 3 + 2 + 2

  17. 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 = 2 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 2 3 7 10 11 14 16 17 auxiliary array Total: 6 + 3 + 2 + 2

  18. 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 = 2 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 2 3 7 10 11 14 16 17 18 auxiliary array Total: 6 + 3 + 2 + 2

  19. 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 = 1 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 2 3 7 10 11 14 16 17 18 auxiliary array Total: 6 + 3 + 2 + 2

  20. 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 = 1 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 2 3 7 10 11 14 16 17 18 19 auxiliary array Total: 6 + 3 + 2 + 2

  21. 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. first half exhausted i = 0 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 2 3 7 10 11 14 16 17 18 19 auxiliary array Total: 6 + 3 + 2 + 2

  22. 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 = 0 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 0 2 3 7 10 11 14 16 17 18 19 23 auxiliary array Total: 6 + 3 + 2 + 2 + 0

  23. 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 = 0 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 0 0 2 3 7 10 11 14 16 17 18 19 23 25 auxiliary array Total: 6 + 3 + 2 + 2 + 0 + 0

  24. 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 = 0 3 7 10 14 18 19 2 11 16 17 23 25 two sorted halves 6 3 2 2 0 0 2 3 7 10 11 14 16 17 18 19 23 25 auxiliary array Total: 6 + 3 + 2 + 2 + 0 + 0 = 13