Loading repository dataβ¦
Loading repository dataβ¦
Rustam-Z / repository
π Notes on Data Structures and Computer Algorithms
Lecture notes on Data Structures and Computer Algorithms
By Rustam Zokirov
NOTES ON COMPUTER ALGORITHMS - HERE
int takes
Efficiency measured in terms of TIME and SPACE. In terms of number of operations.
Asymptotic complexity
f(n) = running time of an algorithm, where n= input size. We are interested in the growth of n to calculate the f(n)3n, 5n, 100n => n, why?log(2) => ln(2)f(n) = O(n2) => describes how f(n) grows in comparison to n2
Big-O notation, Ξ© (Omega) notation, Ξ (Big-Theta) notation
Big-O notation is used to measure the performance of any algorithm by providing the order of growth of the function.
O (Big-O) notation (worst time, upper bound, maximum complexity), 0 <= f(n) <= c*g(n) for all n >= n0, f(n) = O(g(n))
f(n) = 3n + 2, g(n) = n, f(n) = Og(n)
3n + 2 <= Cn
3n + 2 <= 4n
n >= 2
c = 4, n >= 2
Ξ© (Omega) notation (best amount of time, lower bound), 0 <= c*g(n) <= f(n) for all n >=n0
f(n) = 3n + 2, g(n) = n, f(n) = Ξ©g(n)
3n + 2 <= Cn
3n + 2 <= n
2n >= -2
n >= -1
c = 1, n >= 1
Ξ (Big-theta) notation (average case, lower & upper sandwich), 0 <= c1*g(n) <= f(n) <= c2*g(n)
f(n) = 3n + 2, g(n) = n, f(n) = Ξg(n)
C1*n <= 3n + 2 <= C2*n
3n + 2 <= C2*n c1*n <= 3n + 2
3n + 2 <= 4n 3n + 2 >= n
n >= 2 n >= -1
c2 = 4, n >= 2 c1 = 1, n >= 1
n >=2 // We must take a greater number, which is true for both
arr[] of n elements, write a function to search a given element x in arr[].procedure linear_search(list, value)
for each item in the list
if item == value
return the item's location
end if
end for
end procedure
O(1)O(n)O(n)O(log n)procedure binary_search
A β sorted array
n β size of array
x β value to be searched
set lowerBound = 1
set upperBound = n
while x not found
if upperBound < lowerBound
EXIT: x does not exists.
set midPoint