Docsity

Complexity Analysis of Algorithms: A Comprehensive Guide, Lecture notes of Data Structures and Algorithms

Partial preview of the text

Download Complexity Analysis of Algorithms: A Comprehensive Guide and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Complexity analysis

Basics

Chapter 1 Advanced algorithms and complexity

Complexity analysis

Complexity Analysis determines the

amount of time and space (memory)

resources required to execute an

algorithm with respect to input size

(independent from the machine, language and

compiler).

Time and Space Complexity

Evaluating the execution time of an algorithm  Time complexity Evaluating how much space (memory) is needed for the execution of an algorithm  Space complexity

Algorithm analysis steps Step 1 : Let P a problem, this is the problem statement Step 2 : Let M be a method, to resolve the problem P and develop an algorithm:

  • Input
  • Output
  • Resolution steps It’s the description of M in an algorithmic language Step 3 : Validation, To prove the correctness and termination of a program. « Program validation » Step 4: measure the efficiency of the algorithm independently of the environment (machine, system, compiler, …) « Calculating theoretical complexity »

Evaluation of an algorithm

Given two algorithms which calculate the solutions to the same problem. How to compare these algorithms? In other words, which is better? Intuition: We will prefer the one that requires the least resources.

  • Execution time resource;
  • Storage space resource;

Time complexity

  • Theoretical approach
  • Experimental approach

Time complexity

Experimental approach:

  • Obtain a much finer evaluation of the algorithms
  • All instructions are taken into account
  • Provides fine indications
  • Detection of sensitive areas
  • Helps in program optimization

Asymptotic complexity

The behavior of an algorithm when the size of the data becomes large is called:

Asymptotic Complexity

Function’s order (or rate of growth) 1 , log n, n, n 2 , 2 n T ( n ) n 2 n 1 Log n n 2 n

Complexity cases

  • Best-case
  • Average-case
  • Worst-case

Example : if T(n)= 2

n We assume that the execution time of a basic instruction is 10

- 6 seconds

for n=60 T(n)=1,15 x 10

12

seconds

1,15 x 10

12

seconds = 36.558 years

and if T(n)=n! we have n !>> 2

n

Ο (big Oh) Ω (big omega) Θ (big theta)

Landau notation

  • Big Oh : O(g(n))={f:IN →IN| c>0 and n 0 ≥ 0/ 0 ≤ f(n) ≤ c.g(n) n ≥ n 0 }
  • g(n) is the asymptotic upper bound for f(n); we note it: f(n)= O (g(n)).