string read while getline(cin, str) read += str for i = 0 to read.size() if read[i] == '<' // process tag
string read while getline(cin, str) read += str for i = 0 to read.size() if read[i] == '<' // process tag read[i] = ' '
Constant | O(1) | array index |
Log | O(log n) | binary search |
Linear | O(n) | linear search |
Log-linear | O(n log n) | heapsort |
Quadratic, square | O(n2) | bubble sort |
|
|
|
| |||||||||||||
i = 0 while i < n j = i + 1 while j < n if a[i] > a[h] swap(a[i], a[j]) j++ i++
i = 0 while i < n j = i + 1 while j < n if a[i] > a[h] swap(a[i], a[j]) j++ i++
|
O(1) while i < n O(1) while j < n if a[i] > a[h] O(1) O(1) O(1)
|
if
statementif b s1 else s2
b
's cost.
if
Estimates
O(1) while i < n O(1) while j < n if a[i] > a[h] O(1) O(1) O(1)
|
O(1)
while i < n
O(1)
while j < n
O(1) + O(1) = O(1)
O(1)
O(1)
|
;
s2
|
|
O(1) while i < n O(1) while j < n O(1) O(1) O(1)
|
O(1) while i < n O(1) while j < n O(1) + O(1) = O(max(1, 1)) = O(1) O(1)
|
while b do s
s
has asymptotic estimate O(f).
s
gets executed some number of times.
b
.
O(1) while i < n O(1) while j < n O(1) O(1)
|
O(1) while i < n O(1) O(n)*(O(1) + O(1)) = O(n)*O(max(1, 1)) = O(n)*O(1) = O(n*1) = O(n) O(1)
|
O(1) while i < n O(1) O(n) O(1)
|
O(1) while i < n O(1) + O(n) + O(1) = O(max(1, n, 1) = O(n)
|
O(1) while i < n O(n)
|
O(1) O(n)*O(n) = O(n*n) = O(n2)
|
O(1) O(n2)
|
O(1) + O(n2) = O(max(1, n2)) = O(n2)
|
swap(a, b)
= O(1).
This page last modified on 27 January 2006. |
This work is covered by a |