Understanding Algorithmic Complexity: A Focus on Critical Sections - Prof. Nelson Padua-Pe, Study notes of Computer Science

An overview of algorithmic complexity analysis, with a focus on identifying and analyzing critical sections of algorithms. Critical sections are the heart of an algorithm, dominating overall execution time, and are contained inside deeply nested loops or recursion. By understanding the characteristics and executions of critical sections, we can determine the asymptotic complexity of an algorithm. Several examples to illustrate the concepts.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-efx
koofers-user-efx 🇺🇸

10 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CMSC 132:
Object-Oriented Programming II
Algorithmic Complexity II
Department of Computer Science
University of Maryland, College Park
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Understanding Algorithmic Complexity: A Focus on Critical Sections - Prof. Nelson Padua-Pe and more Study notes Computer Science in PDF only on Docsity!

CMSC 132:

Object-Oriented Programming II

Algorithmic Complexity II

Department of Computer Science

University of Maryland, College Park

Overview

Critical sections Comparing complexity Types of complexity analysis

Critical Section of Algorithm

Heart of algorithm Dominates overall execution time Characteristics

Operation central to functioning of program Contained inside deeply nested loops Executed as often as any other part of algorithm

Sources

Loops Recursion

Critical Section Example 1

Code (for input size

n

A

for (int i = 0; i <

n

; i++)

B

C

Code execution

A

once

B

n

times

C

once

Time

n

+ 1 = O(

n

critical

section

Critical Section Example 3

Code (for input size

n

A

for (int

i

= 0; i <

n

; i++)

for (int j =

i

+1; j <

n

; j++)

B

Code execution

A

once

B

n (n-1)

times

Time

n

2

= O(

n

2

critical

section

Critical Section Example 4

Code (for input size

n

A

for (int i = 0; i <

n

; i++)

for (int j = 0; j <

; j++)

B

Code execution

A

once

B

n

times

Time

n

= O(

n

critical

section

Critical Section Example 6

Code (for input size

n

i = 1

while (i <

n

A

i = 2

××××

i

B

Code execution

A

log(

n

) times

B

times

Time

log(

n

) + 1 = O( log(

n

critical

section

Critical Section Example 7

Code (for input size

n

DoWork (int n)

if (n == 1)

A

else

DoWork(n/2)

DoWork(n/2)

Code execution

A

times

DoWork(n/2)

times

Time(1)

Time(

n

×

×

×

×

Time(

n

critical

sections

Recursive Algorithm Example

Code (for input size

n

DoWork (int n)

if (n == 1)

A

else

DoWork(n/2)

DoWork(n/2)

recursive

cases

base

case

Asymptotic Complexity Categories

Complexity

Name

Example

O(

Constant

Array access

O(

log(n)

Logarithmic

Binary search

O(

n

Linear

Largest element

O(

n log(n)

N log N

Optimal sort

O(

n

2

Quadratic

2D Matrix addition

O(

n

3

Cubic

2D Matrix multiply

O(

n

k

Polynomial

Linear programming

O(

k

n

Exponential

Integer programming

From smallest to largestFor size

n

, constant

k

Complexity Comparison Examples

log(n) vs. n

n

vs.

n

lim

n

→→→→

f(n)g(n)

lim

n

→→→→

log(n)

n

lim

n

→→→→

f(n)g(n)

lim

n

→→→→

n

n

Not clear, use

L’Hopital’s Rule

Additional Complexity Measures

Upper bound

Big-O

Represents upper bound on # steps

Lower bound

Big-Omega

Represents lower bound on # steps

Combined bound

Big-Theta

Represents combined upper/lower bound on # steps Best possible asymptotic solution

Additional Complexity Categories

Name

Description

NP

Nondeterministic polynomial time (NP)

PSPACE

Polynomial space

EXPSPACE

Exponential space

Decidable

Can be solved by finite algorithm

Undecidable

Not solvable by finite algorithm

Mostly of academic interest only

Quadratic algorithms usually too slow for large data Use fast

heuristics

to provide non-optimal solutions

NP Time Algorithm

Polynomial solution possible

If make correct

guesses

on how to proceed

Required for many fundamental problems

Boolean satisfiability Traveling salesman problem (TLP) Bin packing

Key to solving many optimization problems

Most efficient trip routes Most efficient schedule for employees Most efficient usage of resources