Design & Analysis of Algorithms Combinatory optimization SCHOOL OF COMPUTING Pasi Fränti 20.10.2014.
Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.
-
Upload
kathryn-hood -
Category
Documents
-
view
218 -
download
2
Transcript of Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.
![Page 1: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/1.jpg)
Design and Analysis of Algorithms (DAA)
3621511 (6 cp)
Pasi Fränti7.9.2015
![Page 2: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/2.jpg)
2
DAA course at Autumn 2015
• Web: http://cs.uef.fi/pages/franti/asa/
• ETCS 6 (=richer content)• Lectures (34h):
- Mon 14-17- Tue 14-16
• Exercises (16h):- Fri 10-12
• Exam dates: 6.11. 27.11.
![Page 3: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/3.jpg)
3
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
![Page 4: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/4.jpg)
4
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
![Page 5: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/5.jpg)
136
170315
148 78
231
234
12089
131109
116
86
246
182
216110
117
199
121
142242
79
191178
191
126149
17051 112
90163
59
14373
63 5327
135
10558
116
72
79
Graph problems• Coloring problem• Shortest path• Traveling
salesman
![Page 6: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/6.jpg)
6
Clustering problem
Input Output
![Page 7: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/7.jpg)
7
• 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
What is algorithm?
AlgorithmInput Output
![Page 8: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/8.jpg)
8
Non-solvable problems
• Give list of all rational numbers in [0..1]• Longest sequence of without the 0 digit• Stopping problem
A B
Anyalgorithm
SolveStopping
TRUE
FALSE
Does algorithm A stop always?
![Page 9: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/9.jpg)
9
Non-solvable problems
• Give list of all rational numbers in [0..1]• Longest sequence of without the 0 digit• Stopping problem
A B
Anyalgorithm
SolveStopping
TRUE
FALSECEternal loop
Algorithm“Vice
Versa”
Stop
Algorithm C NOT stop always!
![Page 10: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/10.jpg)
Algorithm principles
• Sequence- One command at a time- Parallel and distributed computing
• Condition- IF- CASE
• Loops- FOR- WHILE- REPEAT
![Page 11: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/11.jpg)
11
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)
Complexity
![Page 12: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/12.jpg)
12
Time complexity
• N = Size of the input
• T(N) = Time complexity function
• Order of magnitude:– How rapidly T(N) grows when N grows– For example: O(N) O(logN) O(N²) O(2N)
![Page 13: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/13.jpg)
13Examples: Bubble sort (N²), Quicksort (N∙logN)
Asymptotic analysis
log N --- sub-linear
2N -
-- e
xponenti
al
N²
---
quad
raticN ---
linear
N3
---
cubic
N lo
gN
![Page 14: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/14.jpg)
14
Processing power increases →
f(N) T(N) = 1,000 T(N)=10,000 Growth rate
100N N = 10 N=100 10 x
5N² 14 44 3.1 x
½N³ 12 27 2.3 x
2N 9 13 1.4 x
logN 21,000 210,000 Very high!!
Problem size vs. processing time
![Page 15: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/15.jpg)
15
Exponential time complexity
1 2 4 8 16 32 64 128
512256 1k 2k
264 = 18.4 ∙ 1018
1M
1G
…
1T
1P
1E
Halfway…?
Large than Everest
![Page 16: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/16.jpg)
Graph algorithms
![Page 17: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/17.jpg)
Graph algorithms
![Page 18: Design and Analysis of Algorithms (DAA) 3621511 (6 cp) Pasi Fränti 7.9.2015.](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f1e5503460f94c362f3/html5/thumbnails/18.jpg)