1 / 6

Algorithmic complexity: Speed of algorithms

Algorithmic complexity: Speed of algorithms. Michael Ernst CSE 190p University of Washington. How fast does your program run?. Usually, this does not matter Correctness trumps speed Computer time is much cheaper than human time The cost of your program depends on:

abia
Download Presentation

Algorithmic complexity: Speed of algorithms

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. Algorithmic complexity:Speed of algorithms Michael Ernst CSE 190p University of Washington

  2. How fast does your program run? • Usually, this does not matter • Correctness trumps speed • Computer time is much cheaper than human time • The cost of your program depends on: • Time to write and verify it • High cost: salaries • Time to run it • Low cost: electricity • An inefficient program may give results faster

  3. Sometimes, speed does matter • Ridiculously inefficient algorithms • Very large datasets Google: 46 billion pages indexed (2011) 3 billion searches per day (2012) = 150,000,000,000,000,000,000 pages searched per day

  4. Example: Processing pairs defmake_pairs(list1, list2): """Return a list of pairs. Each pair is made of corresponding elements of list1 and list2. list1 and list2 must be of the same length.""" … assert make_pairs([100, 200], [101, 201]) == [[100, 101], [200, 201]] • 2 nested loops vs. 1 loop • Quadratic vs. linear time

  5. Searching defsearch(n, list): """Return index of value in list. The value must be in the list.""" … • Any list vs. a sorted list • Linear vs. logarithmic time

  6. Sorting defsort(l): """Return a sorted version of the input list. The input list is not modified.""" … assert sort([3, 1, 4, 1, 5, 9, 2, 6, 5]) == [1, 1, 2, 3, 4, 5, 5, 6, 9] • selection sort vs. quicksort • 2 nested loops vs. recursive decomposition • time: quadratic (n2) vs. n log n

More Related