Definition: An algorithm is a finite step-by-step list of well- defined instructions for solving a particular problem. Algorithm complexity: is a key task in comparing the efficiency of algorithms. Two factors are considered: ◦ 1- the (running) timeTime Complexity ◦ 2- the space (usage)Space Complexity
Time Complexity: estimates the running time of the algorithm. ◦ Measured by the number of key step of the basic steps used by the algorithm. Basic Steps are: ◦ Arithmetic operations (+, -, *, /) ◦ Comparison operations (>, >=, <, <=, ==) ◦ Reading from a memory, file ◦ Writing to memory, file, (cin, fin)
Key step: The most costly step of the algorithm ◦ Takes most of the running time ◦ Other steps is much less or at most proportional to the time of the key step.
In worse-case analysis: ◦ We find the maximum value of the number of the key steps. In Average-case analysis: ◦ We find the average value of the number of the key steps.
Let f (n ) the complexity of an algorithm, i.e., ◦ # key operations ◦ For an instance of size n A computer processor has a speed of 1 MIP ◦ Million Instructions Per (MIP) second
Big Oh O() Notation is used ◦ To estimate the growth rate of f : N R + ◦ f O(g) ◦ There exist two positive integer k, n 0 : f(n) ≤ k*g(n), for all n ≥ n 0 f grows not fast than g f belongs to the complexity class O(g)
f(n) = 3 n+2= O(n) as 3 n +2 ≤ 4 n for all n ≥ 2. f(n) =100 n+6=O(n) as 100 n+6 ≤ 101 n for all n ≥ 6. f(n) =1000 n 2 + 100 n - 6 = Ο(n 2 ) as 1000 n 2 + 100 n - 6 ≤ 1001 n 2 for all n ≥ 100. f(n) = 6 2 n + n 2 = Ο (2 n ) as 6 2 n + n 2 ≤ 7 * 2 n for all n ≥ 4.
Find the class complexity of the following functions 1. f(n) = n 3 + 23n 2 - 8n + 6 2. f(n) = (6n 7 +4) / (n 2 +1) 3. f(n) = 2 n + 3n 5 + 34n 4
An algorithm : is a finite step-by-step list of well-defined instructions for solving a particular problem. Algorithm complexity is a key task in comparing the efficiency of algorithms. Two factors are considered: ◦ 1- the (running) timeTime Complexity ◦ 2- the space (usage)Space Complexity
Sorting Algorithms ◦ Bubble Sort ◦ Insertion Sort ◦ And many other algorithms (Quick Sort, Selection Sort, …. ) Searching Algorithms ◦ Linear search (sequential search) ◦ Binary search ◦ And many other algorithms (BFS, DFS, … ) And There are many and many algorithms used in this fields and other fields.
Your consent to our cookies if you continue to use this website.