1 / 8

Algorithm Performance

Algorithm Performance. CMSC 150 – Introduction to Computing. Big-Oh: Algorithm Complexity. We group algorithms into classes of similar complexity (i.e., how many steps required) Sequential search is a O( n ) algorithm (linear). O(1). O(log n ). O(n ). O(n 2 ). O(2 n ). Sequential

zwi
Download Presentation

Algorithm Performance

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 Performance CMSC 150 – Introduction to Computing

  2. Big-Oh: Algorithm Complexity • We group algorithms into classes of similar complexity (i.e., how many steps required) • Sequential search is a O(n) algorithm (linear) O(1) O(logn) O(n) O(n2) O(2n) Sequential search Modifying a 2D image Traveling Salesman (brute force) constant-time logarithmic linear quadratic exponential

  3. Some Comparisons • nis the size of the input • Entry in table gives approximate number of steps required by an algorithm of that complexity

  4. Analyzing binary search • Consider worst case for an array of size 32: 32 elements 16 elements 8 elements 4 elements 2 elements 1 element

  5. Analyzing binary search • Consider worst case for an array of size 32: 32 elements 16 elements 8 elements • Ignore the last (1-elementarray) comparison • Start with 32 elements • 5 comparisons total until found • Note 25 = 32  log2 32 = 5 • Log2 of input size gives ~ number of comparisons 4 elements 2 elements 1 element

  6. Big-Oh: Algorithm Complexity • Binary search is a O(logn) algorithm (logarithmic) O(1) O(logn) O(n) O(n2) O(2n) Binary search Sequential search Modifying a 2D image Traveling Salesman (brute force) constant-time logarithmic linear quadratic exponential

  7. Some Comparisons • nis the size of the input binary search sequential search

  8. Sequential vs. Binary Search • Sequential • O(n): linear • Easy to implement • Inefficient for large input size • Binary: O(logn) • O(logn): logarithmic • Reasonably efficient for large input size • Requires the list to be sorted

More Related