Statement Analysis: Identifying Critical Sections and Complexity in Algorithms, Slides of Computer Science

An analysis of algorithms, focusing on statement analysis and the identification of critical sections and their impact on overall efficiency. It covers the characteristics of critical sections, the analysis of consecutive statements, if/else statements, for loops, and nested for loops. The document also includes general rules for analyzing algorithms.

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dharmaraaj
dharmaraaj 🇮🇳

4.4

(68)

145 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Analysis of Algorithms
Statement Analysis
Docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Statement Analysis: Identifying Critical Sections and Complexity in Algorithms and more Slides Computer Science in PDF only on Docsity!

Analysis of Algorithms

Statement Analysis

Statement Analysis – Critical Section

  • When analyzing an algorithm, we do not care

about the behavior of each statement

  • We focus our analysis on the part of the algorithm

where the greatest amount of its time is spent

  • A critical section has the following characteristics:
    • It is an operation central to the functioning of the

algorithm, and its behavior typifies the overall

behavior of the algorithm

  • It is contained inside the most deeply nested loops of

the algorithm and is executed as often as any other

section of the algorithm.

Statement Analysis - Sequence Consecutive statements

  • Maximum statement is the one counted e.g. a fragment with single for-loop followed by double for- loop is O(n^2 ).

Block #

Block #

t 1

t 2

t 1 +t 2 = max(t 1 ,t 2 )

Statement Analysis - If

If/Else:

if cond then

S

else

S2; Block #1 t 1 Block #2 t 2 Max(t 1 ,t2)

Statement Analysis – Nested For

Nested For-Loops

  • Analyze inside-out. Total running time is

running time of the statement multiplied by product of the sizes of all the for-loops

e.g. for (i =0; i < n; i++)

for (j = 0, sum = a[0]; j <= i ; j++)

sum += a[j]; printf("sum for subarray - through %d is %d\n", i, sum);

Statement Analysis – Nested For (cont)

2

1

1 1 1

O n

O i

i

n

i

n

i

i

j

n

i

O = O

=

= = =