Docsity

Principles of Algorithm Analysis, Slides of Algorithms and Programming

Partial preview of the text

Download Principles of Algorithm Analysis and more Slides Algorithms and Programming in PDF only on Docsity!

Principles of Algorithm

Analysis

Biostatistics 615

Lecture 3

Problem Set… z

Questions?

z

FAQ:

How to compile C code?

10 minute introduction for the adventurous…

GCC z

GNU C Compiler

Available on most UNIX systems

Also on newer Macintosh computers

z

For Windows, download from

www.mingw.org

www.cygwin.com

Running GCC z

Command line application z Basic usage is: gcc –o program_name source.c

Use extension “.c” or “.cpp” for source code z Reads in source(s), creates executableprogram

Good editors for C programs… z

Commercial compilers provide veryfancy editors

z

A good free alternative is

nedit

On Windows, available when you installcygwin.

Today z

Strategies for comparing algorithms

z

Common relationships betweenalgorithm complexity and input data

z

Compare two simple search algorithms

Specific Questions z

Compare two algorithms for one task z Predict performance in a new environment

If we had a computer that was 10x faster and couldhandle 10x more data, how would approach perform? z Set values of algorithm parameters

Two Common Mistakes z

Ignore performance of algorithm

Shun faster algorithms to avoid complexity in program

Instead, wait for simple

N

2 algorithms, when N log N alternatives exist of modest complexity available z Too much weight on performance of algorithm

Improving a very fast program is not worth it

Spending too much time tinkering with code is rarelygood use of time

Choices of Input Data z

Actual data

Measures performance in use

z

Random data

Generic approach, may not be representative

z

Perverse data

Attempt worst case analysis

Limitations of EmpiricalAnalysis z

Quality of implementation

Is our favored implementation coded morecarefully than another?

z

Extraneous factors

Compiler

Machine

Computer system

Theoretical Analysis z

Predict performance of algorithm basedon theoretical properties

z

“Independent” of actual implementation

z

Several constructs occur frequently inalgorithm analysis

Limitations of TheoreticalAnalysis z

Efficiency can depend on compiler

z

Efficiency may fluctuate with input data

z

Some algorithms are not well understood

Two typical analyses z

Average-case for random input

z

Worst-case

z

Are these representative of real worldproblems?

Check with empirical predictions…

The Primary Parameter

N

z Examples

Degree of polynomial

Number of characters in a string

Size of file to be sorted

Number of input data items

Some other abstract measure of problem size z With multiple parameters, we can often holdone of them constant