1 / 9

computer science

CSCI 1001. overview of. computer science. ALGORITHM EFFICIENCY III. Input : a list a 1 ,…,a n set g to n , ℓ to 1 while ℓ ≤  g do if a ℓ ≠ 0 then set ℓ to ℓ+ 1 else set g to g-1, r to ℓ+ 1 while r ≤ n do set a r-1 to a r , r to r+1

tammy
Télécharger la présentation

computer science

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. CSCI 1001 overview of computer science ALGORITHM EFFICIENCY III

  2. Input: a list a1,…,an set g to n, ℓto 1 whileℓ≤ gdo if aℓ≠ 0 then setℓto ℓ+1 else set g to g-1, r to ℓ+1 while r ≤ ndo set ar-1 to ar, r to r+1 output a1,…,ag and stop.

  3. Input: a list a1,…,an set ℓ1…ℓn to 0, g to 0 for each i in {1,…,n} do if ai ≠ 0 then set g to g+1 set ℓgto ai output ℓ1,…,ℓg and stop.

  4. Input: a list a1,…,an set ℓ to 1, r to n while ℓ ≤ rdo if aℓ = 0 then set aℓ to ar, r to r-1 else set ℓ to ℓ + 1 ifar = 0 then set r to r-1 output a1,…,ar and stop.

  5. O(logn) Binary Search O(n) Linear Search Cleanup! Common Friends O(n log n) Merge Sort O(n2) Bubble, Insertion Sort Stable Marriages Viterbi Decoding O(n3) Public Key Crypto Linear Equation Solving

  6. O(2n) Satisfiability Traveling Salesperson Optimization Problems P vs NP Is it easier to check an answer than find one?

  7. Unsolvable Halting problem def wont_halt(s): while True: None return def will_halt(s): return The Halting Problem: given a program and its input, will the program halt?

  8. liar_liar = ‘def liar_liar_pants_on_fire(code): def will_it_halt(code,input): … def loop_forever(): while True: None if will_it_halt(code, code): loop_forever() else: return True’ liar_liar_pants_on_fire(liar_liar)

  9. http://cs1001.us/

More Related