Analysis of Algorithms
Output maximum element of A
Download 372.17 Kb.
|
1 2
Bog'liq8-mavzu(AL)
- Bu sahifa navigatsiya:
- Algoritm usuli
- Primitiv operatsiyalarni hisoblash
- Ishlash vaqtini hisoblash
- Ishlash vaqtining osish surati
- Log-log diagrammasida chiziqning qiyaligi funktsiyaning osish tezligiga mos keladi Doimiy omillar
- Asimptotik algoritmlarni tahlil qilish
- Hisoblash prefiksining ortacha korsatkichlari
- Matematikani korib chiqishingiz kerak
Output maximum element of A
currentMax A[0] for i 1 to n 1 do if A[i] currentMax then currentMax A[i] return currentMax Psevdokod tafsilotlari
Algoritm usuli ( arg [, arg …])Kiritish …Chiqish …
var.method (arg [, arg…]) return expression n2 Superscripts and other mathematical formatting allowed RAM
0 1 2
Primitiv operatsiyalar
Primitiv operatsiyalarni hisoblash
Algorithm arrayMax(A, n) # operations currentMax A[0] 2 for i 1 to n 1 do 2n if A[i] currentMax then 2(n 1) currentMax A[i] 2(n 1) { increment counter i } 2(n 1) return currentMax 1 Total 8n 2 Ishlash vaqtini hisoblash
a = Eng tez primitiv operatsiya tomonidan olingan vaqtb = Eng sekin primitiv operatsiya tomonidan qabul qilingan vaqtIshlash vaqtining o'sish sur'ati
Yetti muhim funksiya
Doimiy omillar
Big-Oh belgisi
f(n) cg(n) for n n0Big-Oh misoli
Ko'proq Big-Oh misollari
7n-2 is O(n) need c > 0 and n0 1 such that 7n-2 c•n for n n0 this is true for c = 7 and n0 = 1
3n3 + 20n2 + 5 is O(n3) need c > 0 and n0 1 such that 3n3 + 20n2 + 5 c•n3 for n n0 this is true for c = 4 and n0 = 21
3 log n + 5 is O(log n) need c > 0 and n0 1 such that 3 log n + 5 c•log n for n n0 this is true for c = 8 and n0 = 2 Asimptotik algoritmlarni tahlil qilish
Hisoblash prefiksining o'rtacha ko'rsatkichlari
A [ i ] = ( X [0] + X [1] + … + X [ i ])/( i +1)O'rtacha prefiks (kvadrat)
Algorithm prefixAverages1(X, n) Input array X of n integers Output array A of prefix averages of X #operations A new array of n integers n for i 0 to n 1 do n s X[0] n for j 1 to i do 1 + 2 + …+ (n 1) s s + X[j] 1 + 2 + …+ (n 1) A[i] s / (i + 1) n return A 1 Arifmetik progressiya
Prefiks o'rtachalari (chiziqli)
Algorithm prefixAverages2(X, n) Input array X of n integers Output array A of prefix averages of X #operations A new array of n integers n s 0 1 for i 0 to n 1 do n s s + X[i] n A[i] s / (i + 1) n return A 1 Matematikani ko'rib chiqishingiz kerak
log b (xy) = log b x + log b ylog b (x/y) = log b x - log b ylog b xa = alog b xlog b a = log x a/log x ba (b+c) = a b a ca bc = (a b ) ca b / a c = a (bc)b = a log a bb c = a c*log a b
Download 372.17 Kb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling