Lecture 1: Introduction - Peak Finding
COMS10007 - Algorithms
- Dr. Christian Konrad
27.01.2020
- Dr. Christian Konrad
Lecture 1: Introduction - Peak Finding 1 / 18
Lecture 1: Introduction - Peak Finding COMS10007 - Algorithms Dr. - - PowerPoint PPT Presentation
Lecture 1: Introduction - Peak Finding COMS10007 - Algorithms Dr. Christian Konrad 27.01.2020 Dr. Christian Konrad Lecture 1: Introduction - Peak Finding 1 / 18 GO China: STEM Futures Join this 4-week summer school at the Beijing Institute
Lecture 1: Introduction - Peak Finding 1 / 18
Lecture 1: Introduction - Peak Finding 2 / 18
Lecture 1: Introduction - Peak Finding 3 / 18
Lecture 1: Introduction - Peak Finding 4 / 18
Lecture 1: Introduction - Peak Finding 5 / 18
Lecture 1: Introduction - Peak Finding 6 / 18
Lecture 1: Introduction - Peak Finding 7 / 18
Lecture 1: Introduction - Peak Finding 8 / 18
Lecture 1: Introduction - Peak Finding 9 / 18
Lecture 1: Introduction - Peak Finding 10 / 18
Lecture 1: Introduction - Peak Finding 10 / 18
1 Input: An integer array of length n 2 Output: A position 0 ≤ i ≤ n − 1 such that ai is a peak
Lecture 1: Introduction - Peak Finding 11 / 18
1 Input: An integer array of length n 2 Output: A position 0 ≤ i ≤ n − 1 such that ai is a peak
Lecture 1: Introduction - Peak Finding 11 / 18
Lecture 1: Introduction - Peak Finding 12 / 18
Lecture 1: Introduction - Peak Finding 12 / 18
Lecture 1: Introduction - Peak Finding 12 / 18
Lecture 1: Introduction - Peak Finding 12 / 18
Lecture 1: Introduction - Peak Finding 12 / 18
Lecture 1: Introduction - Peak Finding 13 / 18
1 if A is of length 1 then return 0 2 if A is of length 2 then compare A[0] and A[1] and
3 if A[⌊n/2⌋] is a peak then return ⌊n/2⌋ 4 Otherwise, if A[⌊n/2⌋ − 1] ≥ A[⌊n/2⌋] then
5 else
Lecture 1: Introduction - Peak Finding 14 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lecture 1: Introduction - Peak Finding 15 / 18
Lecture 1: Introduction - Peak Finding 16 / 18
1
2
3
4
5
Lecture 1: Introduction - Peak Finding 17 / 18
5 10 15 20 25 30 35 40 1 2 3 4 5 6 7 8 9 10 number of accesses to the array Fast-Peak-Finding: 5 log(n) Slow Peak Finding: 4(n-1)
Lecture 1: Introduction - Peak Finding 18 / 18
50 100 150 200 250 300 350 400 10 20 30 40 50 60 70 80 90 100 number of accesses to the array Fast-Peak-Finding: 5 log(n) Slow Peak Finding: 4(n-1)
Lecture 1: Introduction - Peak Finding 18 / 18
500 1000 1500 2000 2500 3000 3500 4000 100 200 300 400 500 600 700 800 900 1000 number of accesses to the array Fast-Peak-Finding: 5 log(n) Slow Peak Finding: 4(n-1)
Lecture 1: Introduction - Peak Finding 18 / 18
500 1000 1500 2000 2500 3000 3500 4000 100 200 300 400 500 600 700 800 900 1000 number of accesses to the array Fast-Peak-Finding: 5 log(n) Slow Peak Finding: 4(n-1)
Lecture 1: Introduction - Peak Finding 18 / 18