Sortieralgorithmen Flashcards

1
Q

Selection-Sort

A
def selectionSort(liste):
    l = len(liste)
    for i in range(l):
        min = i
        for j in range(i+1,l):
            if liste[j] < liste[min]: min = j
            tausche(liste, i, min)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Selection-Sort Laufzeit

A

Best Case: 1/2 N^2
Mittel: 1/2 N^2
Worst Case: 1/2 N^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Insertion Sort Laufzeit

A

Best Case: N
Mittel: 1/4 N^2
Worst Case: 1/2 N^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Mergesort Laufzeit

A

Best Case: 1/2 N lg N
Mittel: N lg N
Worst Case: N lg N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Quicksort-Laufzeit

A

Best Case: N lg N
Mittel: 2N ln N
Worst Case: 1/2 N^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Sort Implementierung (Mergesort)

A
def sortPart(a, lo, hi, aux):
   if hi <= lo: return
   mid = (lo + hi) // 2
   sortPart(a, lo, mid, aux)
   sortPart(a, mid+1, hi, aux)
   merge(a, lo, mid, hi, aux)

def mergeSort(a):
   n = len(a)
   aux = [0] * n
   sortPart(a, 0, n-1, aux)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Merge Implementierung

A
def merge(a, lo, mid, hi, aux):
    aux[lo:hi+1] = a[lo:hi+1]
    i = lo
    j = mid+1
    for k in range(lo, hi+1):
        if i > mid:
            a[k] = aux[j]
            j += 1
        elif j > hi:
            a[k] = aux[i]
            i += 1
        elif aux[j] < aux[i]:
            a[k] = aux[j]
            j += 1
        else:
            a[k] = aux[i]
            i += 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Insertion Sort

A
def insertionSort(liste):
    l = len(liste)
    for i in range(1,l):
        j = i
        while (j > 0) and (liste[j] < liste[j-1]):
            tausche(liste, j, j-1)
            j -= 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Selection Sort Tausch

A

Selection Sort benötigt N Austausch Operationen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Insertion Sort Tausch

A

Es werden 1/4 N^2 Austausch Operationen benötigt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Definition: Stabil

A

Ein Sortieralgorithmus ist stabil wenn er die Reihenfolgen von gleichen Elementen während der Sortierung nicht vertauscht.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly