Running Time Calculations in Algorithm Analysis, Slides of Data Structures and Algorithms

An in-depth analysis of running time calculations in algorithms, including factors affecting running time, consecutive statements, recursive functions, and recurrence relations. It also covers the maximum subsequence sum problem and its algorithms, logarithms in running time, and methods for computing running time.

Typology: Slides

2011/2012

Uploaded on 07/15/2012

sahill
sahill 🇮🇳

4.8

(4)

46 documents

1 / 83

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
7/7/2012 Algorithm Analysis 2-1
Chapter 2
Algorithm Analysis
EE 232 Data Structures
Session-05 , Spring-07
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53

Partial preview of the text

Download Running Time Calculations in Algorithm Analysis and more Slides Data Structures and Algorithms in PDF only on Docsity!

7/7/2012 Algorithm Analysis 2-

Chapter 2

Algorithm Analysis

EE 232 Data Structures Session-05 , Spring-

7/7/2012 Algorithm Analysis 2-

Chapter 2: Algorithm Analysis

2.1 Mathematical Background

2.2 Model

2.3 What to Analyze

2.4 Running Time Calculations

7/7/2012 Algorithm Analysis 2-

Lets Recall

 What is an Algorithm?  a clearly specified set of simple instructions to be followed to solve a problem

  • Takes a set of values, as input and
  • produces a value, or set of values, as output

 What are Data structures?  Methods of organizing data

 Program = algorithms + data structures

7/7/2012 Algorithm Analysis 2-

Lets Recall…

 Why should we analyse an algorithm?

 Writing a working program is not good enough!  The program may be inefficient  If the program is run on a large data set, then the running time becomes an issue

  • Recall the selection problem

7/7/2012 Algorithm Analysis 2-

Mathematical Background

 We need a theoretical framework upon which we can compare algorithms

 The idea is to establish a relative order among different algorithms, in terms of their relative rates of growth (of the running time)

 The rates of growth are expressed as functions, which are generally in terms of the number of inputs n e.g. a running time function can be expressed as T( n )

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 Such functions describe the utilization of some precious resource (e.g. time or space) as the size of the problem increases

 We can determine the exact running time of an algorithm, however for large inputs, the multiplicative constants and lower-order terms are dominated by the effects of the input size itself

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 *If we look at a slightly larger range from n = [0, 10], we begin to note that they are more similar:

*http://www.ece.uwaterloo.ca/~ece250/ docsity.com

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 *Extending the range to n = [0, 100], the similarity increases:

*http://www.ece.uwaterloo.ca/~ece250/ docsity.com

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 *They are different absolutely, for example, f(1000) = 1 000 000 g(1000) = 997 002  however, the relative difference is very small

 and this difference goes to zero as n → ∞  The justification for the pair of polynomials being similar is that, both have the same leading term:  n^2

f( 1000 )

f( 1000 ) g( 1000 )

*http://www.ece.uwaterloo.ca/~ece250/ docsity.com

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

We can throw away the lower-order terms and ignore the leading coefficients of the highest term as the problem size grows really, really large

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

Asymptotic Notation  The “big-Oh” O - Notation  f( n ) 1 = O (g( n )) , if there exists positive constants c and n 0 , such that f( n )  cg( n ) for all n ≥ n 0

 f( n ) and g( n ) are functions over non-negative integers  The growth rate of f( n ) is less than or equal to that of g( n )

f ( n)

c g n  ( )

n (^0) Input Size

Running Time

1: means set membership i.e. f( n ) Є O (g( n ))

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 g( n ) is an upper bound on f( n )  O -notation provides an asymptotic upper bound on a function  Used for worst-case analysis

Examples  If f( n ) = 2 n^2 , then f( n ) = O ( n^4 ) , f( n ) = O ( n^3 ) and f( n ) = O ( n^2 ) are all technically correct but the last answer is the best

f( n)

c g n  ( )

n 0 Input Size

Running Time

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 W–notation provides an asymptotic lower bound on a function  Used to describe best- case running times

Examples  n^3 grows faster than n^2 , so we can say that n^3 = W( n^2 )

Input Size

Running Time

f ( n) c g n  ( )

n 0

7/7/2012 Algorithm Analysis 2-

Mathematical Background…

 The “big-Theta” Q-Notation

 f( n ) = Q(g( n )) if there exists positive constants c 1 , c 2 , and n 0 , such that c 1 g( n )  f( n )  c 2 g( n ) for all n  n 0

 for all values of n to the right of n 0 , the values of f( n ) lies at or above c 1 g( n ) and at or below c 2 g( n )

Input Size

Running Time

f ( n)

n 0

c 2 g( n)

c 1 g( n)