200 likes | 211 Views
This lecture covers Dijkstra's algorithm for finding the shortest path and introduces Huffman trees for efficient encoding. It also explores complexity theory, the Church-Turing thesis, and the P vs NP problem.
E N D
Intro to Computer Algorithms Lecture 21 Phillip G. Bradford Computer Science University of Alabama
Announcements • Advisory Board’s Industrial Talk Series • http://www.cs.ua.edu/9IndustrialSeries.shtm • 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. • Email me to be on the mailing list!
CS Story Time • Prof. Jones’ research group • See http://cs.ua.edu/StoryHourSlide.pdf
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 du+w(u,v) < dv then • dv du+w(u,v) • Decrease(Q,v,dv)
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 • (x1 or NOT(x2) or x3) AND (NOT(x1) or x2) AND… • Truth assignments • How hard CNF-SAT be? • All (decision) problems in NP are polynomially reducible to CNF-SAT
Tractable and Intractable • O(2n) intractable for even modest n assuming the Church-Turing thesis • O(n100) is `tractable’ given large n • Seems strange… • Say n=106 or 1 million • Then (106)100 = 10600 is certainly not computable in any reasonable sense!
Hypothetical Relationships NP-Comp. NP P