03 O-Notation, Laufzeit und Komplexität - Medieninformatik
03 O-Notation, Laufzeit und Komplexität - Medieninformatik
03 O-Notation, Laufzeit und Komplexität - Medieninformatik
Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.
YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.
Lineare Suche – Bester Fall<br />
●<br />
●<br />
●<br />
●<br />
Eingabe<br />
– s = a[0]<br />
Analyse<br />
– Zuweisung<br />
– Schleife einmal mit<br />
● Vergleich<br />
● Feldzugriff<br />
● Vergleich<br />
– Rückgabe<br />
Anzahl Schritte<br />
– 1 + 3 + 1 = 2 + 3 = 5 Schritte<br />
Bester Fall<br />
– Immer 5 Schritte<br />
– Unabhängig von Feldgröße<br />
a<br />
s<br />
2 3 5 7 11 13 17 19 23 29<br />
2<br />
0 1 2 3 4 5 6 7 8 9<br />
# Lineare Suche<br />
pos = 0<br />
while pos < n and a[pos] != s:<br />
pos = pos+1<br />
return pos<br />
Prof. Dr. Peter Barth<br />
<strong>Medieninformatik</strong> Algorithmen <strong>und</strong> Datenstrukturen 10