Intro to Computer Algorithms Lecture 21 Phillip G. Bradford Computer Science University of Alabama
Announcements Advisory Board’s Industrial Talk Series 2-Dec: Mike Thomas, CIO, Gulf States Paper
Computer Security Research Group Meets every Friday from 11:00 to 12:00 In 112 Houser Computer Security, etc. me to be on the mailing list!
CS Story Time Prof. Jones’ research group See
Next Midterm Tuesday before Thanksgiving ! 25-November
Outline Dijkstra’s Algorithm The Single-source shortest path challenge Start talking about Huffman trees Introduction to Complexity Theory
Dijkstra’s Algorithm in Detail Recall the intuition Sort of like Prim’s Algorithm Fringe and shortest paths Main Invariant: once an element is absorbed from the fringe, then we have its shortest path See “S” in the next algorithm
Dijkstra’s Algorithm Init-Single-Source(G,w,s) S emptyset; Q V[G] While Q not empty do u extractMin(Q) S S union { u } For all v in adj[u] do Relax(u,v,w)
Dijkstra’s Algorithm Init-Single-Source(G,w,s) Set all vertex distance estimates to Infinity Relax(u,v,w): If d u +w(u,v) < d v then d v d u +w(u,v) Decrease(Q,v,d v )
The Cost of Dijkstra’s Algorithm Example at the board We relax each edge once The decrease-key operation and the extractmin operations cost O(log |V|) Therefore, Dijkstra’s algorithm costs O(|E| log |V|) Where might there be room for improvement?
Huffman Trees Fixed length encodings Prefix free Prefix Trees Left edges labeled with 0 Right edges labeled with 1 How can we make sure short encodings represent common letters?
Huffman’s Algorithm Greedy method starting with one-node trees Merge least-weight trees, label the root with the sub tree sums Example in lecture!
Algorithm Design Paradigms vs. Apparently Very Hard Problems Lower bounds for problems Upper bounds for algorithms How about problems that just `seem’ hard?
Church-Turing Thesis What is our model of computation? How can we prove facts about computation using this model? Turing Machine Equivalent, within polynomial time, to all other `reasonable’ proposed computation
Determinism and Non- Determinism Deterministic algorithms Classical idea from Church-Turing Every action is directly from a consequence Non-Deterministic algorithms Guessing actions Verifying guessed solution deterministically
NP and P P is all decision problems solvable in deterministic polynomial time NP is all decision problems solvable in Non-deterministic polynomial time Certainly, P subset NP What about the other way?
P vs. NP is a big deal in all of Engineering and Science Clay Institute $1 million to solve this challenge
Cook-Levin Theorem CNF-SAT (x 1 or NOT(x 2 ) or x 3 ) AND (NOT(x 1 ) or x 2 ) AND… Truth assignments How hard CNF-SAT be? All (decision) problems in NP are polynomially reducible to CNF-SAT
Tractable and Intractable O(2 n ) intractable for even modest n assuming the Church-Turing thesis O(n 100 ) is `tractable’ given large n Seems strange… Say n=10 6 or 1 million Then (10 6 ) 100 = is certainly not computable in any reasonable sense!
Hypothetical Relationships P NP-Comp. NP