DAA Introduction

advertisement

Design and Analysis of Algorithms (DAA)

3621511 (6 cp)

Pasi Fränti

16.9.2013

DAA course at Autumn 2013

• Web: http://cs.uef.fi/pages/franti/asa/

• ETCS 6 (=richer content)

• Lectures (34h):

- Mon 14-16, 16-18

- Tue 14-16

• Exercises (16h):

- Fri 10-12

• Exam dates: 1.11. 18.12. x.5.

2

Motivation

• Design

- 90% cases simple algorithms found from

Bachelor level courses

- Focus on the 10% tough ones

• Analysis

– Why not just measure processing time?

– Time vs. space complexity analyses

– Upper and lower limits

3

Key concepts

• Problem

- Can the problem be solved?

- How difficult is the problem?

- Real-life problems to algorithmic problems

• Algorithm

– How to find suitable algorithm?

– How to make it efficient?

• Instance

– Upper and lower limits

4

199

117

110

216

246

182

121

315

170

231

79

142

191

242

148

136

78

191

178 149

126

116

89

51 112

90

163

59

143

116

79

170

58

73

72

63

105

135

131 109

53

86

27

120

234

Graph problems

• Coloring problem

• Shortest path

• Traveling salesman

Clustering problem

Input Output

6

What is algorithm?

• We need a well-specified problem that tells what needs to be achieved

• Algorithm solves the problem

• It consists of a sequence of commands that takes an input and gives output

Input Algorithm Output

7

Non-solvable problems

• Give list of all rational numbers in [0..1]

• Longest sequence of ļ° without the 0 digit

• Stopping problem

Does algorithm A stop always?

Any algorithm

A

Solve

Stopping

B

8

Non-solvable problems

• Give list of all rational numbers in [0..1]

• Longest sequence of ļ° without the 0 digit

• Stopping problem

Algorithm C NOT stop always!

Any algorithm

A

Solve

Stopping

B

Algorithm

“Vice Versa”

Eternal loop

C

Stop

9

Algorithm principles

• Sequence

- One command at a time

- Parallel and distributed computing

• Condition

- IF

- CASE

• Loops

- FOR

- WHILE

- REPEAT

Complexity

Time complexity:

– How much time it takes to compute

– Measured by a function T ( N )

Space complexity:

– How much memory it takes to compute

– Measured by a function S ( N )

11

Time complexity

N

T ( N

= Size of the input

) = Time complexity function

• Order of magnitude:

– How rapidly T ( N ) grows when N grows

– For example: O( N ) O(log N ) O( N ²) O(2 N )

12

Asymptotic analysis

Examples: Bubble sort ( N ²), Quicksort ( Nāˆ™ log N )

13

Problem size vs. processing time

f(N)

100 N

5 N ²

½ N ³

2 N log N

Processing power increases →

T(N) = 1,000 T(N)=10,000 Growth rate

N = 10 N =100 10 x

14

12

9

2 1,000

44

27

13

2 10,000

3.1 x

2.3 x

1.4 x

Very high!!

14

Exponential time complexity

1 2 4 8 16 32 64 128

256 512

1k 2k

1M

1G

Halfway…?

1T

1P

1E

Large than Everest

2 64 = 18.4 āˆ™ 10 18

15

Graph algorithms

Graph algorithms

Download