[1, 5, 10, 20, 50, 100, 500]
[0] [1] [2] [3] [4] [5] [6]
✉✉✉✉✉✉✉
for each from left to right if 50 is in the return true return false
for each from left to right if 50 is in the return true else return false
for i from 0 to n-1 if 50 is in s[i] return true return false
# Assuming the numbers are sorted if 50 is in middle return true
# Assuming the numbers are sorted if 50 is in middle return true else if 50 < middle search left half else if 50 > middle search right half
# Assuming the numbers are sorted if no return false if 50 is in middle return true else if 50 < middle search left half else if 50 > middle search right half
# Assuming the numbers are sorted if no return false if 50 is in s[middle] return true else if 50 < s[middle] search s[0] through s[middle - 1] else if 50 > s[middle] search s[middle + 1] through s[n - 1]
O()
O() linear search
O() binary search
Ω
Ω()
Ω() linear search, binary search
Θ
[7 2 5 4 1 6 0 3]
[0 1 2 3 4 5 6 7]
[7, 2, 5, 4, 1, 6, 0, 3]
for i from 0 to n-1 find smallest number between numbers[i] and numbers[n-1] swap smallest number with numbers[i]
O() selection sort
Ω() selection sort
Θ() selection sort
Θ()
repeat n-1 times for i from 0 to n-2 if numbers[i] and numbers[i+1] out of order swap the two
O() bubble sort
repeat n-1 times for i from 0 to n-2 if numbers[i] and numbers[i+1] out of order swap the two if no swaps quit
Ω() bubble sort
# Assuming the numbers are already sorted if no return false if 50 is in middle return true else if 50 < middle search left half else if 50 > middle search right half
# Assuming the numbers are already sorted if no return false if 50 is in middle return true else if 50 < middle search left half # could use recursion else if 50 > middle search right half # could use recursion
if only one number quit else sort left half of numbers sort right half of numbers merge sorted halves
7 | 2 | 5 | 4 | 1 | 6 | 0 | 3
2 7 | 4 5 | 1 6 | 0 3
2 4 5 7 | 0 1 3 6
0 1 2 3 4 5 6 7
O() merge sort
Ω() merge sort
Θ() merge sort
The O notation (Big O) is used to represent the upper bound of an algorithm's running time, often in the worst-case scenario.
The Ω notation (Big Omega) is used to represent the lower bound of an algorithm's running time, often in the best-case scenario.
The Θ notation (Theta) is used to represent the precise or tight-bound complexity of an algorithm, capturing both upper and lower bounds, indicating that the algorithm's performance is consistently close to this bound.