CS60007 Algorithm Design and Analysis 2018 Assignment 1
|
|
- Vivien McDonald
- 5 years ago
- Views:
Transcription
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 red color). You are strongly encouraged to do all the problems for your own practice. The deadline is August 13, This is a preliminary version and may contain errors. Please send an to the instructors if you find any error. Thank you for your cooperation. 1. There is a sequence of n activities a 1, a 2,..., a n with corresponding utilities u 1, u 2,..., u n. You wish to perform all these n activities according to this sequence within k days. If you perform the activities from a i to a j for some 1 i j n on the j-th day, then your utility U j for the j-th day is max{u l : i l j}. Your total utility is k l=1 U l. Design a greedy algorithm to find the sequence of activities you will perform on every day which maximizes your total utility. 2. There are n jobs J 1, J 2,..., J n with duration a 1, a 2,..., a n N + and deadlines d 1, d 2,..., d n N respectively. All the jobs are available at the beginning (that is at time 0). If a job J l is completed at time t l with t l > d l then the utility u l incurred for job J l is 1 (which is a penalty); if t l d l, then u l = 1 (which is a profit). You have only one machine. So, you cannot process more than one jobs simultaneously. Every job, once started, must run till it finishes. Design a greedy algorithm to find the schedule for these n jobs which maximizes n l=1 u l. 3. We are given a decimal string s = (a 1, a 2,..., a n ) of n digits (that is a i N and 0 a i 9) and a positive integer k. Design an algorithm for find the lexicographic minimum string which can be obtained from s by performing at most k swaps. Note that we are allowed to swap consecutive elements only. 4. Suppose you have to give Re N to your friend. You have enough number of 500, 200, 100, 50, 20, 10 rupee notes each at your disposal. Your goal is to give Re N to your friend with minimum number of notes. For example, Re 600 can be changed 1
2 using 3 Re 200 notes as well as using 1 Re 500 note and 1 Re 100 note. However, the later one uses minimum number of notes. Either prove correctness or provide counter example of the following greedy strategy: keep picking highest denomination as much as you can! Provide a set of denominations for which the above greedy strategy will fail. 5. An independent set of an undirected graph G = (V, E) is a subset W V such that there does not exist any edge e = {u, v} E with both end points in W (that is, e W 1). An undirected graph G = (V, E) is called an interval graph if every vertex v V can be associated with some interval I v = [a, b) in R such that there is an edge e between u and v if and only if I u I v. Let G be an interval graph and {I v : v V} be the intervals associated with its vertices. Then design an algorithm for computing the size of a maximum independent set of G. 6. [15 marks] Let G = (V, E) be a connected, weighted graph. Let T and T be two MSTs of G and α R. Then the number of edges in T of weight α is the same as the number of edges in T of weight α. 7. Let G = (V, E) be a connected, weighted graph, v V be any vertex, and e be an edge with minimum weight among all the edges that incident on v. Prove that there exists a MST which includes the edge e. 8. Let G be a connected, weighted graph. Prove that, if all edge weights in G are distinct, then G has exactly one MST. 9. Let G = (V, E) be a connected, weighted graph. Let S V with S, S V, and e = argmin e E:e={u,v},u S,v V\S {w(e)}. Then there exists a MST T where e T. 10. Let G = (V, E) be a connected, weighted graph and e be an edge with minimum weight in G. Then prove that there exists a MST which includes the edge e. 11. [Independent Set of Binary Tree] Refer to the definition of Independent Set of an undirected graph in problem 5. In this exercise you will compute a maximum weighted independent set of a binary tree. Your algorithm will be given as input a pointer to the root of a binary tree. Each node v has a weight w(v) and two pointers left(v) and right(v) leading to the left and right children of v respectively; if a child is absent, the corresponding pointer is NULL. The weight of an independent set in a tree is the sum of the weights of the nodes in it. A maximum weight independent set is an independent set whose weight is maximum. (a) [4 marks] Derive a recursive relation for the weights of a maximum weight independent set of various subtrees. (b) [4 marks] Design an efficient algorithm to compute the weight of a maximum weight independent set of the input tree. 2
3 (c) [4 marks] Modify your algorithm to also compute a maximum weight independent set of the input tree, in addition to its weight. (d) [3 marks] Discuss running times of your algorithms. 12. Suppose a trader has a container vehicle capable of shipping at most W amount of goods (W is an integer). Suppose that he has n items {1,..., n}. Each item i has a price v i and an integral weight w i. The trader wants to ship a set S {1,..., n} of items of highest possible total price subject to the constraint that the total weight of the items is at most W. (a) [1.5 marks] Mathematically formulate the constraint of the trader. (b) [1.5 marks] Mathematically formulate the objective that the trader wants to maximize subject to his constraint. (c) [4 marks] For an integer W, let c(i, W) be the maximum total price of a set of items in {1,..., i} with total weight at most W. Derive a recursive relation for c(i, W). (d) [4 marks] Design an efficient algorithm for computing c(n, W). (e) [3 marks] Modify your algorithm to also find a set of items that correspond to c(n, W). (f) [1 marks] Discuss running times of your algorithms. 13. Consider the following properties of an undirected graph G with n vertices. (a) G is connected. (b) G is acyclic. (c) G has n 1 edges. Prove that if G satisfies any two of the above three properties, then G also satisfies the third property, i.e., (i) [2 marks] if G satisfies properties (a) and (b), then G satisfies property (c), (ii) [2 marks] if G satisfies properties (a) and (c), then G satisfies property (b), (iii) [2 marks] if G satisfies properties (b) and (c), then G satisfies property (a). As you must know, graphs satisfying these three properties are called trees. 14. We are given two English strings s 1 and s 2 of length n each. Design a dynamic programming based algorithm to find the minimum number of the following operations that one requires to perform on s 1 to convert it into s 2. Insert any symbol at any position of the string. 3
4 Delete any symbol from the string. Replace any symbol in the string by another symbol. 15. A string s is called a sub-sequence of another string t if s can be obtained from t by deleting some symbols from s. Design a dynamic programming based algorithm which finds a longest common sub-sequence of two input strings. 16. Design a dynamic programming based algorithm which finds a subset of a set of integers (given as an array of integers as input) which has maximum sum of its elements. 17. Design a dynamic programming based algorithm for problem 4 which works for any set of denominations. 18. There are n jobs J 1, J 2,..., J n with start and end times s 1, s 2,..., s n N and deadlines t 1, t 2,..., t n N respectively with t l > s l for every l [n]. The weight of the job J l is w l N for l [n]. You have only one machine. So, you cannot process more than one jobs simultaneously. Every job, once started, must run till it finishes. Design a dynamic programming based algorithm for the problem of scheduling a subset S {J l : l [n]} of jobs which maximizes J l S w l. 19. Suppose we have a stick of length n N +. Design a dynamic programming based algorithm to break the stick into at least 2 pieces of integral lengths which maximizes the product of the lengths of the pieces. 20. Suppose we have a stick of length n N +. Let p : N + N + be a function which maps every positive integer l to the utility of a stick of length l. Design a dynamic programming based algorithm to break the stick into pieces which maximizes the total utility (the sum of utilities of the pieces). Solutions Problem 6: For the sake of contradiction, let us assume that there exist two minimum spanning trees T 1 and T 2 of a graph G and α R such that the number of edges of weight α in T 1 and T 2 are not the same. Let us consider the set S = {T : T is a minimum spanning tree of G and there exists α R such that the number of edges of weight α in T 1 and T are not the same}. By our assumption S is not an empty set since we have T 2 S. Also since the input graph G is finite, S is also a finite set. Let T be a minimum spanning tree in S for which T 1 T is minimum possible where T 1 T denotes symmetric difference of the set of edges of T 1 and T. Such a T always exists since S is a non-empty and finite set. Let e T 1 \ T be any edge in T 1 \ T. Let us consider the subgraph F = T {e} of G. Since T is a tree, there exists a unique cycle C in F. Moreover, the C contains the edge {e}. Let the two components of T 1 \ {e} be H 1 and H 2. Since the cycle 4
5 C includes e, there exists an edge f C \ {e} with one end point in H 1 and the other end point in H 2. Clearly f / T 1 since otherwise there would be an edge (namely f) between H 1 and H 2 in T 1 \ {e}. We claim that w(f) w(e). Indeed, otherwise, F 1 = F \ {f} is a spanning tree of G of weight less than T which contradicts our assumption that T is an minimum spanning tree of G. So we have w(f) w(e). We also have w(f) w(e) since otherwise (T 1 \ {e}) {f} would be a spanning tree of G of weight less than T 1 contradicting our assumption that T 1 is an minimum spanning tree of G. Hence we have w(f) = w(e). However, then F 1 is a spanning tree of G of weight same as T and thus itself an minimum spanning tree of G. Moreover, for every positive integer α, the number of edges of weight α in F 1 and T are the same. Hence we have F 1 S. However, we have T 1 F 1 < T 1 T which contradicts our choice of T. This concludes the proof of the statement. Problem 11 (a) Let v be either NULL, or a pointer to a vertex of the tree. Let MIND(v) be defined as follows: { 0 if v is NULL, MIND(v) = the size of a maximum independent set of the subtree rooted at v otherwise. Clearly, MIND(v) = 1 if v is a leaf. Now, let v be an internal node, and let v l and v r be its left and right children respectively. If v is NULL, assume that v l and v r are both NULL. case 1: A maximum independent set of the subtree rooted at v does not include v. Then, it is the union of maximum independent sets of the subtrees rooted at v l and v r. MIND(v) = MIND(v l ) + MIND(v r ). case 2: A maximum independent set of the subtree rooted at v includes v. Then, it is the union of {v} and maximum independent sets of the subtrees rooted at the grandchildren of v. Note that some of the grandchildren may be NULL. MIND(v) = 1 + MIND((v l ) l ) + MIND((v l ) r ) + MIND((v r ) l ) + MIND((v r ) r ). Combining the two subcases above, we get the following recurrence relation for MIND(v). 0 if v is NULL, MIND(v) = 1 if v is a leaf, max{mind(v l ) + MIND(v r ), 1 + MIND((v l ) l ) + MIND((v l ) r )+ MIND((v r ) l ) + MIND((v r ) r )} 5 otherwise
6 Notice that in the recursive expression of MIND(v) only vertices whose heights are strictly less than that of v are used. (b) The above recurrence reveals an optimal substructure property. Notice that a recursive algorithm based on part (a) will suffer from the overlapping subproblems. So, how about trying dynamic programming? We are given the root pointer. So it may be convenient to retain the recursive structure of our algorithm, and do memoization. Let r be the input root pointer. Let MIND(v) be a global table, with one entry for each vertex. FINDMIND(r) returns the size of a maximum independent set of the input tree. Algorithm 1 FINDMIND(r) 1: Do a breadth-first traversal on the tree. For each vertex v, MIND(v) 0. 2: return IND(r). Algorithm 2 IND(v) 1: if v = NULL then 2: return 0. 3: end if 4: if MIND(v) > 0 then 5: return MIND(v). 6: end if 7: MIND(v) max{ind(v l ) + IND(v r ), 1 + IND((v l ) l ) + IND((v l ) r ) + IND((v r ) l ) + IND((v r ) r )}. 8: return MIND(v). (c) For each v maintan the information of whether or not v is included in the maximum independent set of the subtree rooted at v that your algorithm computes. Let it be stored in the global table ININD. IND mod is the modified IND function. IND mod fills up the table ININD. Finally, output the set of vertices v for which ININD[v] = 1. (d) Running time is O( V ). Problem 12 (a) i S w i W. (b) i S v i. (c) Let T be a set of items from {1,..., i} with total weight at most W of maximum total price, i.e., j T v j = c(i, W). 6
7 Algorithm 3 IND mod (v) 1: if v = NULL then 2: return 0. 3: end if 4: if MIND(v) > 0 then 5: return MIND(v). 6: end if 7: val1 IND(v l ) + IND(v r ). 8: val2 1 + IND mod ((v l ) l ) + IND mod ((v l ) r ) + IND mod ((v r ) l ) + IND mod ((v r ) r ). 9: if val1 val2 then 10: ININD[v] 0. 11: MIND(v) val1. 12: return MIND(v). 13: end if 14: ININD[v] 1. 15: MIND(v) val2. 16: return MIND(v). case1: i / T: In this case T is also a set of items from {1,..., i 1} with total weight at most W of maximum total price. Thus c(i, W) = c(i 1, W). case 2: i T: In this case, w i W and T \ {i} is a set of items from {1,..., i 1} with total weight at most W w i of maximum total price. Thus, c(i, W) = v i + c(i 1, W w i ). From the above two cases we have that 0 if i = 1 and w i > W, v c(i, W) = i if i = 1 and w i W, c(i 1, W) if i > 1and w i > W, max{c(i 1, W), v i + c(i 1, W w i )} if i > 1and w i W. (d) Use dynamic programming. A recursive program will suffer from overlapping subproblems. Recall that w i s are all integers. Let the global table T stores the solutions of various c(i, W) s. The first step is initializing all its entries to 1. Then update it using the algorithm KNAPSACK. Finally return T(n, W). We use memoization here; but you can do iterative table-filling also. (e) Easy. Modify the KNAPSACK algorithm to also store whether or not i is included in the solution. Let this information be kept in the 2-dimensional global array A; A(i, w) stores whether or not the element i is included in the optimal solution when the set of items is {1,..., i} and the weight limit is W. The algorithm KNAPSACK-MODIFIED (see pseudocode) fills up the table A. The set of items can be retrieved from the table A as follows: First, check if A(n, W) = 1. If A(n, W) = 1, include n in the set, 7
8 Algorithm 4 KNAPSACK (i, W) 1: if i=0 then 2: return 0. 3: end if 4: if T(i, W) > 1 then 5: return T(i, W). 6: end if 7: val1 KNAPSACK(i 1, W). 8: if w i > W then 9: T(i, W) val1. 10: return T(i, W). 11: end if 12: val2 KNAPSACK(i 1, W w i ) + v i. 13: if val1 val2 then 14: T(i, W) val1. 15: else 16: T(i, W) val2. 17: end if 18: return T(i, W). and then check if A(n 1, W w n ) = 1 to decide whether or not to include n 1. If A(n, W) = 0, then do not include n in the set, and check if A(n 1, W) = 1 to decide whether or not to include n 1. Continue similarly. The algorithm FINDSET (see pseudocode) does this. (f) Same order as the number of subproblems. O(nW). Problem 13 Let G = (V, E). (i) The proof is by induction on n. Base case: n = 1. Number of edges is 0 = n 1. Induction step: Assume that the hypothesis is true for all graphs of at most n 1 vertices, for n 1. Now consider a graph G with n vertices that satisfies properties (a) and (b). Now consider any maximal path v 1,..., v k in G 1. Since the graph is acyclic, from the maximality of the path it follows that the degree of vertex v 1 (also v k ) is 1 2. Consider the subgraph G of G induced by the vertex set V \ {v 1 }. Note that the number of edges in G is E 1. Also, observe that G is connected and acyclic. Since G has n 1 vertices, by inductive hypothesis, we have that the number of edges E 1 in G is equal to (n 1) 1 = n 2, which implies that E = n 1 and the proof is complete. 1 a path is maximal if it cannot be extended any more in either direction. 2 such vertices are called leaves. 8
9 Algorithm 5 KNAPSACK-MODIFIED (i, W) 1: if i=0 then 2: return 0. 3: end if 4: if T(i, W) > 1 then 5: return T(i, W). 6: end if 7: val1 KNAPSACK(i 1, W). 8: if w i > W then 9: A(i, W) 0. 10: T(i, W) val1. 11: return T(i, W). 12: end if 13: val2 KNAPSACK(i 1, W w i ) + v i. 14: if val1 val2 then 15: A(i, W) 0. 16: T(i, W) val1. 17: else 18: A(i, W) 1. 19: T(i, W) val2. 20: end if 21: return T(i, W). (ii) Proof by contradiction. Assume that G satisfies properties (a) and (c), and G has a cycle. Then we modify G in the following way: As long as G has a cycle, remove an edge from that cycle. Notice that these operations preserve the connectivity of G. Thus at the end we get a graph which is connected and acyclic, but has strictly less than n 1 edges. This contradicts (i). (iii) Proof by contradiction. Assume that G satisfies properties (b) and (c), and G is not connected. Thus G has at least two connected components. Now modify G as follows: As long as G is not connected, add an edge between two vertices in two different connected components. Note that these operations preserve acyclicity of G. At the end, we get a graph which is connected, acyclic and has strictly more than n 1 vertices. This contradicts (i). 9
10 Algorithm 6 FINDSET 1: weight W. 2: S. 3: for i = n to 1 do 4: if A(i, weight) = 1 then 5: S S {i}. 6: weight weight w i. 7: end if 8: end for 9: return S. 10
Greedy Algorithms My T. UF
Introduction to Algorithms Greedy Algorithms @ UF Overview A greedy algorithm always makes the choice that looks best at the moment Make a locally optimal choice in hope of getting a globally optimal solution
More informationFINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)
FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) The final exam will be on Thursday, May 12, from 8:00 10:00 am, at our regular class location (CSI 2117). It will be closed-book and closed-notes, except
More information/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17
601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 12.1 Introduction Today we re going to do a couple more examples of dynamic programming. While
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 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 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 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 informationCOL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) 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 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 informationCPSC 320 (Intermediate Algorithm Design and Analysis). Summer Instructor: Dr. Lior Malka Final Examination, July 24th, 2009
CPSC 320 (Intermediate Algorithm Design and Analysis). Summer 2009. Instructor: Dr. Lior Malka Final Examination, July 24th, 2009 Student ID: INSTRUCTIONS: There are 6 questions printed on pages 1 7. Exam
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 informationDynamic 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 informationTree Decompositions and Tree-Width
Tree Decompositions and Tree-Width CS 511 Iowa State University December 6, 2010 CS 511 (Iowa State University) Tree Decompositions and Tree-Width December 6, 2010 1 / 15 Tree Decompositions Definition
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 informationCS Analysis of Recursive Algorithms and Brute Force
CS483-05 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 information1 Basic Definitions. 2 Proof By Contradiction. 3 Exchange Argument
1 Basic Definitions A Problem is a relation from input to acceptable output. For example, INPUT: A list of integers x 1,..., x n OUTPUT: One of the three smallest numbers in the list An algorithm A solves
More informationAside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n
Aside: Golden Ratio Golden Ratio: A universal law. Golden ratio φ = lim n a n+b n a n = 1+ 5 2 a n+1 = a n + b n, b n = a n 1 Ruta (UIUC) CS473 1 Spring 2018 1 / 41 CS 473: Algorithms, Spring 2018 Dynamic
More information1 Some loose ends from last time
Cornell University, Fall 2010 CS 6820: Algorithms Lecture notes: Kruskal s and Borůvka s MST algorithms September 20, 2010 1 Some loose ends from last time 1.1 A lemma concerning greedy algorithms and
More information13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks
13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks Average-case analysis Average-case analysis of algorithms and data structures: Input is generated according to a known probability
More informationMore Dynamic Programming
CS 374: Algorithms & Models of Computation, Spring 2017 More Dynamic Programming Lecture 14 March 9, 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 42 What is the running time of the following? Consider
More informationThis means that we can assume each list ) is
This means that we can assume each list ) is of the form ),, ( )with < and Since the sizes of the items are integers, there are at most +1pairs in each list Furthermore, if we let = be the maximum possible
More informationMore Dynamic Programming
Algorithms & Models of Computation CS/ECE 374, Fall 2017 More Dynamic Programming Lecture 14 Tuesday, October 17, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 48 What is the running time of the following?
More informationLecture 2: Divide and conquer and Dynamic programming
Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results 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 informationAlgorithms: COMP3121/3821/9101/9801
NEW SOUTH WALES Algorithms: COMP3121/3821/9101/9801 Aleks Ignjatović School of Computer Science and Engineering University of New South Wales TOPIC 4: THE GREEDY METHOD COMP3121/3821/9101/9801 1 / 23 The
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 informationDynamic Programming. Data Structures and Algorithms Andrei Bulatov
Dynamic Programming Data Structures and Algorithms Andrei Bulatov Algorithms Dynamic Programming 18-2 Weighted Interval Scheduling Weighted interval scheduling problem. Instance A set of n jobs. Job j
More informationCSE 421 Dynamic Programming
CSE Dynamic Programming Yin Tat Lee Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs compatible if they don t overlap. Goal: find maximum
More informationCS 161: Design and Analysis of Algorithms
CS 161: Design and Analysis of Algorithms Greedy Algorithms 3: Minimum Spanning Trees/Scheduling Disjoint Sets, continued Analysis of Kruskal s Algorithm Interval Scheduling Disjoint Sets, Continued Each
More informationDynamic programming. Curs 2017
Dynamic programming. Curs 2017 Fibonacci Recurrence. n-th 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 374: Algorithms & Models of Computation, Spring 2017 Greedy Algorithms Lecture 19 April 4, 2017 Chandra Chekuri (UIUC) CS374 1 Spring / 1
CS 374: Algorithms & Models of Computation, Spring 2017 Greedy Algorithms Lecture 19 April 4, 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 1 Part I Greedy Algorithms: Tools and Techniques Chandra
More informationCSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD
Course Overview Material that will be covered in the course: Basic graph algorithms Algorithm Design Techniques Greedy Algorithms Divide and Conquer Dynamic Programming Network Flows Computational intractability
More informationLecture 9. Greedy Algorithm
Lecture 9. Greedy Algorithm T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018
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 informationAlgorithm Design and Analysis (NTU CSIE, Fall 2017) Homework #3. Homework #3. Due Time: 2017/12/14 (Thu.) 17:20 Contact TAs:
Instructions and Announcements Homework #3 ue Time: 017/1/14 (Thu.) 17:0 Contact TAs: ada-ta@csie.ntu.edu.tw There are four programming problems and two handwritten problems. Programming. The judge system
More informationDynamic programming. Curs 2015
Dynamic programming. Curs 2015 Fibonacci Recurrence. n-th 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 informationCSE 202 Dynamic Programming II
CSE 202 Dynamic Programming II Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally,
More informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and
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 informationNATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours
NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: 2017 2018 Time Allowed 2 Hours INSTRUCTIONS TO STUDENTS 1. This assessment consists of Eight (8) questions and comprises
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 information2. A vertex in G is central if its greatest distance from any other vertex is as small as possible. This distance is the radius of G.
CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh (rezab@stanford.edu) HW#1 Due at the beginning of class Thursday 01/21/16 1. Prove that at least one of G and G is connected. Here, G
More information4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd
4.8 Huffman Codes These lecture slides are supplied by Mathijs de Weerd Data Compression Q. Given a text that uses 32 symbols (26 different letters, space, and some punctuation characters), how can we
More informationAlgorithms Exam TIN093 /DIT602
Algorithms Exam TIN093 /DIT602 Course: Algorithms Course code: TIN 093, TIN 092 (CTH), DIT 602 (GU) Date, time: 21st October 2017, 14:00 18:00 Building: SBM Responsible teacher: Peter Damaschke, Tel. 5405
More informationFundamental Algorithms
Fundamental Algorithms Chapter 5: Searching Michael Bader Winter 2014/15 Chapter 5: Searching, Winter 2014/15 1 Searching Definition (Search Problem) Input: a sequence or set A of n elements (objects)
More informationDynamic Programming: Interval Scheduling and Knapsack
Dynamic Programming: Interval Scheduling and Knapsack . Weighted Interval Scheduling Weighted Interval Scheduling Weighted interval scheduling problem. Job j starts at s j, finishes at f j, and has weight
More information(a) Write a greedy O(n log n) algorithm that, on input S, returns a covering subset C of minimum size.
Esercizi su Greedy Exercise 1.1 Let S = {[a 1, b 1 ], [a 2, b 2 ],..., [a n, b n ]} be a set of closed intervals on the real line. We say that C S is a covering subset for S if, for any interval [a, b]
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 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 informationOn improving matchings in trees, via bounded-length augmentations 1
On improving matchings in trees, via bounded-length augmentations 1 Julien Bensmail a, Valentin Garnero a, Nicolas Nisse a a Université Côte d Azur, CNRS, Inria, I3S, France Abstract Due to a classical
More informationGreedy. Outline CS141. Stefano Lonardi, UCR 1. Activity selection Fractional knapsack Huffman encoding Later:
October 5, 017 Greedy Chapters 5 of Dasgupta et al. 1 Activity selection Fractional knapsack Huffman encoding Later: Outline Dijkstra (single source shortest path) Prim and Kruskal (minimum spanning tree)
More informationLecture 7: Dynamic Programming I: Optimal BSTs
5-750: Graduate Algorithms February, 06 Lecture 7: Dynamic Programming I: Optimal BSTs Lecturer: David Witmer Scribes: Ellango Jothimurugesan, Ziqiang Feng Overview The basic idea of dynamic programming
More informationdirected weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time
Network Flow 1 The Maximum-Flow Problem directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time 2 Maximum Flows and Minimum Cuts flows and cuts max flow equals
More informationGreedy Algorithms and Data Compression. Curs 2018
Greedy Algorithms and Data Compression. Curs 2018 Greedy Algorithms A greedy algorithm, is a technique that always makes a locally optimal choice in the myopic hope that this choice will lead to a globally
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 informationCSCE 750 Final Exam Answer Key Wednesday December 7, 2005
CSCE 750 Final Exam Answer Key Wednesday December 7, 2005 Do all problems. Put your answers on blank paper or in a test booklet. There are 00 points total in the exam. You have 80 minutes. Please note
More informationShortest paths with negative lengths
Chapter 8 Shortest paths with negative lengths In this chapter we give a linear-space, nearly linear-time algorithm that, given a directed planar graph G with real positive and negative lengths, but no
More informationCSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure
CSE Weighted Interval Scheduling, Knapsack, RNA Secondary Structure Shayan Oveis haran Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs
More informationCMSC 451: Lecture 7 Greedy Algorithms for Scheduling Tuesday, Sep 19, 2017
CMSC CMSC : Lecture Greedy Algorithms for Scheduling Tuesday, Sep 9, 0 Reading: Sects.. and. of KT. (Not covered in DPV.) Interval Scheduling: We continue our discussion of greedy algorithms with a number
More information8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM
8. INTRACTABILITY I poly-time reductions packing and covering problems constraint satisfaction problems sequencing problems partitioning problems graph coloring numerical problems Lecture slides by Kevin
More information8.5 Sequencing Problems
8.5 Sequencing Problems Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE,
More informationKnapsack and Scheduling Problems. The Greedy Method
The Greedy Method: Knapsack and Scheduling Problems The Greedy Method 1 Outline and Reading Task Scheduling Fractional Knapsack Problem The Greedy Method 2 Elements of Greedy Strategy An greedy algorithm
More informationCS173 Running Time and Big-O. Tandy Warnow
CS173 Running Time and Big-O Tandy Warnow CS 173 Running Times and Big-O analysis Tandy Warnow Today s material We will cover: Running time analysis Review of running time analysis of Bubblesort Review
More informationMatching Residents to Hospitals
Midterm Review Matching Residents to Hospitals Goal. Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and
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 informationCMPSCI 311: Introduction to Algorithms Second Midterm Exam
CMPSCI 311: Introduction to Algorithms Second Midterm Exam April 11, 2018. Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question. Providing more
More informationMA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3
MA008 p.1/37 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/37 Exercise 1 (from LN 2) Asymptotic Notation When constants appear in exponents
More informationAlgorithm Design Strategies V
Algorithm Design Strategies V Joaquim Madeira Version 0.0 October 2016 U. Aveiro, October 2016 1 Overview The 0-1 Knapsack Problem Revisited The Fractional Knapsack Problem Greedy Algorithms Example Coin
More informationUNIVERSITY OF CALIFORNIA, RIVERSIDE
UNIVERSITY OF CALIFORNIA, RIVERSIDE DEPARTMENT OF COMPUTER SCIENCE 2006 DEPTH EXAMINATION IN THEORY OF OF COMPUTATION AND ALGORITHMS There are 10 problems on the test. Each problem is worth 10 points.
More informationOn shredders and vertex connectivity augmentation
On shredders and vertex connectivity augmentation Gilad Liberman The Open University of Israel giladliberman@gmail.com Zeev Nutov The Open University of Israel nutov@openu.ac.il Abstract We consider the
More information6. DYNAMIC PROGRAMMING I
6. DYNAMIC PROGRAMMING I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013
More informationRecoverable Robustness in Scheduling Problems
Master Thesis Computing Science Recoverable Robustness in Scheduling Problems Author: J.M.J. Stoef (3470997) J.M.J.Stoef@uu.nl Supervisors: dr. J.A. Hoogeveen J.A.Hoogeveen@uu.nl dr. ir. J.M. van den Akker
More informationMatroids. Start with a set of objects, for example: E={ 1, 2, 3, 4, 5 }
Start with a set of objects, for example: E={ 1, 2, 3, 4, 5 } Start with a set of objects, for example: E={ 1, 2, 3, 4, 5 } The power set of E is the set of all possible subsets of E: {}, {1}, {2}, {3},
More informationBinary Search Trees. Motivation
Binary Search Trees Motivation Searching for a particular record in an unordered list takes O(n), too slow for large lists (databases) If the list is ordered, can use an array implementation and use binary
More informationCS675: Convex and Combinatorial Optimization Fall 2016 Combinatorial Problems as Linear and Convex Programs. Instructor: Shaddin Dughmi
CS675: Convex and Combinatorial Optimization Fall 2016 Combinatorial Problems as Linear and Convex Programs Instructor: Shaddin Dughmi Outline 1 Introduction 2 Shortest Path 3 Algorithms for Single-Source
More informationDiscrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees
, 2009 Lecture 5: Shortest Paths & Spanning Trees University of Twente m.uetz@utwente.nl wwwhome.math.utwente.nl/~uetzm/dw/ Shortest Path Problem "#$%&'%()*%"()$#+,&- Given directed "#$%&'()*+,%+('-*.#/'01234564'.*,'7+"-%/8',&'5"4'84%#3
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 informationBinary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016
Binary Search Trees Lecture 29 Section 19.2 Robb T. Koether Hampden-Sydney College Fri, Apr 8, 2016 Robb T. Koether (Hampden-Sydney College) Binary Search Trees Fri, Apr 8, 2016 1 / 40 1 Binary Search
More informationProof methods and greedy algorithms
Proof methods and greedy algorithms Magnus Lie Hetland Lecture notes, May 5th 2008 1 Introduction This lecture in some ways covers two separate topics: (1) how to prove algorithms correct, in general,
More informationCS 6783 (Applied Algorithms) Lecture 3
CS 6783 (Applied Algorithms) Lecture 3 Antonina Kolokolova January 14, 2013 1 Representative problems: brief overview of the course In this lecture we will look at several problems which, although look
More information25. Minimum Spanning Trees
695 25. Minimum Spanning Trees Motivation, Greedy, Algorithm Kruskal, General Rules, ADT Union-Find, Algorithm Jarnik, Prim, Dijkstra, Fibonacci Heaps [Ottman/Widmayer, Kap. 9.6, 6.2, 6.1, Cormen et al,
More informationExact Algorithms for Dominating Induced Matching Based on Graph Partition
Exact Algorithms for Dominating Induced Matching Based on Graph Partition Mingyu Xiao School of Computer Science and Engineering University of Electronic Science and Technology of China Chengdu 611731,
More information25. Minimum Spanning Trees
Problem Given: Undirected, weighted, connected graph G = (V, E, c). 5. Minimum Spanning Trees Motivation, Greedy, Algorithm Kruskal, General Rules, ADT Union-Find, Algorithm Jarnik, Prim, Dijkstra, Fibonacci
More informationAlgorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University
Algorithms NP -Complete Problems Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr The Class P Definition 13.2 Polynomially bounded An algorithm is said to be polynomially bounded if its worst-case
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 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 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 informationCS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle
8.5 Sequencing Problems Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE,
More informationGRAPH ALGORITHMS Week 3 (16-21 October 2017)
GRAPH ALGORITHMS Week 3 (16-21 October 2017) C. Croitoru croitoru@info.uaic.ro FII October 15, 2017 1 / 63 OUTLINE Graph Theory Vocabulary 1 Definition of a Graph 2 Variations in the Definition of a Graph
More informationCSC236H Lecture 2. Ilir Dema. September 19, 2018
CSC236H Lecture 2 Ilir Dema September 19, 2018 Simple Induction Useful to prove statements depending on natural numbers Define a predicate P(n) Prove the base case P(b) Prove that for all n b, P(n) P(n
More informationAditya Bhaskara CS 5968/6968, Lecture 1: Introduction and Review 12 January 2016
Lecture 1: Introduction and Review We begin with a short introduction to the course, and logistics. We then survey some basics about approximation algorithms and probability. We also introduce some of
More informationCSE 591 Foundations of Algorithms Homework 4 Sample Solution Outlines. Problem 1
CSE 591 Foundations of Algorithms Homework 4 Sample Solution Outlines Problem 1 (a) Consider the situation in the figure, every edge has the same weight and V = n = 2k + 2. Easy to check, every simple
More informationIn-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2
In-Class Soln 1 Let f(n) be an always positive function and let g(n) = f(n) log n. Show that f(n) = o(g(n)) CS 361, Lecture 4 Jared Saia University of New Mexico For any positive constant c, we want to
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 informationCS781 Lecture 3 January 27, 2011
CS781 Lecture 3 January 7, 011 Greedy Algorithms Topics: Interval Scheduling and Partitioning Dijkstra s Shortest Path Algorithm Minimum Spanning Trees Single-Link k-clustering Interval Scheduling Interval
More informationCS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi
CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs Instructor: Shaddin Dughmi Outline 1 Introduction 2 Shortest Path 3 Algorithms for Single-Source Shortest
More information1 T 1 = where 1 is the all-ones vector. For the upper bound, let v 1 be the eigenvector corresponding. u:(u,v) E v 1(u)
CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh (rezab@stanford.edu) Final Review Session 03/20/17 1. Let G = (V, E) be an unweighted, undirected graph. Let λ 1 be the maximum eigenvalue
More information7.4 DO (uniqueness of minimum-cost spanning tree) Prove: if all edge weights are distinct then the minimum-cost spanning tree is unique.
Algorithms CMSC-700 http://alg1.cs.uchicago.edu Homework set #7. Posted -19. Due Wednesday, February, 01 The following problems were updated on -0: 7.1(a), 7.1(b), 7.9(b) Read the homework instructions
More informationACO Comprehensive Exam October 18 and 19, Analysis of Algorithms
Consider the following two graph problems: 1. Analysis of Algorithms Graph coloring: Given a graph G = (V,E) and an integer c 0, a c-coloring is a function f : V {1,,...,c} such that f(u) f(v) for all
More informationFall 2017 November 10, Written Homework 5
CS1800 Discrete Structures Profs. Aslam, Gold, & Pavlu Fall 2017 November 10, 2017 Assigned: Mon Nov 13 2017 Due: Wed Nov 29 2017 Instructions: Written Homework 5 The assignment has to be uploaded to blackboard
More information