Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Merge Sort

734db8ec0a1532dbf3b8a818267449bc?s=47 KuoE0
March 05, 2013

Merge Sort

734db8ec0a1532dbf3b8a818267449bc?s=128

KuoE0

March 05, 2013
Tweet

More Decks by KuoE0

Other Decks in Programming

Transcript

  1. Merge Sort ֲࢸݢʢKuoE0ʣ KuoE0.tw@gmail.com KuoE0.ch

  2. Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://creativecommons.org/licenses/by-sa/3.0/ Latest update: Mar

    6, 2013
  3. Traditional Merge Sort

  4. Algorithm ࠾༻ divide & conquer ࡦུ

  5. Divide ሡᙛલᏐྻሣ൒੾ׂᬇ᫮ਐߦ ௚౸ᷮႫҰݸݩૉ

  6. 2 9 4 3 8 7 5 1 6 2

    9 4 3 8 7 5 1 6 2 9 4 3 8 7 5 1 6 2 9 4 8 3 5 7 6 1 9 2
  7. Conquer 1. ར༻ၷݸࢦඪࢦ޲ၷݸ༗ংᏐྻ A ᢛ B 2. ൺֱࢦඪࢦ޲తᏐ值 3. ሡֱখతᏐ值์ೖ৽తᏐྻ

    Cɼฒሡ֘ࢦඪ ࢦ޲ԼҰᏐ值 4. ௚౸๭Ұࢦඪࢦ޲Ꮠྻ݁ඌɼሡ㠥ҰᏐྻႫ ᰨతᏐ值์౎ೖᏐྻ C
  8. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  9. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  10. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  11. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  12. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  13. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  14. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  15. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  16. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  17. Merge Two Sequence 9 8 7 6 5 4 3

    2 1
  18. 1 2 3 4 5 6 7 8 9 2

    3 4 8 9 1 5 6 7 2 4 9 3 8 5 7 1 6 2 9 4 8 3 5 7 6 1 9 2
  19. Natural Merge Sort

  20. Key Point ར༻Ꮠྻதత༗ংᏐྻยஈɼҎݮগ੾ׂ࣍Ꮠʂ

  21. ༗ংᏐྻยஈ 1 3 4 2 7 9 8 0 5

    1 3 4 2 7 9 8 0 5
  22. How to Divide 1 3 4 2 7 9 8

    0 5 A B
  23. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1
  24. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1
  25. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3
  26. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3
  27. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4
  28. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4
  29. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4
  30. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2
  31. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2
  32. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7
  33. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7
  34. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9
  35. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9
  36. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9
  37. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8
  38. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8
  39. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8 8
  40. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8 8 0
  41. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8 8 0
  42. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8 8 0 5
  43. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8 8 0 5
  44. How to Divide 1 3 4 2 7 9 8

    0 5 A B 1 3 4 1 3 4 2 7 9 2 7 9 8 8 0 5 0 5
  45. The merge operation is as same as traditional merge sort.

  46. End