1 / 9

Algorithm Analysis

Algorithm Analysis. Run time complexity. Analysis Concepts. Input Size Number of input units Sorting – List length Adding 2 numbers – Number digits Running Time Number of basic operations Sorting – Comparison Adding 2 numbers – Computing sum & carry. Orders of Growth.

Download Presentation

Algorithm Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithm Analysis Run time complexity

  2. Analysis Concepts • Input Size • Number of input units • Sorting – List length • Adding 2 numbers – Number digits • Running Time • Number of basic operations • Sorting – Comparison • Adding 2 numbers – Computing sum & carry

  3. Orders of Growth

  4. Worst Case / Every Case • Every case refers to algorithms whose run time do not depend on input but only size. Examples : Adding sequence of numbers, etc. • Worst case refers to algorithms whose run time does depend on input as well as size. Examples : Insertion Sort

  5. Big Oh Notation • A function f(n) is O(g(n)) iff • There is an integer no and • There is a constant c such that • f(k) < c g(k) when k > no • Show that an2 + bn + c is O(n2)

  6. Analysis of MaxElement • Determines value of largest element in array • Maxval = A(0) • For I = 1 to n-1 • If A(I) > Maxval • Maxval = A(I) • Return Maxval

  7. Unique Element • For I = 0 to n-1 • For J = I+1 to n-2 • If A(J) = A(I) return false • Return True

  8. Efficiency Analysis • Measure input size • Identify basic operation • Determine whether number of times basic operation is every case or worst case • Calculate number of times T(n) basic operation is executed as function of input size n • Determine Order of T

  9. Analysis of MaxElt and UniqueElt • MaxElt • Has to go thru entire array, regardless of values • Every Case • O(n) • UniqueElt • May detect false on 1st comparison or last • Best Case / Worst Case • O(1) / O(n2)

More Related