Find: a multiset M { 1,..., n } so that. i M w i W and. i M v i is maximized. Find: a set S { 1,..., n } so that. i S w i W and. i S v i is maximized.


 Nicholas Hoover
 1 years ago
 Views:
Transcription
1 Knapsack gain Slides for IS 675 PV hapter 6: ynamic Programming, Part 2 Jim Royer EES October 28, 2009 The Knapsack Problem (KP) knapsack with weight capacity W. Items 1,..., n where item i has weight w i and value v i.... with repetition Find: a multiset M 1,..., n } so that... without repetition Find: a set S 1,..., n } so that i S w i W and i S v i is maximized. Image from: IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21 Knapsack with repetition Knapsack without repetition, 1 Knapsack with repetition knapsack with capacity W. Items 1,..., n Item i has weight w i & value v i. Find: a multiset M 1,..., n } K(w) = max. value gained from a knapsack with cap. w = max i:w i w K(w w i) + v i (Why?) array K[0..W] K[0] 0 for w 1 to W do K[w] 0 for i 1 to n do if w i w then K[w] max(k[w], K[w w i ] + v i ) This runs in Θ(n W) time. Since we usually measure the size of W as W = the number of bits in the binary rep. of W. Hence, Θ(n W) = Θ(n 2 W ). So this is only useful for small values of W. Knapsack without repetition knapsack with capacity W. Items 1,..., n Item i has weight w i & value v i. Find: a set M 1,..., n } Problem K[w w n ] is not useful since it does not tell you whether item n was used in an optimal solution. Therefore, we refine things to: K[w, j] the best value obtainable with = capacity w using items from 1,..., j K[w, j 1], if w j > w; = max(k[w, j 1], K[w w j, j 1] + v j ), otherwise. (Why?) IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21
2 Knapsack without repetition, 2 Knapsack w/o repetition knapsack with capacity W. Items 1,..., n Item i has weight w i & value v i. Find: a set M 1,..., n } Our recursive relation is: K[w, j] the best value obtainable with = capacity w using items from 1,..., j K[w, j 1], if w j > w; = max(k[w, j 1], K[w w j, j 1] + v j ), otherwise. array K[0..W, 0..n] // This is also Θ(n W) time. for w 0 to W do K[w, 0] 0 // Hence only useful K[0, j] 0 // when W is small. for w 1 to W do if w i > w then K[w, j] K[w, j 1] else K[w, j] max(k[w, j 1], K[w w i, j 1] + v i ) IS 675 (EES) ynamic Programming, part 2 October 28, / 21 hain matrix multiplication, 1 Recall Multiplying an d 0 d 1 matrix by an d 1 d 2 matrix results in a d 0 d 2 matrix and takes (d 0 d 1 d 2 )many scalar multiplies. The hain Matrix Multiplication Problem (MMP) d 0,..., d n N + and matrices 1,..., n where dim( i ) = d i 1 d i. Find: The cheapest way to order the multiplications. Example: Suppose that is an matrix. is an 20 1 matrix. is an 1 10 matrix. is an matrix. Then: Parenthesization ost computation ost ( ( )) ,000 (( ) ) ,200 ( ) ( ) ,000 ( ( )) ,200 (( ) ) ,000 IS 675 (EES) ynamic Programming, part 2 October 28, / 21 hain matrix multiplication, 2 hain matrix multiplication, 3 Parenthesization ost computation ost ( ( )) ,000 (( ) ) ,200 ( ) ( ) ,000 ( ( )) ,200 (( ) ) ,000 The hain Matrix Multiplication Problem (MMP) d 0,..., d n N + and matrices 1,..., n where dim( i ) = d i 1 d i. Find: The cheapest way to order the multiplications. The (i, k) subproblem, 1 i k n Find: (i, k) = the min. cost of the i k. (i, i) = 0. (i, k) = min j=i,...,k 1 ((i, j) + (j + 1, k) + d i 1 d j d k ), where i < k. (1, n) is the minimal cost of the MMP for 1,..., n. Question: Why does optimal substructure hold? IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21
3 hain matrix multiplication, 4 The (i, k) subproblem, 1 i k n Find: (i, k) = the min. cost of the i k. (i, i) = 0. (i, k) = min j=i,...,k 1 (1, n) is the minimal cost of the MMP for 1,..., n. ( (i, j) + (j + 1, k) + di 1 d j d k ), where i < k. for i 1 to n do [i, i] 0 for s 1 to n 1 do // ompute [1, 1 + s], [2, 2 + s],..., [n s, n] for i 1 to n s do k i + s; [i, k] + for j i to k 1 do [i, k] min([i, k], [i, j] + [j + 1, k] + d i 1 d j d k return [1, n] Run Time: Θ(n 3 ). Question: How do you reconstruct the order of multiplication from the [, ] table? IS 675 (EES) ynamic Programming, part 2 October 28, / 21 Shortest paths: llpairs, 1 Vaughn Truth or onseq. Tucumcari lbuquerque lamogordo Taos Socorro Silver ity Santa Rosa Santa Fe Ruidoso Roswell Reserve Red River Raton Los lamos Portales Lordsburg Las Vegas IS 675 (EES) ynamic Programming, part 2 October 28, / 21 Las ruces Hobbs Farmington Gallup eming lovis layton hama arlsbad rtesia Shortest paths: llpairs, 2 Shortest paths: llpairs, 3 llpairs Shortest Paths Problem (PSP) G = ( 1,..., n }, E) an undirected graph and len:e R +. onstruct: S[1..n, 1..n] so that S[i, j] = the length of a shortest Gpath from i to j. ssumption: G is initially given by a matrix [1..n, 1..n] so that len(i, j), if (i, j) E; [i, j] = +, if (i, j) / E. PSP, restated: Given [1..n, 1..n], compute S[1..n, 1..n]. Question: What are good subproblems? is the approximation to S in which that paths have no vertices: ❶ ❸ ❶ ❷ ❸ llowing more and more vertices gives subproblems... vertices from 1,..., k } len(i, j), if (i, j) E; dist[i, j, 0] = [i, j] = +, if (i, j) / E. dist[i, j, n] = S[i, j] = the length of a shortest Gpath from i to j IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21
4 length of the shortest path from i to j in which only nodes 1, 2,..., k} can be used as interme diates. Initially, dist(i, j, 0) is the length of the direct edge between i and j, if it exists, and is Shortest paths: llpairs, 3 otherwise. a,.h. Papadimitriou, and U.V. Vazirani 187 Shortest paths: llpairs, 4 What happens when we expand the set to include an extra node k? We mus reexamine all pairs Question: i, j and check How do whether we go using from dist[, k as, an k 1] to dist[,, k], point where: gives us a shorter shortest paths path from i to j. ut this is easy: a shortest path from i to j that uses k along with possibly want to find the shortest path not just between s and t but between other all lowernumbered pairs nodes goes through k just once (why? because we assume One approach would be to execute our general shortestpath algorithm that there from are no negative cycles). nd we have already vertices from calculated 1,... the, k } length of the shortes.1 (since there may be the negative length of edges) a shortest V times, Gpath once from for i to each j using starting path node. from The i to k and from k to j using only lowernumbered vertices: ng time would then be O( V 2 E ). vertices We ll now from see 1, a.. better., k } alternative, the O( V 3 ) k ogrammingbased FloydWarshall len(i, algorithm. j), if (i, j) E; dist(i, k, k 1) is a good dist[i, subproblem j, 0] = [i, for j] = computing distances between all pairs of vertices in a +, if (i, j) / E. i dist(k, j, k 1) ply solving the problem for more and more pairs or starting points is unhelpful, leads right dist[i, back j, n] to= the S[i, O( V j] = 2 the E ) length algorithm. of a shortest Gpath from i to j a comes to mind: the shortest path u w 1 w l v between u and v dist(i, j, k 1) j number of nodes possibly none. Suppose we disallow ether. Then Question: we can How solve do we allpairs go from shortest dist[,, k paths 1] to at dist[, once:, k]? the shortest Thus, pathusing from k gives us a shorter path from i to j if and only if mply the direct edge (u, v), if it exists. What if we now gradually expand the set dist[i, j, k 1] = dist[i, j, k] means: there is a shortest path from i to j using dist(i, k, k vertices 1) + dist(k, from j, 1, k..., k 1) } that < dist(i, does not j, use k k. 1), ble nodes? We can do this one node at a time, updating the shortest s at each stage. Eventually this set grows to all of V, at which pointin allwhich vertices case dist(i, j, k) should be updated accordingly. to be on all paths, and we have found the true shortest paths between vertices Here isofthe FloydWarshall algorithm and as you can see, it takes O( V 3 ) time. IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21 ncretely, number the vertices in V as 1, 2,..., n}, and let dist(i, j, k) denote forthe i = 1 to n: e shortest path from i to j in which only nodes 1, 2,..., k} can be used as intermeially, for j = 1 to n: dist(i, j, 0) is the length of the direct edge between i and j, if it exists, and is dist(i, j, 0) = e. Shortest paths: llpairs, 5 appens when we expand the set to include an extra node k? We must Shortest paths: llpairs, 6 all pairs Question: i, j and check How do whether we go using from dist[, k as, an k 1] to dist[,, k], point where: gives us a shorter i to j. ut this is easy: a shortest path from i to j that uses k along with possibly Question: How do we go from dist[,, k 1] to dist[,, k]? numbered nodes goes through k just once (why? because we assume are no negative dist[i, cycles). j, k] = nd we have already vertices from calculated 1,... the, k } length of the shortest vertices from 1,..., k } to k and from k to j using only lowernumbered vertices: = min(dist[i, j, k 1], dist[i, k, k 1] + dist[k, j, k 1]). dist(i, k, k 1) k for i 1 to n do // Initialization i dist(k, j, k 1) dist[i, j, 0] [i, j] for i 1 to n do // Main iteration dist(i, j, k 1) j for k 1 to n do g k gives us a shorter path from i to j if and only if dist[i, j, k] min(dist[i, j, k 1], dist[i, j, k 1] = dist[i, j, k] means: shortest paths from i to j using dist[i, k, k 1] + dist[k, j, k 1]) for i dist(i, k, k vertices 1) + dist(k, from j, 1, k..., k 1) } must < dist(i, use k. j, k 1), 1 to n do // Output dist[i, k, k 1] + dist[k, j, k 1]. (Why?) S[i, j] dist[i, j, n] se dist(i, j, k) should be updated accordingly. the FloydWarshall algorithm and as you can see, it takes O( V 3 return S ) time. i = 1 to n: IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21
5 Shortest paths: llpairs, 7 The traveling salesman problem for i 1 to n do // Initialization dist[i, j, 0] [i, j] for i 1 to n do // Main iteration for k 1 to n do dist[i, j, k] min(dist[i, j, k 1], dist[i, k, k 1] + dist[k, j, k 1]) for i 1 to n do // Output S[i, j] dist[i, j, n] return S Time complexity: Θ( V 3 ). (Why?) Space complexity: lso Θ( V 3 ), but this is easy to improve to Θ( V 2 ). The traveling salesman problem G a complete graph on verts 1,..., n and d(i, j) = (the distance of i to j) < Find: minimal cost of a complete tour of G. Subproblems For S 1,..., n } with 1 S, and j S: the minimal cost of a path from [S, j] = 1 to j using just nodes in S. [S, 1] =, when S > 1. [S, j] = min [S j }, i] + dist(i, j). i (S j } Note: This is a set up for hapter There are at most 2 n nmany subproblems, and each one takes O(n) time to solve.!!! This takes O(n 2 2 n ) time!!! 2 IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21 Independent sets in trees, 1 Independent sets in trees, 2 efinition Suppose G = (V, E) is an undirected graph. (a) u and v V are independent when (u, v) / E. (b) U V is an independent set when every pair of elements from U are independent. The Independent Set Problem (ISP) G an undirected graph. Find: maxsized independent set for G. The Independent Set Problem for Trees T a tree. Find: maxsized independent set for T. Example In the graph below: 1, 4, 5 } is not an independent set. 1, 5 } and 1, 6 } are independent sets 2, 3, 6 } and 1, 4, 6 } are maxsized independent sets efinition Suppose G = (V, E) is an undirected graph. (a) u and v V are independent when (u, v) / E. (b) U V is an independent set when every pair of elements from U are independent. The Indep. Set Problem for Trees T a tree. Find: maxsized independent set for T. Strategy Pick some vertex of T as the root, r. Now each vertex of T is the root of a subtree. For each v in T, define I(v) = the size of a largest independent set in v s subtree. I(v) = 1 when v is a leaf. I(r) = the size of a largest indep. set in T. So, what is the recursion? IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21
6 Independent sets in trees, 3 Strategy Pick some vertex of T as the root, r. For each v in T: I(v) = the size of a largest indep. set in v s subtree. I(v) = 1 when v is a leaf and I(r) = the size of a largest indep. set in T. Wwhat is the recursion for I(u)? ase: u is in some maximal sized indep. set for u s subtree Then I(u) = 1 + I(v) : v is a grandchild of u }. ase: u is in no maximal sized indep. set for u s subtree Then I(u) = I(v) : v is a child of u }. Independent sets in trees, 4 Strategy Pick some vertex of T as the root, r. For each u in T compute: I(u) = the size of a largest indep. set in u s subtree = max ( 1 + v is a grandchild of u I(v), v is a child of u I(v) ) This can be done in Θ( V ) time. For the general graph case, O(2 V ) is the best known time. Note: This is another set up for hapter 8. I(u) = max ( 1 + v is a grandchild of u I(v), v is a child of u I(v) ) IS 675 (EES) ynamic Programming, part 2 October 28, / 21 IS 675 (EES) ynamic Programming, part 2 October 28, / 21
Dynamic Programming: Shortest Paths and DFA to Reg Exps
CS 374: Algorithms & Models of Computation, Fall 205 Dynamic Programming: Shortest Paths and DFA to Reg Exps Lecture 7 October 22, 205 Chandra & Manoj (UIUC) CS374 Fall 205 / 54 Part I Shortest Paths with
More informationDynamic Programming: Shortest Paths and DFA to Reg Exps
CS 374: Algorithms & Models of Computation, Spring 207 Dynamic Programming: Shortest Paths and DFA to Reg Exps Lecture 8 March 28, 207 Chandra Chekuri (UIUC) CS374 Spring 207 / 56 Part I Shortest Paths
More informationCS483 Design and Analysis of Algorithms
CS483 Design and Analysis of Algorithms Lectures 1516 Dynamic Programming Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm  6:00pm or by appointments
More informationChapter 8 Dynamic Programming
Chapter 8 Dynamic Programming Copyright 007 Pearson AddisonWesley. All rights reserved. Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by
More informationChapter 8 Dynamic Programming
Chapter 8 Dynamic Programming Copyright 2007 Pearson AddisonWesley. All rights reserved. Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by
More informationSlides for CIS 675. Huffman Encoding, 1. Huffman Encoding, 2. Huffman Encoding, 3. Encoding 1. DPV Chapter 5, Part 2. Encoding 2
Huffman Encoding, 1 EECS Slides for CIS 675 DPV Chapter 5, Part 2 Jim Royer October 13, 2009 A toy example: Suppose our alphabet is { A, B, C, D }. Suppose T is a text of 130 million characters. What is
More informationAllPairs Shortest Paths
AllPairs Shortest Paths Version of October 28, 2016 Version of October 28, 2016 AllPairs Shortest Paths 1 / 26 Outline Another example of dynamic programming Will see two different dynamic programming
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 03 Dynamic Programming (Chapter 15) Stephen Scott and Vinodchandran N. Variyam sscott@cse.unl.edu 1/44 Introduction Dynamic
More informationCSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms
CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms Professor Henry Carter Fall 2016 Recap Spacetime tradeoffs allow for faster algorithms at the cost of space complexity overhead Dynamic
More informationData Structures in Java
Data Structures in Java Lecture 21: Introduction to NPCompleteness 12/9/2015 Daniel Bauer Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways
More informationCS173 Lecture B, November 3, 2015
CS173 Lecture B, November 3, 2015 Tandy Warnow November 3, 2015 CS 173, Lecture B November 3, 2015 Tandy Warnow Announcements Examlet 7 is a takehome exam, and is due November 10, 11:05 AM, in class.
More informationAlgorithm Design CS 515 Fall 2015 Sample Final Exam Solutions
Algorithm Design CS 515 Fall 2015 Sample Final Exam Solutions Copyright c 2015 Andrew Klapper. All rights reserved. 1. For the functions satisfying the following three recurrences, determine which is the
More informationLecture 7: Shortest Paths in Graphs with Negative Arc Lengths. Reading: AM&O Chapter 5
Lecture 7: Shortest Paths in Graphs with Negative Arc Lengths Reading: AM&O Chapter Label Correcting Methods Assume the network G is allowed to have negative arc lengths but no directed negativelyweighted
More informationDynamic Programming (CLRS )
Dynamic Programming (CLRS..) Today we discuss a technique called dynamic programming. It is neither especially dynamic nor especially programming related. We will discuss dynamic programming by looking
More informationComputer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms
Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Limitations of Algorithms We conclude with a discussion of the limitations of the power of algorithms. That is, what kinds
More informationCMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015
NAME: CMPSCI 611 Advanced Algorithms Midterm Exam Fall 015 A. McGregor 1 October 015 DIRECTIONS: Do not turn over the page until you are told to do so. This is a closed book exam. No communicating with
More informationCS60007 Algorithm Design and Analysis 2018 Assignment 1
CS60007 Algorithm Design and Analysis 2018 Assignment 1 Palash Dey and Swagato Sanyal Indian Institute of Technology, Kharagpur Please submit the solutions of the problems 6, 11, 12 and 13 (written in
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of s Lecture 09 Dynamic Programming (Chapter 15) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 41 Spring 2010 Dynamic programming
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 22 AllPairs Shortest Paths Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 All Pairs
More informationDynamic Programming. Prof. S.J. Soni
Dynamic Programming Prof. S.J. Soni Idea is Very Simple.. Introduction void calculating the same thing twice, usually by keeping a table of known results that fills up as subinstances are solved. Dynamic
More informationCS 470/570 Dynamic Programming. Format of Dynamic Programming algorithms:
CS 470/570 Dynamic Programming Format of Dynamic Programming algorithms: Use a recursive formula But recursion can be inefficient because it might repeat the same computations multiple times So use an
More informationDynamic Programming( Weighted Interval Scheduling)
Dynamic Programming( Weighted Interval Scheduling) 17 November, 2016 Dynamic Programming 1 Dynamic programming algorithms are used for optimization (for example, finding the shortest path between two points,
More information1 Assembly Line Scheduling in Manufacturing Sector
Indian Institute of Information Technology Design and Manufacturing, Kancheepuram, Chennai 600 27, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 209T Design and Analysis
More informationDynamic Programming. p. 1/43
Dynamic Programming Formalized by Richard Bellman Programming relates to planning/use of tables, rather than computer programming. Solve smaller problems first, record solutions in a table; use solutions
More informationMaximum sum contiguous subsequence Longest common subsequence Matrix chain multiplication All pair shortest path Kna. Dynamic Programming
Dynamic Programming Arijit Bishnu arijit@isical.ac.in Indian Statistical Institute, India. August 31, 2015 Outline 1 Maximum sum contiguous subsequence 2 Longest common subsequence 3 Matrix chain multiplication
More informationIntroduction. I Dynamic programming is a technique for solving optimization problems. I Key element: Decompose a problem into subproblems, solve them
ntroduction Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 03 Dynamic Programming (Chapter 15) Stephen Scott and Vinodchandran N. Variyam Dynamic programming is a technique
More informationDynamic Programming ACM Seminar in Algorithmics
Dynamic Programming ACM Seminar in Algorithmics Marko GenykBerezovskyj berezovs@fel.cvut.cz Tomáš Tunys tunystom@fel.cvut.cz CVUT FEL, K13133 February 27, 2013 Problem: Longest Increasing Subsequence
More informationCS Algorithms and Complexity
CS 50  Algorithms and Complexity Linear Programming, the Simplex Method, and Hard Problems Sean Anderson 2/15/18 Portland State University Table of contents 1. The Simplex Method 2. The Graph Problem
More information1. (a) Explain the asymptotic notations used in algorithm analysis. (b) Prove that f(n)=0(h(n)) where f(n)=0(g(n)) and g(n)=0(h(n)).
Code No: R05220502 Set No. 1 1. (a) Explain the asymptotic notations used in algorithm analysis. (b) Prove that f(n)=0(h(n)) where f(n)=0(g(n)) and g(n)=0(h(n)). 2. (a) List some of the relative advantages
More informationCS/COE
CS/COE 1501 www.cs.pitt.edu/~nlf4/cs1501/ P vs NP But first, something completely different... Some computational problems are unsolvable No algorithm can be written that will always produce the correct
More informationCOL351: Analysis and Design of Algorithms (CSE, IITD, SemesterI ) Name: Entry number:
Name: Entry number: There are 5 questions for a total of 75 points. 1. (5 points) You are given n items and a sack that can hold at most W units of weight. The weight of the i th item is denoted by w(i)
More informationGeneral Methods for Algorithm Design
General Methods for Algorithm Design 1. Dynamic Programming Multiplication of matrices Elements of the dynamic programming Optimal triangulation of polygons Longest common subsequence 2. Greedy Methods
More informationLecture 13. More dynamic programming! Longest Common Subsequences, Knapsack, and (if time) independent sets in trees.
Lecture 13 More dynamic programming! Longest Common Subsequences, Knapsack, and (if time) independent sets in trees. Announcements HW5 due Friday! HW6 released Friday! Last time Not coding in an action
More informationQuiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)
Introduction to Algorithms October 13, 2010 Massachusetts Institute of Technology 6.006 Fall 2010 Professors Konstantinos Daskalakis and Patrick Jaillet Quiz 1 Solutions Quiz 1 Solutions Problem 1. We
More informationBKLUP PRELIMINARY SUMMARY REPORT JULY 2016
PARTICIPATED LAST MONTH TOTAL BLKUP HOURS OTHER Alamogordo PD 2 Otero 6 0 0 0 0 0 4 3 N/P Albuquerque PD 3 Bernalillo N/P Anthony PD 1 Dona Ana 4 0 0 0 0 0 3 0 Artesia PD 2 Eddy 16 0 0 0 0 3 9 0 N/P Aztec
More informationExercises NPcompleteness
Exercises NPcompleteness Exercise 1 Knapsack problem Consider the Knapsack problem. We have n items, each with weight a j (j = 1,..., n) and value c j (j = 1,..., n) and an integer B. All a j and c j
More informationAdvanced Analysis of Algorithms  Midterm (Solutions)
Advanced Analysis of Algorithms  Midterm (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu} 1 Problems 1. Solve the following recurrence using substitution:
More informationChapter 7 Network Flow Problems, I
Chapter 7 Network Flow Problems, I Network flow problems are the most frequently solved linear programming problems. They include as special cases, the assignment, transportation, maximum flow, and shortest
More informationLecture 6 September 21, 2016
ICS 643: Advanced Parallel Algorithms Fall 2016 Lecture 6 September 21, 2016 Prof. Nodari Sitchinava Scribe: Tiffany Eulalio 1 Overview In the last lecture, we wrote a nonrecursive summation program and
More informationCSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices
CSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices This lab consists of exercises on realvalued vectors and matrices. Most of the exercises will required pencil and paper. Put
More informationWeek 5: Quicksort, Lower bound, Greedy
Week 5: Quicksort, Lower bound, Greedy Agenda: Quicksort: Average case Lower bound for sorting Greedy method 1 Week 5: Quicksort Recall Quicksort: The ideas: Pick one key Compare to others: partition into
More informationBranchandBound. Leo Liberti. LIX, École Polytechnique, France. INF , Lecture p. 1
BranchandBound Leo Liberti LIX, École Polytechnique, France INF431 2011, Lecture p. 1 Reminders INF431 2011, Lecture p. 2 Problems Decision problem: a question admitting a YES/NO answer Example HAMILTONIAN
More informationCS Analysis of Recursive Algorithms and Brute Force
CS48305 Analysis of Recursive Algorithms and Brute Force Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 4:30pm  5:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/
More informationPractice Final Solutions. 1. Consider the following algorithm. Assume that n 1. line code 1 alg(n) { 2 j = 0 3 if (n = 0) { 4 return j
Practice Final Solutions 1. Consider the following algorithm. Assume that n 1. line code 1 alg(n) 2 j = 0 3 if (n = 0) 4 return j } 5 else 6 j = 2n+ alg(n 1) 7 return j } } Set up a recurrence relation
More informationDynamic Programming. Cormen et. al. IV 15
Dynamic Programming Cormen et. al. IV 5 Dynamic Programming Applications Areas. Bioinformatics. Control theory. Operations research. Some famous dynamic programming algorithms. Unix diff for comparing
More informationAlgorithm Design Strategies V
Algorithm Design Strategies V Joaquim Madeira Version 0.0 October 2016 U. Aveiro, October 2016 1 Overview The 01 Knapsack Problem Revisited The Fractional Knapsack Problem Greedy Algorithms Example Coin
More informationRandomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th
CSE 3500 Algorithms and Complexity Fall 2016 Lecture 10: September 29, 2016 Quick sort: Average Run Time In the last lecture we started analyzing the expected run time of quick sort. Let X = k 1, k 2,...,
More informationLimitations of Algorithm Power
Limitations of Algorithm Power Objectives We now move into the third and final major theme for this course. 1. Tools for analyzing algorithms. 2. Design strategies for designing algorithms. 3. Identifying
More informationCSE 202 Homework 4 Matthias Springer, A
CSE 202 Homework 4 Matthias Springer, A99500782 1 Problem 2 Basic Idea PERFECT ASSEMBLY N P: a permutation P of s i S is a certificate that can be checked in polynomial time by ensuring that P = S, and
More informationDiscrete Optimization 2010 Lecture 2 Matroids & Shortest Paths
Matroids Shortest Paths Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths Marc Uetz University of Twente m.uetz@utwente.nl Lecture 2: sheet 1 / 25 Marc Uetz Discrete Optimization Matroids
More informationAnalysis of Algorithms I: AllPairs Shortest Paths
Analysis of Algorithms I: AllPairs Shortest Paths Xi Chen Columbia University The AllPairs Shortest Paths Problem. Input: A directed weighted graph G = (V, E) with an edgeweight function w : E R. Output:
More informationMethods for solving recurrences
Methods for solving recurrences Analyzing the complexity of mergesort The merge function Consider the following implementation: 1 int merge ( int v1, int n1, int v, int n ) { 3 int r = malloc ( ( n1+n
More informationLecture 11. SingleSource Shortest Paths AllPairs Shortest Paths
Lecture. SingleSource Shortest Paths AllPairs Shortest Paths T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to, rd Edition, MIT Press, 009 Sungkyunkwan University Hyunseung Choo choo@skku.edu
More informationActivity selection. Goal: Select the largest possible set of nonoverlapping (mutually compatible) activities.
Greedy Algorithm 1 Introduction Similar to dynamic programming. Used for optimization problems. Not always yield an optimal solution. Make choice for the one looks best right now. Make a locally optimal
More informationIntro to Contemporary Math
Intro to Contemporary Math Hamiltonian Circuits and Nearest Neighbor Algorithm Nicholas Nguyen nicholas.nguyen@uky.edu Department of Mathematics UK Agenda Hamiltonian Circuits and the Traveling Salesman
More informationDominating Set Counting in Graph Classes
Dominating Set Counting in Graph Classes Shuji Kijima 1, Yoshio Okamoto 2, and Takeaki Uno 3 1 Graduate School of Information Science and Electrical Engineering, Kyushu University, Japan kijima@inf.kyushuu.ac.jp
More informationCS325: Analysis of Algorithms, Fall Final Exam
CS: Analysis of Algorithms, Fall 0 Final Exam I don t know policy: you may write I don t know and nothing else to answer a question and receive percent of the total points for that problem whereas a completely
More informationCS 6901 (Applied Algorithms) Lecture 3
CS 6901 (Applied Algorithms) Lecture 3 Antonina Kolokolova September 16, 2014 1 Representative problems: brief overview In this lecture we will look at several problems which, although look somewhat similar
More informationData Structures and Algorithms (CSCI 340)
University of Wisconsin Parkside Fall Semester 2008 Department of Computer Science Prof. Dr. F. Seutter Data Structures and Algorithms (CSCI 340) Homework Assignments The numbering of the problems refers
More informationRandomized Algorithms III Min Cut
Chapter 11 Randomized Algorithms III Min Cut CS 57: Algorithms, Fall 01 October 1, 01 11.1 Min Cut 11.1.1 Problem Definition 11. Min cut 11..0.1 Min cut G = V, E): undirected graph, n vertices, m edges.
More informationCombinatorial Optimization
Combinatorial Optimization Problem set 8: solutions 1. Fix constants a R and b > 1. For n N, let f(n) = n a and g(n) = b n. Prove that f(n) = o ( g(n) ). Solution. First we observe that g(n) 0 for all
More informationLecture 13. More dynamic programming! Longest Common Subsequences, Knapsack, and (if time) independent sets in trees.
Lecture 13 More dynamic programming! Longest Common Subsequences, Knapsack, and (if time) independent sets in trees. Announcements HW5 due Friday! HW6 released Friday! Last time Not coding in an action
More informationCS281A/Stat241A Lecture 19
CS281A/Stat241A Lecture 19 p. 1/4 CS281A/Stat241A Lecture 19 Junction Tree Algorithm Peter Bartlett CS281A/Stat241A Lecture 19 p. 2/4 Announcements My office hours: Tuesday Nov 3 (today), 12pm, in 723
More informationJuly 18, Approximation Algorithms (Travelling Salesman Problem)
Approximation Algorithms (Travelling Salesman Problem) July 18, 2014 The travellingsalesman problem Problem: given complete, undirected graph G = (V, E) with nonnegative integer cost c(u, v) for each
More informationNotes on the MatrixTree theorem and Cayley s tree enumerator
Notes on the MatrixTree theorem and Cayley s tree enumerator 1 Cayley s tree enumerator Recall that the degree of a vertex in a tree (or in any graph) is the number of edges emanating from it We will
More informationAlgorithms and Data Structures Final Lesson
Algorithms and Data Structures Final Lesson Michael Schwarzkopf https://www.uni weimar.de/de/medien/professuren/medieninformatik/grafische datenverarbeitung Bauhaus University Weimar July 11, 2018 (Corrected
More informationApplications of Binary Search
Applications of Binary Search The basic idea of a binary search can be used in many different places. In particular, any time you are searching for an answer in a search space that is somehow sorted, you
More informationIS 2610: Data Structures
IS 2610: Data Structures Graph April 12, 2004 Graph Weighted graph call it networks Shortest path between nodes s and t in a network Directed simple path from s to t with the property that no other such
More informationQuery Optimization: Exercise
Query Optimization: Exercise Session 6 Bernhard Radke November 27, 2017 Maximum Value Precedence (MVP) [1] Weighted Directed Join Graph (WDJG) Weighted Directed Join Graph (WDJG) 1000 0.05 R 1 0.005 R
More informationCSI 4105 MIDTERM SOLUTION
University of Ottawa CSI 4105 MIDTERM SOLUTION Instructor: Lucia Moura Feb 6, 2010 10:00 am Duration: 1:50 hs Closed book Last name: First name: Student number: There are 4 questions and 100 marks total.
More informationDynamic Programming: Matrix chain multiplication (CLRS 15.2)
Dynamic Programming: Matrix chain multiplication (CLRS.) The problem Given a sequence of matrices A, A, A,..., A n, find the best way (using the minimal number of multiplications) to compute their product.
More informationPartha Sarathi Mandal
MA 252: Data Structures and Algorithms Lecture 32 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati The AllPairs Shortest Paths Problem
More informationSolutions to Final Practice Problems 115
Solutions to Final Practice Problems 115 1. Given a sequence of n real numbers A 1... A n, determine in linear time a contiguous subsequence A i... A j (i j) for which the sum of elements in the subsequence
More informationLecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018
CS17 Integrated Introduction to Computer Science Klein Contents Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 1 Tree definitions 1 2 Analysis of mergesort using a binary tree 1 3 Analysis of
More informationUniversity of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016
University of Toronto Department of Electrical and Computer Engineering Final Examination ECE 345 Algorithms and Data Structures Fall 2016 Print your first name, last name, UTORid, and student number neatly
More informationDivide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14
Divide and Conquer Algorithms CSE 101: Design and Analysis of Algorithms Lecture 14 CSE 101: Design and analysis of algorithms Divide and conquer algorithms Reading: Sections 2.3 and 2.4 Homework 6 will
More informationSingle Source Shortest Paths
CMPS 00 Fall 017 Single Source Shortest Paths Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk Paths in graphs Consider a digraph G = (V, E) with an edgeweight
More information13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks
13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks Averagecase analysis Averagecase analysis of algorithms and data structures: Input is generated according to a known probability
More informationSanta Claus Schedules Jobs on Unrelated Machines
Santa Claus Schedules Jobs on Unrelated Machines Ola Svensson (osven@kth.se) Royal Institute of Technology  KTH Stockholm, Sweden March 22, 2011 arxiv:1011.1168v2 [cs.ds] 21 Mar 2011 Abstract One of the
More informationDo not turn this page until you have received the signal to start. Please fill out the identification section above. Good Luck!
CSC 373H5 F 2017 Midterm Duration 1 hour and 50 minutes Last Name: Lecture Section: 1 Student Number: First Name: Instructor: Vincent Maccio Do not turn this page until you have received the signal to
More informationDynamic Programming. Reading: CLRS Chapter 15 & Section CSE 6331: Algorithms Steve Lai
Dynamic Programming Reading: CLRS Chapter 5 & Section 25.2 CSE 633: Algorithms Steve Lai Optimization Problems Problems that can be solved by dynamic programming are typically optimization problems. Optimization
More informationWeek 7 Solution. The two implementations are 1. Approach 1. int fib(int n) { if (n <= 1) return n; return fib(n 1) + fib(n 2); } 2.
Week 7 Solution 1.You are given two implementations for finding the nth Fibonacci number(f Fibonacci numbers are defined by F(n = F(n 1 + F(n 2 with F(0 = 0 and F(1 = 1 The two implementations are 1. Approach
More informationNPComplete Problems
NPComplete Problems Max Bisection Is NPComplete max cut becomes max bisection if we require that S = V S. We shall reduce the more general max cut to max bisection. Add V isolated nodes to G to yield
More informationWeighted Activity Selection
Weighted Activity Selection Problem This problem is a generalization of the activity selection problem that we solvd with a greedy algorithm. Given a set of activities A = {[l, r ], [l, r ],..., [l n,
More informationDAA Unit II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad
DAA Unit II Greedy and Dynamic Programming By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad 1 Greedy Method 2 Greedy Method Greedy Principal: are typically
More information4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle
Directed Hamiltonian Cycle Chapter 8 NP and Computational Intractability Claim. G has a Hamiltonian cycle iff G' does. Pf. Suppose G has a directed Hamiltonian cycle Γ. Then G' has an undirected Hamiltonian
More informationMergesort and Recurrences (CLRS 2.3, 4.4)
Mergesort and Recurrences (CLRS 2.3, 4.4) We saw a couple of O(n 2 ) algorithms for sorting. Today we ll see a different approach that runs in O(n lg n) and uses one of the most powerful techniques for
More informationAlgorithms and Data Structures 2016 Week 5 solutions (Tues 9th  Fri 12th February)
Algorithms and Data Structures 016 Week 5 solutions (Tues 9th  Fri 1th February) 1. Draw the decision tree (under the assumption of alldistinct inputs) Quicksort for n = 3. answer: (of course you should
More informationLecture 18: More NPComplete Problems
6.045 Lecture 18: More NPComplete Problems 1 The Clique Problem a d f c b e g Given a graph G and positive k, does G contain a complete subgraph on k nodes? CLIQUE = { (G,k) G is an undirected graph with
More informationDynamic Programming. Reading: CLRS Chapter 15 & Section CSE 2331 Algorithms Steve Lai
Dynamic Programming Reading: CLRS Chapter 5 & Section 25.2 CSE 233 Algorithms Steve Lai Optimization Problems Problems that can be solved by dynamic programming are typically optimization problems. Optimization
More informationEven More on Dynamic Programming
Algorithms & Models of Computation CS/ECE 374, Fall 2017 Even More on Dynamic Programming Lecture 15 Thursday, October 19, 2017 Sariel HarPeled (UIUC) CS374 1 Fall 2017 1 / 26 Part I Longest Common Subsequence
More informationClustering using Mixture Models
Clustering using Mixture Models The full posterior of the Gaussian Mixture Model is p(x, Z, µ,, ) =p(x Z, µ, )p(z )p( )p(µ, ) data likelihood (Gaussian) correspondence prob. (Multinomial) mixture prior
More informationQuestion Paper Code :
www.vidyarthiplus.com Reg. No. : B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2011. Time : Three hours Fourth Semester Computer Science and Engineering CS 2251 DESIGN AND ANALYSIS OF ALGORITHMS (Regulation
More informationLecture 15  NP Completeness 1
CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) February 29, 2018 Lecture 15  NP Completeness 1 In the last lecture we discussed how to provide
More informationCSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo
CSE 431/531: Analysis of Algorithms Dynamic Programming Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Paradigms for Designing Algorithms Greedy algorithm Make a
More informationDynamic programming. Curs 2015
Dynamic programming. Curs 2015 Fibonacci Recurrence. nth Fibonacci Term INPUT: n nat QUESTION: Compute F n = F n 1 + F n 2 Recursive Fibonacci (n) if n = 0 then return 0 else if n = 1 then return 1 else
More informationCS Lunch. Dynamic Programming Recipe. 2 Midterm 2! Slides17  Segmented Least Squares.key  November 16, 2016
CS Lunch 1 Michelle Oraa Ali Tien Dao Vladislava Paskova Nan Zhuang Surabhi Sharma Wednesday, 12:15 PM Kendade 307 2 Midterm 2! Monday, November 21 In class Covers Greedy Algorithms Closed book Dynamic
More informationComputational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9
1 Computational Complexity and Intractability: An Introduction to the Theory of NP Chapter 9 2 Objectives Classify problems as tractable or intractable Define decision problems Define the class P Define
More informationCS325: Analysis of Algorithms, Fall Midterm
CS325: Analysis of Algorithms, Fall 2017 Midterm I don t know policy: you may write I don t know and nothing else to answer a question and receive 25 percent of the total points for that problem whereas
More information