of 24/24
LOGO Tính chi phí ca thut toán Cấu trúc dữ liệu & Giải thuật (Data Structures and Algorithms) Nguyn Tri Tun Khoa CNTT – ĐH.KHTN.Tp.HCM Email: [email protected]

Tinh chi phi thuat toan

  • View
    42

  • Download
    5

Embed Size (px)

DESCRIPTION

tinh chi phi cua thuat toan(co ban)

Text of Tinh chi phi thuat toan

Cu trc d liu & Gii thut (Data Structures and Algorithms)

Tnh chi ph ca thut ton

LOGO

Nguyn Tri Tun Khoa CNTT H.KHTN.Tp.HCM Email: [email protected]

Ni dung

1 2

Chi ph ca thut ton Big-O, Big-, Big-

www.themegallery.com

2

Chi ph ca cc gii thut ?Tnh tng n s nguyn:sum = 0; for (i = 0; i < n; i++) sum += i;

Thut ton Bubble sort:for (i = n-1; i > 0; i--) for (j = 1; j a[j]) { temp = a[j-1]; a[j-1] = a[j]; a[j] = temp; }3

Chi ph ca thut ton [1/6]Cng mt vn , c th gii quyt bng nhiu gii thut khc nhauVD. Sp xp mng Bubble sort, Heap sort, Quick sort,

Mi gii thut c chi ph (cost) khc nhau Chi ph thng c tnh da trn:thi gian (time) b nh (space/memory)

Chi ph thi gian thng c quan tm nhiu hn4

Chi ph ca thut ton [2/6]Tuy nhin, vic dng khi nim thi gian theo ngha en (vd. gii thut A chy trong 10s) l khng n, v:tu thuc vo loi my tnh (vd. my Dual-Core s chy nhanh hn Pentium II) tu thuc ngn ng lp trnh (vd. Gii thut vit bng C/Pascal c th chy nhanh gp 20 ln vit bng Basic/LISP)

Do , ngi ta thng dng n v o logic (vd. s php tnh) thay cho n v o thi gian tht (mili-giy, giy,)VD. Chi ph (thi gian) sp xp mng n phn t bng gii thut Bubble sort l n2 (thao tc)

5

Chi ph ca thut ton [3/6]VD. Xem on code sausum = 0; for (i=0; i