ADVANCED ALGORITHMStheory.cs.utah.edu › fall18 › algorithms › slides › lecture27.pdfmerge...
Transcript of ADVANCED ALGORITHMStheory.cs.utah.edu › fall18 › algorithms › slides › lecture27.pdfmerge...
ADVANCED ALGORITHMSLecture 27: Course review
�1
ANNOUNCEMENTS
➤ HW 6 is due tomorrow
➤ Final exam — see practice finals and finals of 2016-17 ➤ Tuesday, 10:30 AM (same room)
�2
C I on
short questions1Sane everything offline 3 problems
EXAM
�3
➤ Much easier than HW — think simple
TOPICS REVIEW
�4
➤ Data structures ➤ what data is stored? ➤ what operations? time/space per operation ➤ common: tries for strings, binary search trees
➤ Divide and conquer ➤ analyze correctness via induction ➤ analyze running time via recursion — solving recurrences usually “easy” ➤ merge sort, multiplying integers (n^1.58.. time for n bit #s) ➤ selecting the k’th smallest number in unsorted list
iteminOllogn
timesmallestelement
mi4
101nlttimeTpeaosy.nl
usffaiy
TOPICS REVIEW
�5
➤ Dynamic programming ➤ memorize answers to all sub-problems ➤ so only works if “number of sub-problems” is small ➤ subset-sum, “coin change”, max increasing subsequence
➤ Greedy algorithms ➤ loosely defined as algorithm that iteratively takes the “best decision at
the current state” ➤ sometimes finds optimal solution: minimum spanning tree ➤ usually does not; approximation algorithm — for covering
Substum aytarget sums
Mor ks camwea urn of
space usage
SHINofsub.pt ems
I47631
TOPICS REVIEW
�6
➤ Local search ➤ start with a solution; try to go to a “better” one by “slight changes” ➤ how to change solution? ➤ works in some problems (convex optimization), 2-approximation for
matching
➤ Graph basics ➤ BFS/DFS — O(m+n) time — simplest procedures to explore graphs ➤ Dijkstra’s algorithm for shortest paths — works if all weights are +ve
o
TTi
i Ip
t
m
TOPICS REVIEW
�7
➤ Flows and cuts ➤ send as much “flow” as possible without violating capacities ➤ powerful framework: Ford/Fulkerson algorithm ➤ closely related to “cuts” ➤ definitions of flows and cuts; max flow = min cut
minint
greedyalgorithm
min cut correction
DMax flow E min cut of
a X
Algorithms we knowfor min cut govia flows
TOPICS REVIEW
�8
➤ Probabilistic algorithms ➤ may have a “probability of success” ➤ expected running time ➤ analyze running time via defining appropriate “random variables” ➤ dealing with random variables
➤ express in terms of “simple” r.v.s ➤ linearity of expectation ➤ Markov, Chebychev inequalities ➤ sampling and how to analyze it
Jscorrectness
run time upperbound
4outcomeof a
y zProb Proms
EX EY t IE Z
coningtigrandom variables ou to
expectation w h p
TOPICS REVIEW
�9
➤ Optimization formulations ➤ formulate different problems as optimization ➤ how to pick variables, their domains, … ➤ key: must make sure that formulation “captures” problem — any
solution to formulation gives valid solution to problem ➤ binary optimization is NP-hard — so we “relax” to linear programs ➤ linear programs can be solved in time poly(size of LP) ➤ LPs have nice geometry — feasible region is a “polytope” ➤ optimum solutions are always corner points
nichol my 0 Exit
crucialpart
I LIP is
i
TOPICS REVIEW
�10
➤ Optimization formulations ➤ relaxed LPs can be useful too ➤ sometimes all corner points are (luckily) integral! ➤ can “round” fractional solutions to integer ones
Ft
gf 04,0
texana pE i
Limits of computationsNP NP hard NP complete
redeema
O Oif Q ii easy so is a
if Q is hard Q is hardalso
r ng
Dynamic programming longestSubsequence
Matchingsolutions t
ILExpected running time T HW
a an Ai 70
ai EZ
want toknow if 3 a subsetofthese s addingupto
Target subset
eitherhas a a an S
or NOT da Emea
30
Iaa an and make a are an
Tsarina mahegags
I n t s
ai targ mt
t E fo s t a an integer
I E i E h
keyobs there are only 1 different
sub problems if Sta n GIthen we can do muchbetter
Algorithm Can maintain an array
Aft ifl f we can geta sum of t
musing a subset of ai an
0 ofwise
Fill all Juries of this arrayA Al
a
I Aft a ill
I Aft ai it
tA n fill by inspection
E af i or if t o
Alt n i
ma
enact to each child s'tGoal assignattotal happiness value is maximized
find some permutation Ti s t
t is maximized
Til procedure aftis IT convergence
2 dm with
2produces a soln
with
objective vat 3 IzOPT
if Hi values are then this
problem can be written as maxflow
linear programming
feasible set only has integral cornerpoints
solving actually the same
as the discrete opt problem
gives an algorithm for all Hij values
Want to solve some discrete optVerter
s't every edgeisXi covered
O
xiI if i CSubset
0 ofwise
canbeSolved
est
n.Y.tn V edgesEig0PT2
OPT I op11
Take a Sdn to OPT Xi Xn
if x i 312 Ii 1
if Xi at I 0
Claim I is a valid solution to OP11