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

Info icon This 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 Document Right Arrow Icon

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

View Full Document Right 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern