1 / 9

Class 7: Complexity & Sorting

Class 7: Complexity & Sorting. Why Big O complexity?. There are many functions (every program is a function) Sizes of inputs vary enormously Rates of growth differ enormously (see table) We can’t see the forest for the trees Solution: groups functions into complexity classes.

Télécharger la présentation

Class 7: Complexity & Sorting

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. Class 7: Complexity & Sorting

  2. Why Big O complexity? • There are many functions (every program is a function) • Sizes of inputs vary enormously • Rates of growth differ enormously (see table) • We can’t see the forest for the trees • Solution: groups functions into complexity classes cis 335 Fall 2001 Barry Cohen

  3. Big O rules • Ignore all but the fastest growing term • Ignore a multiplicative constant in the remaining term • Add together growth rate functions cis 335 Fall 2001 Barry Cohen

  4. Some practice • Is O(log2n) = O(log10n)? • Which grows faster,1,000,000n2 or n3? • Which grows faster,n10 or 2n/10? cis 335 Fall 2001 Barry Cohen

  5. Worst case, average case,best case • Big O is worst case. It is a performance guarantee. • It’s usually the most important measure. (And the one we can most easily get.) • Sometimes average case is most common (Qsort) • Crypto: a different yardstick cis 335 Fall 2001 Barry Cohen

  6. Selection sort • How the algorithm works (like sorting a hand of cards) • What is its Big O complexity? • What is its average case complexity? • At 1,000 comparisons/sec, how long would it take to sort 100,000 items? cis 335 Fall 2001 Barry Cohen

  7. Merge sort • How the algorithm works • Big O complexity. Is the work being done in the divide or the combine phase? • Does the order of the input matter? If so, what are the best and worst cases? • What is the space requirement of mergesort? What is its Big O space complexity? cis 335 Fall 2001 Barry Cohen

  8. Quicksort • Another divide and conquer • Basic idea: * partition around a pivot* recurse on each of the parts • Where is most of the work done? • What is the best case, and how long does it take? • What is the worst case, and how long does it take? cis 335 Fall 2001 Barry Cohen

  9. Radix sort • Method: sort into buckets. No comparison of elements! • Analysis we break the n log n barrier. • What is the space requirement? • How long does it take to retrieve the answer? cis 335 Fall 2001 Barry Cohen

More Related