lec12 - n CS 323/700 Lecture 12 o Design and Analysis of...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n CS 323/700 Lecture 12 o Design and Analysis of Algorithms Hoeteck Wee · hoeteck@cs.qc.cuny.edu http://algorithms.qwriting.org/ Algorithmic paradigms GREEDY. build up a solution incrementally, myopically optimizing some local criterion. I challenge: which criterion? does it work? I real difficulty: perhaps there is no greedy strategy DIVIDE-AND-CONQUER. break up a problem into two independent sub-problems, recurse, and combine the solutions. I typically used to obtain better polynomial running time, e.g. O ( n 2 ) → O ( n log n ) DYNAMIC PROGRAMMING. break up a problem into a series of overlapping sub-problems, then build up solutions to larger and larger sub-problems. I challenge: which sub-problem? I applications: Unix diff for comparing two files, Bellman-Ford for computing shortest paths, Smith-Waterman for sequence alignment, Viterbi for hidden Markov models Hoeteck Wee CS 323/700 Mar 22, 2010 2 / 13 Computing the minimum PROBLEM. compute the minimum of n numbers p [ ] , . . . , p [ n- 1 ] . ALGORITHM. def smallest (p): ans = p[0] for i in range(1, n): ans = min(ans, p[i]) return ans RUNNING TIME. O ( n ) I breaking problem down into n sub-problems I in the i ’th iteration, set ans to opt[i] := smallest(p[0],...,p[i]) I compute opt[i] as min(opt[i-1], p[i]) (takes O ( 1 ) time) I return opt[n-1] I paradigm: dynamic programming Hoeteck Wee CS 323/700 Mar 22, 2010 3 / 13 Computing the minimum...
View Full Document

Page1 / 12

lec12 - n CS 323/700 Lecture 12 o Design and Analysis of...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online