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
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 7 ➤ Usually prove correctness via induction ➤ How to solve a recurrence? (plug-n-chug, guess and prove, recurrence tree, Akra-Bazzi, master theorem, …) n time ➤ Examples: multiplying n -bit numbers, merge sort, median finding
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 d 1 , d 2 , …, d k , find how to make change for S cents using fewest number of coins It ➤ One way: let m(S, i) be the min number of coins needed to make change for S using coins d i and above. Recurrence tries all possibilities i dn di dit for # of d i coins: I m ( S , i ) = min j : jd i ≤ S j + m ( S − jd i , i + 1) m S di ith m Spiti It min S 2di Itil T paI Stl k 2tm Std Time for.mg iyES di overall times
EXAMPLE — COIN CHANGE ➤ Problem: given k denominations of coins d 1 , d 2 , …, d k , 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 d i and above. Recurrence tries all possibilities for # of d i coins: m ( S , i ) = min j : jd i ≤ S j + m ( S − jd i , i + 1) ➤ Another: let f(S) be the min number of coins needed to make change for S. Recurrence tries all possible coins: f ( S ) = min i : d i ≤ S f ( S − d i )
of coins needed to make f s min change for S Observation ft f for any di S i E It Obson 2 f It di s f s min denominations is.t di ES store all the ft values S Sp.ae S k Time denom 2,33 s 5 5 saz 0 s
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: r ➤ 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! value
LOCAL SEARCH ➤ Basic idea: start with an arbitrary solution, and try to improve by changing a lilthbi ➤ Typically: Pas ➤ 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
It 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 e ffi ciently ➤ 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) F ➤ Takes n iterations, each taking m = |E| time ➤ Cool property: works also when graph has negative edges (but no cycles) tht Matri p
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 e ffi ciently ➤ 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 minimum spanning hie Very similar to
NEXT: CUTS & FLOWS
CUTS IN GRAPHS ➤ Problem: given a graph, find a small set of (weighted) edges to “cut” so that the graph is disconnected . ➤ Variants: ii r O ➤ Separate given vertices u and v (called s-t cut) ➤ Break graph into two nearly equal pieces (partition) distributed ➤ Maximize the number of edges going between the two pieces ➤ Each variant has many applications maxut.im 9 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 ed to t . 450 ➤ origins ot yo minimize total wt of edges out goat as to disconnect t fwm s so
IEI m what is known IVI History n Cz nems Ford Fulkerson Polynomial time algorithm MY are harder than Directed graphs Ohm undirected ones n m Undirected graphs unweighted Okmtn bg I 903ns David Karger Radndomized algorithm Thorup 2015 Kawarabayashi
MAXIMUM FLOW a weighted directed graph we are given Problemi interpreted as the capacity an edge is intea wt of flow from given amount of maximum Find the that does not violate to a t sink s source edge capacities the 50 0 o so iii
ALGORITHMS FOR FLOW? send some flow Natural approaches capacities appropriately reduce another path exists etc find if not optimal does Not work in a systematic Can backtracking Yay
MAXIMUM FLOW VS MIN CUT E ftow Value of max min cut of T fahe onto
Recommend
More recommend