insertion sort
play

Insertion-Sort M. Esponda Insertion-Sort M. Esponda - PowerPoint PPT Presentation

Insertion-Sort M. Esponda Insertion-Sort M. Esponda Insertion-Sort M. Esponda Insertion-Sort <? M. Esponda Insertion-Sort M. Esponda Insertion-Sort M. Esponda Insertion-Sort M. Esponda Insertion-Sort M. Esponda Insertion-Sort


  1. Insertion-Sort M. Esponda

  2. Insertion-Sort M. Esponda

  3. Insertion-Sort M. Esponda

  4. Insertion-Sort <? M. Esponda

  5. Insertion-Sort M. Esponda

  6. Insertion-Sort M. Esponda

  7. Insertion-Sort M. Esponda

  8. Insertion-Sort M. Esponda

  9. Insertion-Sort <? M. Esponda

  10. Insertion-Sort <? M. Esponda

  11. Insertion-Sort <? M. Esponda

  12. Insertion-Sort M. Esponda

  13. Insertion-Sort M. Esponda

  14. Insertion-Sort <? M. Esponda

  15. Insertion-Sort <? M. Esponda

  16. Insertion-Sort M. Esponda

  17. Insertion-Sort M. Esponda

  18. Insertion-Sort <? M. Esponda

  19. Insertion-Sort <? M. Esponda

  20. Insertion-Sort <? M. Esponda

  21. Insertion-Sort <? M. Esponda

  22. Insertion-Sort M. Esponda

  23. Insertion-Sort Sortierter Bereich M. Esponda

  24. Insertion-Sort Sortierter Bereich M. Esponda

  25. Insertion-Sort verschoben M. Esponda

  26. Insertion-Sort Bester Fall Größer als alle Elemente auf der linken Seite Es ist kein weiterer Vergleich notwendig M. Esponda

  27. Insertion-Sort Kleiner als alle Elemente Schlimmster Fall der linken Seite M. Esponda

  28. Insertion-Sort Alle Elemente müssen verschoben werden M. Esponda

  29. Insertion-Sort M. Esponda

  30. Insertion-Sort M. Esponda

  31. Insertion-Sort isort :: [ Integer ] -> [ Integer ] isort [] = [] isort (a:x) = ins a (isort x) ins :: Integer -> [Integer] -> [Integer] ins a [] = [a] ins a (b:y) | a<= b = a:(b:y) | otherwise = b: (ins a y) Das Problem in Haskell ist vor allem der Speicherverbrauch M. Esponda

  32. Insertion-Sort (imperativ) Einfacher Sortieralgorithmus • In-Place und kein zusätzlicher Speicherbedarf O(1) • Stabil • gut für kleine Mengen oder leicht unsortierte Informationen def insertsort(seq): for j in range(1,len(seq)): key = seq[j] k = j-1; Eine geeignete Position while k>=0 and seq[k]>key: wird gesucht und die seq[k+1] = seq[k] Elemente des sortierten Bereichs verschoben k = k-1 Die einzusortierende seq[k+1] = key Zahl wird in den gefundenen Platz kopiert M. Esponda

  33. Insertion-Sort (imperativ) len(seq)-1 seq 3 1 7 2 0 6 5 9 4 8 3 1 7 def insertsort(seq): for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  34. Insertion-Sort (imperativ) j len(seq)-1 seq 3 1 7 2 0 6 5 9 4 8 3 1 7 def insertsort(seq): for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  35. Insertion-Sort (imperativ) j len(seq)-1 seq 3 1 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  36. Insertion-Sort (imperativ) j len(seq)-1 k seq 3 1 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  37. Insertion-Sort (imperativ) j len(seq)-1 k seq 3 1 7 2 0 6 5 9 4 8 3 1 7 >? key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  38. Insertion-Sort (imperativ) j len(seq)-1 k seq 3 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  39. Insertion-Sort (imperativ) j len(seq)-1 k seq 3 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  40. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  41. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 1 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  42. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 7 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  43. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 7 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  44. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 <? key def insertsort(seq): 7 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  45. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 7 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

  46. Insertion-Sort (imperativ) j len(seq)-1 k seq 1 3 7 2 0 6 5 9 4 8 3 1 7 key def insertsort(seq): 7 for j in range(1,len(seq)): key = seq[j] k = j-1; while k>=0 and seq[k]>key: seq[k+1] = seq[k] k = k-1 seq[k+1] = key M. Esponda

Recommend


More recommend