ADVANCED ALGORITHMS
Lecture 11: Review, flows/cuts
ADVANCED ALGORITHMS Lecture 11: Review, flows/cuts ANNOUNCEMENTS - - PDF document
ADVANCED ALGORITHMS Lecture 11: Review, flows/cuts ANNOUNCEMENTS 5 Hong g HW 1 grades out (?) Maheshakya 2 Amin 034 HW 2 due this Friday, 11:59 PM sravein I 43 gIouglegroups.com utah algo ta way ym.nu gym TODAYS PLAN Quick
Lecture 11: Review, flows/cuts
ANNOUNCEMENTS
➤ HW 1 grades out (?) ➤ HW 2 due this Friday, 11:59 PM
g
Hong
5
Maheshakya 2
Amin
034
sravein I 43 utah algo ta
gIouglegroups.com
gym
way ym.nu
TODAY’S PLAN
➤ Quick review/recap of course so far ➤ Comments about HW ➤ Flows and cuts in graphs ➤ Some applications of flows
DIVIDE & CONQUER
➤ Basic idea: divide instance into sub-problems, solve them recursively,
combine
➤ Usually sub-problems don’t overlap much ➤ Analysis by writing down a recurrence ➤ Usually prove correctness via induction ➤ How to solve a recurrence? (plug-n-chug, guess and prove, recurrence
tree, Akra-Bazzi, master theorem, …)
➤ Examples: multiplying n-bit numbers, merge sort, median finding
n time
DYNAMIC PROGRAMMING
➤ Basic idea: write down a recursive expression for quantity of interest,
store answers to all “sub-problems”
➤ Works well if # of distinct sub-problems is small ➤ Examples: subset sum, coin change, longest increasing subsequence,
…
➤ Key: how we write recurrence determines space/time ➤ See notes: top down vs bottom up
EXAMPLE — COIN CHANGE
➤ Problem: given k denominations of coins d1, d2, …, dk, find how to
make change for S cents using fewest number of coins
➤ One way: let m(S, i) be the min number of coins needed to make
change for S using coins di and above. Recurrence tries all possibilities for # of di coins:
m(S, i) = min
j : jdi≤S j + m(S − jdi, i + 1)
It
di dit
i dn
I min
m Spiti
It
m S di ith
TpaI
Stl
k
2tm
S 2di Itil
Time for.mgiyESdi
Std
EXAMPLE — COIN CHANGE
➤ Problem: given k denominations of coins d1, d2, …, dk, find how to
make change for S cents using fewest number of coins
➤ One way: let m(S, i) be the min number of coins needed to make
change for S using coins di and above. Recurrence tries all possibilities for # of di coins:
➤ Another: let f(S) be the min number of coins needed to make change
for S. Recurrence tries all possible coins:
m(S, i) = min
j : jdi≤S j + m(S − jdi, i + 1)
f(S) = min
i : di≤S f(S − di)
f s
min
changefor S
Observation
ft
E
It
f
S
di
for any
i
Obson 2
f s
min
It
f
s
di
denominations
is.t
di ES
Sp.ae
S
store all the ft
values
Time
S k
denom
s
2,33
5
5 s
saz
DYNAMIC PROGRAMMING
➤ Basic idea: write down a recursive expression for quantity of interest,
store answers to all “sub-problems”
➤ Works well if # of distinct sub-problems is small ➤ Examples: subset sum, coin change, longest increasing subsequence,
…
➤ Key: how we write recurrence determines space/time ➤ See notes: top down vs bottom up
GREEDY ALGORITHMS
➤ Basic idea: to make a sequence of choices, make one by one, best
choice in each step. Greedy == myopic
➤ Typically: ➤ easy to design algorithm & implement ➤ Not easy to analyze ➤ Doesn’t produce optimal answers ➤ Examples: matching gifts to children, scheduling, spanning trees,
hiring problem — first example of approximation — always at least 63% of optimum!
r
value
LOCAL SEARCH
➤ Basic idea: start with an arbitrary solution, and try to improve ➤ Typically: ➤ easy to design algorithm & implement ➤ how we swap determines running time (usually large) ➤ produces reasonable answers (esp in practice) ➤ Examples: matching gifts to children (always 1/2 of optimum),
gradient descent is example of local search
by changing a lilthbi
Pas
BASIC GRAPH ALGORITHMS
➤ Shortest paths ➤ Problem: given a directed graph with edge lengths, find the shortest
total length path from u to v. Can be done efficiently
➤ Bellman-Ford/Shimbel’s algorithm: maintain “candidate” dist[w]
values for all vertices w. Update all using dist[w] = min(dist[w], dist[i] + len(i, w)) for all edges (i,w)
➤ Takes n iterations, each taking m = |E| time ➤ Cool property: works also when graph has negative edges (but no
cycles)
F
Matri
p
tht
BASIC GRAPH ALGORITHMS
➤ Shortest paths ➤ Problem: given a directed graph with edge lengths, find the shortest
total length path from u to v. Can be done efficiently
➤ Dijkstra’s algorithm: maintain “candidate” dist[w] values for all
vertices w. Grow “ball of certain radius” around u.
➤ Add one vertex to ball in each iteration — pick one that has least
dist[] value; update dist[] values
➤ Properties: near linear time; doesn’t work with negative edges
Very similar to
minimum spanning hie
CUTS IN GRAPHS
➤ Problem: given a graph, find a small set of (weighted) edges to “cut”
so that the graph is disconnected.
➤ Variants: ➤ Separate given vertices u and v (called s-t cut) ➤ Break graph into two nearly equal pieces (partition) ➤ Maximize the number of edges going between the two pieces ➤ Each variant has many applications
r
O
distributed
maxut.im9 D
MIN S-T CUT
➤ Problem: given a directed graph with edge weights, find a small set of
(weighted) edges to “cut” so that there is no longer a direct path from s to t.
➤ origins
450
ed
goat
minimize total wt of edges out
so
as to disconnect t fwm
s
m
IEI
History
what is known
n
IVI
nems
Cz
Polynomial time algorithm
Ford Fulkerson
MY
Directed
graphs
are harder than
m
Ohm
n
undirectedones
Undirected graphs
unweighted
Okmtn bg I
903ns
David Karger
Radndomized algorithm 2015
Thorup
Kawarabayashi
MAXIMUM FLOW
Problemi
we are given
a weighted directed graph
intea wt of
an edge is
interpreted as the
capacity
Find
the
maximum
amount of
flow from given
source
s
to a t
sink
that does not violate
the
edge capacities 50
so
ALGORITHMS FOR FLOW?
Natural approaches
send someflow reduce
capacities appropriately
find if
another path exists etc does Not work
not optimal
Can
backtracking
in
a systematic
Yay
MAXIMUM FLOW VS MIN CUT
Value of
max
ftow
E
min cut