Algorithmen Flashcards
Clock Cycle
Is the time separating one process step of CPU from the next. The clock rate is corresponding frequency. Typical values are nowadays 0.3 ns and 3 GHz, respectively
Moore’s law
Is an empirical law stating that the power of CPUs increases by factor of 10 about every 6 years
Compiling a program
Translation of code into machine language, thereby producing a (binary) object file. The object file is just a translation of source file, it is not yet on its own executable
Liking a program
Will take all the objects files required by a program, possibly along with other object files gathered from libraries and uses these to produce a single file containing the executable program
A greedy algorithm
Solves a problem by always selecting the option yielding the largest immediate progress towards the goal
Rekursive Implementierung Struktur
Funktion deklarieren { If(n=1) Return 1; Abbruchbedingung Bsp Return n*funktion(n-1); Auch Bsp }
Sequential search Algorithmus
Falls kein Element gefunden wird retourniert 0
int sequentialSearch (int n[], int N, int goal) { for (int i=0; i
Sequential search „prigrammiertrick“
n[N] = goal setzen
Int SeqSearch (int n[], int N, int goal) { n[N]=goal; int i = 0 while (n[i] != goal) i++ Return i; }
Resultat wird immer gefunden
Was ist ein Binary search?
Wir nehemen das mittlere Element und vergleichen, ob der zu suchende Wert größer, kleiner oder gleich diesem ist.
Man benutzt Arrays
Binary search Bsp. Code
Int BinSeach (int n[], int N, int goal) { int left=0, right=N-1, middle; while (left <= right) { middle = (right + left) / 2; //integer division if (goal < n[middle]) right = middle - 1; else if (goal > n[middle]) left = middle + 1; else Return middle; } Return -1 }
Wie wird ein sorrieralgorithmus der gleiche Elemente nucht vertauscht genannt
Stable
Wie funktioniert ein Selection Sort Algorithmus (Prinzip)
- Suche aus dem Array das kleinste Element
- Lege diesen an den Anfang
- Suche aus dem (noch nicht sortieren) Rest wiederum das kleinste Element)
- etc.
Selection Sort Algorithmus
Void selSort (int n[], int N) { //repeat this step as long as there are elements to sort for (int i=0; i
Was ist due anzahl vergleiche beim Selection sort argorithmus?
N(N-1)/2
Was ist die Anzahl Tauschoperationen beim Selection Sort Algorithmus (worst case)
N-1