90 likes | 222 Vues
This overview delves into algorithm efficiency, a critical concept in computer science. Discussing various algorithms, it provides insights into input handling, output determination, and complexity classes. Key topics include binary search (O(log n)), linear search (O(n)), sorting algorithms (merge sort O(n log n), bubble, insertion sort O(n^2)), and more complex problems such as the Traveling Salesperson and the Halting Problem. This resource is essential for anyone looking to grasp the fundamentals of algorithm analysis and its implications in computational theory.
E N D
CSCI 1001 overview of computer science ALGORITHM EFFICIENCY III
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.
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.
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.
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
O(2n) Satisfiability Traveling Salesperson Optimization Problems P vs NP Is it easier to check an answer than find one?
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?
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)