Professional Documents
Culture Documents
Ders 01 Not Lari
Ders 01 Not Lari
401J
DERS 1
Algoritmalarn zmlemesi Araya yerletirme sralamas Asimptotik zmleme Birletirme sralamas Yinelemeler
September 7, 2005
Introduction to Algorithms
L1.2
Algoritmalarn zmlemesi
Bilgisayar program baarm ve kaynak kullanm konusunda teorik almalar Baarmdan daha nemli ne vardr ? kullanc dostluu modlerlik programc zaman doruluk basitlik bakm kolayl
ilevsellik salamlk geniletilebilirlik gvenilirlik
September 7, 2005
Introduction to Algorithms
L1.3
Introduction to Algorithms
L1.4
Introduction to Algorithms
L1.5
pseudocode
( szdekod )
September 7, 2005
Introduction to Algorithms
L1.6
pseudocode
(szde kod)
A:
sorted (sral)
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
September 7, 2005
Introduction to Algorithms
L1.8
September 7, 2005
Introduction to Algorithms
L1.9
September 7, 2005
Introduction to Algorithms
L1.10
September 7, 2005
Introduction to Algorithms
L1.11
September 7, 2005
Introduction to Algorithms
L1.12
September 7, 2005
Introduction to Algorithms
L1.13
September 7, 2005
Introduction to Algorithms
L1.14
September 7, 2005
Introduction to Algorithms
L1.15
September 7, 2005
Introduction to Algorithms
L1.16
September 7, 2005
Introduction to Algorithms
L1.17
2 8 4 4 3 3
4 4 8 8 4 4
9 9 9 9 8 6
3 3 3 3 9 8
6 6 6 6 6 9 (bitti)
L1.18
Introduction to Algorithms
September 7, 2005
Introduction to Algorithms
L1.19
zmleme trleri
En kt durum (Worst-case): (genellikle) T(n) = n boyutlu bir girite algoritmann maksimum sresi Ortalama durum: (bazen) T(n) = n boyutlu her girite algoritmann beklenen sresi. Girilerin istatistiksel dalm iin varsaym gerekli. En iyi durum: (gerek d) Bir giri yapsnda hzl alan yava bir algoritma ile hile yapmak.
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.20
Makineden-bamsz zaman
Araya yerletirme sralamasnn en kt zaman nedir?
Bilgisayarn hzna baldr: bal ( rlatif ) zaman ( ayn makinede), mutlak (absolt ) zaman (farkl makinelerde). BYK FKR: Makineye baml sabitleri grmezden gel. n ' a yaklatka, T(n)'nin bymesine bak. " Asimptotik zmleme"
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.21
- simgelemi (notation)
Matematik: (g(n)) = { f (n) : yle c1, c2, n0 pozitif sabit saylar Mhendislik:
Dk deerli terimleri at; n sabitleri ihmal et. rnek: 3n3 + 90n2 5n + 6046 = (n3)
September 7, 2005
Introduction to Algorithms
L1.22
Asimptotik baarm
n yeterince byrse, (n2) algoritmas bir (n3) algoritmasndan her zaman daha hzldr.
te yandan asimptotik adan yava algoritmalar ihmal etmemeliyiz. Gerek dnyada tasarmn mhendislik hedefleriyle dikkatle dengelenmesi gereklidir. Asimptotik zmleme dncemizi yaplandrmada nemli bir aratr.
L1.23
T(n)
n
September 7, 2005
n0
Introduction to Algorithms
T ( n) =
( j ) = (n 2 )
j =2 n 2) ( ( j / 2 ) = n j =2
[aritmetik seri]
T ( n) =
L1.24
Birletirme sralamas
BRLETRME-SIRALAMASI A[1 . . n] 1. Eer n = 1 ise, ilem bitti. 2. A[ 1 . . n/2 ]ve A[ n/2+1 . . n ]'yi zyinelemeli srala. 3. 2 sralanm listeyi Birletir. Anahtar altyordam: Birletirme
September 7, 2005
Introduction to Algorithms
L1.25
September 7, 2005
Introduction to Algorithms
L1.26
September 7, 2005
Introduction to Algorithms
L1.27
September 7, 2005
Introduction to Algorithms
L1.28
September 7, 2005
Introduction to Algorithms
L1.29
September 7, 2005
Introduction to Algorithms
L1.30
September 7, 2005
Introduction to Algorithms
L1.31
September 7, 2005
Introduction to Algorithms
L1.32
September 7, 2005
Introduction to Algorithms
L1.33
September 7, 2005
Introduction to Algorithms
L1.34
September 7, 2005
Introduction to Algorithms
L1.35
September 7, 2005
Introduction to Algorithms
L1.36
September 7, 2005
Introduction to Algorithms
L1.37
Introduction to Algorithms
L1.38
Introduction to Algorithms
L1.39
Genellikle n'nin kk deerleri iin taban durumu ( base case ) olan T(n) = (1) 'i hesaplara katmayacaz; ama bunu sadece yinelemenin asimptotik zmn etkilemiyorsa yapacaz. 2. Derste T(n)'nin st snrn bulmann birka yolunu inceleyeceiz.
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.40
Yineleme aac
T(n) = 2T(n/2) + cn'yi zn; burada c > 0 bir sabittir.
September 7, 2005
Introduction to Algorithms
L1.41
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir.
T(n)
September 7, 2005
Introduction to Algorithms
L1.42
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn T(n/2) T(n/2)
September 7, 2005
Introduction to Algorithms
L1.43
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn/2 T(n/4) T(n/4) T(n/4) cn/2 T(n/4)
September 7, 2005
Introduction to Algorithms
L1.44
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir.'i cn cn/2 cn/4 (1)
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.45
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn/2 h = lg n cn/4 (1)
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.46
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn cn/2 h = lg n cn/4 (1)
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.47
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn cn/2 h = lg n cn/4 (1)
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
cn
Introduction to Algorithms
L1.48
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn cn/2 h = lg n cn/4
cn cn
(1)
September 7, 2005
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
L1.49
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn cn/2 h = lg n cn/4
cn cn (n)
L1.50
(1)
September 7, 2005
yaprak says = n
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Introduction to Algorithms
Yineleme aac
T(n) = 2T(n/2) + cn'i zn; burada c > 0 bir sabittir. cn cn cn/2 h = lg n cn/4
cn cn (n)
(1)
September 7, 2005
yaprak says = n
Copyright 2001-5 Erik D. Demaine and Charles E. Leiserson
Toplam = (n lg n)
Introduction to Algorithms L1.51
Sonular
(n lg n), (n2)'dan daha yava byr. En kt durumda, birletirme sralamas asimptotik
olarak araya yerletirme sralamasndan daha iyidir.
Introduction to Algorithms
L1.52