Lecture 29(Friday) - counting costs want a coarse...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: counting costs want a coarse comparison of algorithms \speed" that ignores hardware, programmer virtuosity which speed do we care about: best, worst, average? why? de ne idealized \step" that doesn't depend on particular hardware and idealized \time" that counts the number of steps for a given input. slide 9 linear search def LS(A,x) : """ Return index i such that x == L[i]. 1. i = 0 2. while i < len(A) : 3. if A[i] == x : 4. return i 5. i = i + 1 6. return -1 Otherwise, return -1 """ Trace LS([2,4,6,8],4), and count the time complexity What is What is tLS A; x tLS ([2 4 6 8] 4) ; ; ; ; ( ), if the rst index where is found is ? x j tLS A; x ( ) is isn't in at all? x A slide 10 worst case denote the worst-case complexity for program with input where the input size of is as size( ) = P ( ) = max P ( ) P x n W n ft x j x P I x ng x P I , The upper bound That is: WP P y U ( ) means N N ; Vn P Wc P Wc P R+ R+ ; WB P ; WB P ; Vx P I ; N size( ) x ;n ! B ! B A A max P ( ) size( ) = (size( )) P( ) ft x j x P I x x t x cU ng cU n ( ) The lower bound That is: WP P ( ) means L Wc P Wc P R+ R+ ; WB P ; WB P N N ; Vn P ; Vn P N N ;n ! B ;n ! B A A max P ( ) size( ) = ft x Wx P I ; x j x P I n t size( ) = ( ) ( ) P( ) x ng ! cU n x ! cL n slide 11 bounding a sort def IS(A) : """ IS(A) sorts the elements of A in non-decreasing order """ 1. i = 1 2. while i < len(A) : 3. t = A[i] 4. j = i 5. while j > 0 and A[j-1] > t : 6. A[j] = A[j-1] # shift up 7. j = j-1 8. A[j] = t 9. i = i+1 I want to prove that WIS P y n ( 2). slide 12 scratch slide 13 ...
View Full Document

This note was uploaded on 10/13/2011 for the course COMPUTER S CSC 165 taught by Professor Dannyheap during the Fall '10 term at University of Toronto.

Page1 / 5

Lecture 29(Friday) - counting costs want a coarse...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online