DESIGN AND ANALYSIS OF ALGORITHMS (DAA 2017)
|
|
- Susanna Walters
- 5 years ago
- Views:
Transcription
1 DESIGN AND ANALYSIS OF ALGORITHMS (DAA 2017) Veli Mäkinen Design and Analysis of Algorithms 2017 week
2 Dynamic Programming Week 4 2 Design and Analysis of Algorithms 2017 week
3 Longest Increasing Subsequence Example on typical steps for deriving a dynamic programming algorithm 3 Design and Analysis of Algorithms 2017 week
4 LONGEST INCREASING SUBSEQUENCE (LIS) Find a longest subsequence of strictly increasing numbers: A=1, 5, 3, 6, 4, 7 Invent the definition of a table / recurrence to compute L[j] = length of the LIS of A[1..j] ending with A[j] Now, find a dependency among L[j] values such that there is a proper evaluation order to compute them (left to right in this case): L[j] = max 0 i<j {L[i]+1 : A[i]<A[j]}, for 1 j n, and L[0] = 0; A[0]=- (initialization) Show pseudocode to illustrate evaluation order and analyse running time. Prove correctess by induction. Show how to traceback an optimal solution. Design and Analysis of Algorithms 2017 week
5 LIS EXAMPLE L[6]=? 1<4 3<4 L[7]=? A=1, 5, 3, 6, 4, 7 A=1, 5, 3, 6, 4, 7 max max L=1, 2, 2, 3, 3 L=1, 2, 2, 3, 3, 4 Traceback all optimal solutions: A=1, 5, 3, 6, 4, 7 L=1, 2, 2, 3, 3, 4 A=1, 5, 3, 6, 4, 7 L=1, 2, 2, 3, 3, 4 A=1, 5, 3, 6, 4, 7 L=1, 2, 2, 3, 3, 4 Design and Analysis of Algorithms 2017 week
6 LEN, J, L = LIS(A[1..N]) L[0]=0; A[0]=- /* Initialization*/ For j=1 to n do /*evaluation order*/ L[j]=0 /* temporary max*/ For i=0 to j-1 do /* O(n 2 ) */ If A[i]<A[j] and L[i]+1>L[j] then L[j] = L[i]+1 /* update of temporary max */ lenmax = 0; indexmax=0 /* max L[i], argmax L[i] */ For j=1 to n do if L[j]>lenMax then (lenmax, indexmax) = (L[j],j) Return (lenmax, indexmax,l) Design and Analysis of Algorithms 2017 week
7 A = TRACEBACKLIS(A[1..N], L[1..N],J) A = empty stack While j>0 do A.Push(A[j]) For i=0 to j-1 do Return A If A[i]<A[j] and L[i]+1=L[j] then j=i; (break) (Popping from A returns a longest increasing subsequence of A in proper order) Design and Analysis of Algorithms 2017 week
8 LIS: OPTIMAL SUBPROBLEM PROPERTY Assume by induction that L[1..j-1] is correctly computed with the recurrence. If L[j] > max 0 i<j {L[i]+1 : A[i]<A[j]}, there would be a subsequence ending with some A[i], 0<i<j, of length L[j]-1, contradicting the optimality of L[i]. Also, any subsequence ending with A[i], A[i]<A[j], could be extended with A[j] to obtain a subsequence of length L[i]+1. Hence the recurrence is correct. (Check the base case.) This tight connection with the dynamic programming table values is called optimal subproblem property. In literature, full induction proofs for obvious cases are typically omitted by referring to this property holding. yet there are cases where the connection is more elaborate Design and Analysis of Algorithms 2017 week
9 ALTERNATIVE: REDUCTION TO SHORTEST PATH n arcs c(i,j)=-1 n arcs 0 i j n+1 Let A[0]=- and A[n+1]=. DAG G=(V,E) with vertices V={0,1,,n+1} and arcs E defined as (i,j) E if A[i]<A[j]. Source s=0 and target t=n+1. Arc costs c(i,j)=-1, except for c(i,n+1)=0. Cost of shortest s-t path = - OPT LIS, where OPT LIS denotes the length of the longest increasing subsequence. Design and Analysis of Algorithms 2017 week
10 ANOTHER REDUCTION TO SHORTEST PATH n arcs c(i,j)=j-i-1 n arcs 0 i j n+1 Maximizing subsequence length = minimizing number of elements deleted from A Let A[0]=- and A[n+1]=. DAG G=(V,E) with vertices V={0,1,,n+1} and arcs E defined as (i,j) E if A[i]<A[j]. Source s=0 and target t=n+1. Arc costs c(i,j)=j-i-1. Cost of shortest s-t path = n-opt LIS. Design and Analysis of Algorithms 2017 week
11 Segmentation problem Another example of the power of dynamic programming 11 Design and Analysis of Algorithms 2017 week
12 SEGMENTATION PROBLEM Clustering in 1D Clustering in >=2D is NP-hard Clustering in ID is known as the segmentation problem and can be solved efficiently by dynamic programming Design and Analysis of Algorithms 2017 week
13 SEGMENTATION PROBLEM: MOTIVATION A company owns real estates and the CEO requests a map with colour codes showing different property price ranges Design and Analysis of Algorithms 2017 week
14 SEGMENTATION PROBLEM: MOTIVATION Design and Analysis of Algorithms 2017 week
15 SEGMENTATION: MOTIVATION 2 Compression boosting: Partition a string A[1..n] into segments that compress better by tailored compressor for each segment. E.g. ababbbacdaccddbbbaabaab Let c(i,j) give the compression result for segment A[i..j]. Then an optimal partitioning of A is one with the sum of its segment costs being minimum. Design and Analysis of Algorithms 2017 week
16 SEGMENTATION: RECURRENCE Let us consider a table S[1..n,1..n] with S[j,k] storing the cost of an optimal segmentation of the prefix A[1..j] of the input array A[1..n] into k segments. We have S[j, k] = min i [1..j 1] S i, k 1 + c(i + 1, j). This recurrence considers all possible ending positions of segmentations with k-1 segments and adds the cost of adding one more segment. With the optimal subproblem property one can see this works correctly, assuming a suitable initialization for the boundary cases (exercise) and a suitable evaluation order is used (exercise). Design and Analysis of Algorithms 2017 week
17 1D CLUSTERING: GENERIC DEFINITION Input: An array A[1..n] containing an increasing series of numbers, and parameter k. 1D clustering problem : Find cluster centers C=c 1, c 2,, c k that minimize total deviation, sumdev(a,c), when each A[i] is connected to its nearest center: sumdev(a,c)=σ a A min c C dev a, c. k clusters definition? Design and Analysis of Algorithms 2017 week
18 1D CLUSTERING: L2 AND AVERAGE To fix a definition, let us define dev(x,y)=(y-x) 2 [L2 norm] Then an optimal center of a cluster is the average of the values, since that will minimize the total deviation from the center (omitting the proof here). Observation: Centers C form a segmentation (partitioning) of A into A=A[1..i 1 ][A[i 1 +1 i 2 ] A[i k-1 n], where 1 i 1 < i 2 < i k 1 <n, such that numbers in A[i k +1 i k +1 ] are closest to c k +1 among centers in C. c 1 k clusters segment= 1d cluster Design and Analysis of Algorithms 2017 week
19 1D CLUSTERING: L2 AND AVERAGE Now, we seek for segmentation A=A[1..i 1 ][A[i 1 +1 i 2 ] A[i k- 1 n] minimizing σk k =1 c L2 (i k 1+1..ik ), where i 1 =0 and i k =n, and c c L2 (a..c)=σ b=a dev(a b, AVG(A[a.. c])), where c AVG(A[a..c])=σ b=a A b /(c a + 1). A[1..3]=0,4, Clustering with k=1 AVG(0,4,5)=3 c L2 (1..3)=(3-0) 2 +(3-4) 2 +(3-5) 2 =14 Design and Analysis of Algorithms 2017 week
20 1D CLUSTERING: RECURRENCE devmin[j,k ]= minimum total deviation after segmenting A[1..j] into k segments devmin[j,k ]=min i<j devmin [i,k -1]+c L2 (i+1..j) k -1 clusters min C sumdev(a,c) = devmin[n,k] (optimal solution) O(n 3 k) running time with direct implementation Optimizations, extensions, correctness, initialization, traceback in study groups & exercises. + i i+1 j Design and Analysis of Algorithms 2017 week
21 1D CLUSTERING: EVALUATION ORDER devmin[j,k ]=min i<j devmin [i,k -1]+c L2 (i+1..j) Evaluation order: k -1 k i min ( ) + cost of arc j Column-by-column (above), row-by-row, Design and Analysis of Algorithms 2017 week
22 1D CLUSTERING: RECAP+INITIALIZATION A devmin[0..n,0..k] 0 k -1 k k k -1 min cost to segment A[1..i] to k -1 pieces more segments than points: d[i,k ]=, for k >i i AVG dev() min i<j devmin[..] + cost of arc j cost to add segment A[i+1..j] n min cost to segment A[1..j] to k pieces optimum solution: traceback following arcs 0 segments only possible for empty sequence: d[i,0]=, except d[0,0]=0
23 Optimal chain of matrix multiplications Dynamic programming is not always a shortest path problem 23 Design and Analysis of Algorithms 2017 week
24 OPTIMAL CHAIN OF MATRIX MULTIPLICATIONS m p p n x = n O(npm) time m m p q q n x m x p = n Design and Analysis of Algorithms 2017 week
25 OPTIMAL CHAIN OF MATRIX MULTIPLICATIONS m p q q n x m x p = n npm+nqp multiplications n=10, m=15, p=7, q=4: 1330 multiplications n m x m p x p q = n q mqp+nqm multiplications n=10, m=15, p=7, q=4: 1470 multiplications Design and Analysis of Algorithms 2017 week
26 OPTIMAL CHAIN OF MATRIX MULTIPLICATIONS Find an optimal order to multiply n matrices A 1, A 2,.., A n with dimensions l 1 l 2, l 2 l 3,, l n d, where d=l n + 1 M(i,j)= minimum cost to multiply A i, A i+1,.., A j M(i,j)=min k:i k j {M(i,k) +M(k+1,j) +l i l j + 1 l k + 1 }. A i A i+1 A k l k + 1 A k+1 A j l j + 1 l j + 1 l i x = l i l k + 1 Design and Analysis of Algorithms 2017 week
27 OPTIMAL CHAIN: PSEUDOCODE M(i,j): /* this is slow.*/ If i=j return 0 value = For k=i to j-1 do value = min(value, M(i,k)+M(k+1,j)+l(1)*l(j+1)*l(k+1)) return value return M(1,n) m[i,j]= for all i,j MM(i,j): /* memoized variant, this is fast.*/ If i=j {m[i,i]=0; return 0} If m[i,j]= then For k=i to j-1 do m[i,j] = min(m[i,j], MM(i,k)+MM(k+1,j)+l(1)*l(j+1)*l(k+1)) return m[i,j] return MM(1,n) Design and Analysis of Algorithms 2017 week
28 OPTIMAL CHAIN: ANALYSIS Each vertex of the dependency DAG created ones O(n 3 ) time Better to unroll the recursion by computing intervals of length 1,2,3,,n, in that order (see the book) M(i,k) M(i,j) M(k+1,j) Optimization over directed hyperedges Design and Analysis of Algorithms 2017 week
29 OPTIMAL RECURSION TREE AND BALANCED PARANTHESES x x x A B x x C D E F ((AxB)x((CxD)x(ExF))) Design and Analysis of Algorithms 2017 week
30 Range minimum query problem Another example of the power of dynamic programming 30 Design and Analysis of Algorithms 2017 week
31 LCA VS RMQ v x r x w=lca(c,f) x A B p x x q min C D E F Height= DFS= rvavbvrwpcpdpwqeqfqwr arg min LCA = lowest common ancestor RMQ= range minimum query Design and Analysis of Algorithms 2017 week
32 RMQ: DYNAMIC PROGRAMMING Later in the course: O(n log n) time dynamic programming algorithm to preprocess an array for O(1) time range minimum queries. [Section 3: A Faster RMQ Algorithm] Bender & Farach-Colton. The LCA Problem Revisited. LATIN Same article also uses Cartesian trees, reductions, and so-called four-russians technique to improve preprocessing to optimal O(n) time (under RAM model of computation). Design and Analysis of Algorithms 2017 week
33 DYNAMIC PROGRAMMING IN OTHER COURSES Viterbi (kind of clustering, segmentation) Biological Sequence Analysis, period III, 2018 Shortest paths, edit distance, sequence alignment Algorithms for Bioinformatics, period I, 2017 String Processing Methods, period II, 2018 Biological Sequence Analysis, period III, 2018 In many others as a common tool Design and Analysis of Algorithms 2017 week
y j LCS-Length(X,Y) Running time: O(st) set c[i,0] s and c[0,j] s to 0 for i=1 to s for j=1 to t if x i =y j then else if
Recursive solution for finding LCS of X and Y if x s =y t, then find an LCS of X s-1 and Y t-1, and then append x s =y t to this LCS if x s y t, then solve two subproblems: (1) find an LCS of X s-1 and
More information14 Dynamic. Matrix-chain multiplication. P.D. Dr. Alexander Souza. Winter term 11/12
Algorithms Theory 14 Dynamic Programming (2) Matrix-chain multiplication P.D. Dr. Alexander Souza Optimal substructure Dynamic programming is typically applied to optimization problems. An optimal solution
More information12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares
12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares Optimal substructure Dynamic programming is typically applied to optimization problems. An optimal solution to the original
More informationData Structures and Algorithms Week 8
Data Structures and Algorithms Week 8 Dynamic programming Fibonacci numbers Optimization problems Matrix multiplication optimization Principles of dynamic programming Longest Common Subsequence Algorithm
More informationSo far... Finished looking at lower bounds and linear sorts.
So far... Finished looking at lower bounds and linear sorts. Next: Memoization -- Optimization problems - Dynamic programming A scheduling problem Matrix multiplication optimization Longest Common Subsequence
More informationLecture 13: Chain Matrix Multiplication
Lecture 3: Chain Matrix Multiplication CLRS Section 5.2 Revised April 7, 2003 Outline of this Lecture Recalling matrix multiplication. The chain matrix multiplication problem. A dynamic programming algorithm
More informationLecture 57 Dynamic Programming. (Refer Slide Time: 00:31)
Programming, Data Structures and Algorithms Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institution Technology, Madras Lecture 57 Dynamic Programming (Refer Slide Time:
More informationHomework3: Dynamic Programming - Answers
Most Exercises are from your textbook: Homework3: Dynamic Programming - Answers 1. For the Rod Cutting problem (covered in lecture) modify the given top-down memoized algorithm (includes two procedures)
More informationLecture 8. Dynamic Programming
Lecture 8. Dynamic Programming 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 informationLecture 4: Dynamic programming I
Lecture : Dynamic programming I Dynamic programming is a powerful, tabular method that solves problems by combining solutions to subproblems. It was introduced by Bellman in the 950 s (when 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 5: DYNAMIC PROGRAMMING COMP3121/3821/9101/9801 1 / 38
More informationIntroduction to Algorithms I
Summer School on Algorithms and Optimization Organized by: ACM Unit, ISI and IEEE CEDA. Tutorial II Date: 05.07.017 Introduction to Algorithms I (Q1) A binary tree is a rooted tree in which each node has
More informationDynamic Programming Group Exercises
Name: Name: Name: Dynamic Programming Group Exercises Adapted from material by Cole Frederick Please work the following problems in groups of 2 or 3. Use additional paper as needed, and staple the sheets
More informationDynamic Programming (Part #2)
Dynamic Programming (Part #) Introduction to Algorithms MIT Press (Chapter 5) Matrix-Chain Multiplication Problem: given a sequence A, A,, A n, compute the product: A A A n Matrix compatibility: C = A
More informationAlgorithms for Bioinformatics
Adapted from slides by Leena Salmena and Veli Mäkinen, which are partly from http: //bix.ucsd.edu/bioalgorithms/slides.php. 582670 Algorithms for Bioinformatics Lecture 6: Distance based clustering and
More informationPartha Sarathi Manal
MA 515: Introduction to Algorithms & MA353 : Design and Analysis of Algorithms [3-0-0-6] Lecture 29 http://www.iitg.ernet.in/psm/indexing_ma353/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.
More informationPractical Session No. 12 Graphs, BFS, DFS, Topological sort
Practical Session No. 12 Graphs, BFS, DFS, Topological sort Graphs and BFS Graph G = (V, E) Graph Representations (V G ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in
More informationCS473-Algorithms I. Lecture 10. Dynamic Programming. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 1 Dynamic Programming 1 Introduction An algorithm design paradigm like divide-and-conquer Programming : A tabular method (not writing computer code) Divide-and-Conquer (DAC):
More informationChapter 3 Dynamic programming
Chapter 3 Dynamic programming 1 Dynamic programming also solve a problem by combining the solutions to subproblems. But dynamic programming considers the situation that some subproblems will be called
More informationChain Matrix Multiplication
Chain Matrix Multiplication Version of November 5, 2014 Version of November 5, 2014 Chain Matrix Multiplication 1 / 27 Outline Outline Review of matrix multiplication. The chain matrix multiplication problem.
More information/463 Algorithms - Fall 2013 Solution to Assignment 3
600.363/463 Algorithms - Fall 2013 Solution to Assignment 3 (120 points) I (30 points) (Hint: This problem is similar to parenthesization in matrix-chain multiplication, except the special treatment on
More informationCMPSCI 311: Introduction to Algorithms Practice Final Exam
CMPSCI 311: Introduction to Algorithms Practice Final Exam Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question. Providing more detail including
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 7 April 15, 2015 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 7 April 15, 2015 洪國寶 1 Course information (5/5) Grading (Tentative) Homework 25% (You may collaborate when solving the homework, however when writing
More informationCMPS 2200 Fall Dynamic Programming. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk
CMPS 00 Fall 04 Dynamic Programming Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 9/30/4 CMPS 00 Intro. to Algorithms Dynamic programming Algorithm design technique
More informationUML CS Algorithms Qualifying Exam Fall, 2003 ALGORITHMS QUALIFYING EXAM
NAME: This exam is open: - books - notes and closed: - neighbors - calculators ALGORITHMS QUALIFYING EXAM The upper bound on exam time is 3 hours. Please put all your work on the exam paper. (Partial credit
More informationCSE 4/531 Solution 3
CSE 4/531 Solution 3 Edited by Le Fang November 7, 2017 Problem 1 M is a given n n matrix and we want to find a longest sequence S from elements of M such that the indexes of elements in M increase and
More informationEfficient Sequential Algorithms, Comp309. Problems. Part 1: Algorithmic Paradigms
Efficient Sequential Algorithms, Comp309 Part 1: Algorithmic Paradigms University of Liverpool References: T. H. Cormen, C. E. Leiserson, R. L. Rivest Introduction to Algorithms, Second Edition. MIT Press
More informationDynamic Programming II
June 9, 214 DP: Longest common subsequence biologists often need to find out how similar are 2 DNA sequences DNA sequences are strings of bases: A, C, T and G how to define similarity? DP: Longest common
More informationDynamic Programming part 2
Dynamic Programming part 2 Week 7 Objectives More dynamic programming examples - Matrix Multiplication Parenthesis - Longest Common Subsequence Subproblem Optimal structure Defining the dynamic recurrence
More informationECE250: Algorithms and Data Structures Dynamic Programming Part B
ECE250: Algorithms and Data Structures Dynamic Programming Part B Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University
More informationFramework for Design of Dynamic Programming Algorithms
CSE 441T/541T Advanced Algorithms September 22, 2010 Framework for Design of Dynamic Programming Algorithms Dynamic programming algorithms for combinatorial optimization generalize the strategy we studied
More informationPractice Sheet 2 Solutions
Practice Sheet 2 Solutions 28th August, 2016 Dynamic Programming 1. Question: Given an array of n positive integers a 1,, a n, give an algorithm to find the length of the longest subsequence a i1,, a ik
More informationCSE 101, Winter Design and Analysis of Algorithms. Lecture 11: Dynamic Programming, Part 2
CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 11: Dynamic Programming, Part 2 Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Goal: continue with DP (Knapsack, All-Pairs SPs, )
More informationDynamic Programming. Design and Analysis of Algorithms. Entwurf und Analyse von Algorithmen. Irene Parada. Design and Analysis of Algorithms
Entwurf und Analyse von Algorithmen Dynamic Programming Overview Introduction Example 1 When and how to apply this method Example 2 Final remarks Introduction: when recursion is inefficient Example: Calculation
More informationCS 473: Fundamental Algorithms, Spring Dynamic Programming. Sariel (UIUC) CS473 1 Spring / 42. Part I. Longest Increasing Subsequence
CS 473: Fundamental Algorithms, Spring 2011 Dynamic Programming Lecture 8 February 15, 2011 Sariel (UIUC) CS473 1 Spring 2011 1 / 42 Part I Longest Increasing Subsequence Sariel (UIUC) CS473 2 Spring 2011
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 7 April 6, 2016 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 7 April 6, 2016 洪國寶 1 Course information (5/5) Grading (Tentative) Homework 25% (You may collaborate when solving the homework, however when writing up
More informationCS 177. Lists and Matrices. Week 8
CS 177 Lists and Matrices Week 8 1 Announcements Project 2 due on 7 th March, 2015 at 11.59 pm Table of Contents Lists Matrices Traversing a Matrix Construction of Matrices 3 Just a list of numbers 1D
More informationDynamic Programming: 1D Optimization. Dynamic Programming: 2D Optimization. Fibonacci Sequence. Crazy 8 s. Edit Distance
Dynamic Programming: 1D Optimization Fibonacci Sequence To efficiently calculate F [x], the xth element of the Fibonacci sequence, we can construct the array F from left to right (or bottom up ). We start
More information1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)
Dynamic programming is a problem solving method that is applicable to many different types of problems. I think it is best learned by example, so we will mostly do examples today. 1 Rod cutting Suppose
More informationD-BAUG Informatik I. Exercise session: week 5 HS 2018
1 D-BAUG Informatik I Exercise session: week 5 HS 2018 Homework 2 Questions? Matrix and Vector in Java 3 Vector v of length n: Matrix and Vector in Java 3 Vector v of length n: double[] v = new double[n];
More informationLowest Common Ancestor(LCA)
Lowest Common Ancestor(LCA) Fayssal El Moufatich Technische Universität München St. Petersburg JASS 2008 1 Introduction LCA problem is one of the most fundamental algorithmic problems on trees. It is concerned
More information2.3 Optimal paths. Optimal (shortest or longest) paths have a wide range of applications:
. Optimal paths Optimal (shortest or longest) paths have a wide range of applications: Google maps, GPS navigators planning and management of transportation, electrical and telecommunication networks project
More information1 Non greedy algorithms (which we should have covered
1 Non greedy algorithms (which we should have covered earlier) 1.1 Floyd Warshall algorithm This algorithm solves the all-pairs shortest paths problem, which is a problem where we want to find the shortest
More informationAlgorithms and Data Structures 2014 Exercises and Solutions Week 9
Algorithms and Data Structures 2014 Exercises and Solutions Week 9 November 26, 2014 1 Directed acyclic graphs We are given a sequence (array) of numbers, and we would like to find the longest increasing
More informationScan and its Uses. 1 Scan. 1.1 Contraction CSE341T/CSE549T 09/17/2014. Lecture 8
CSE341T/CSE549T 09/17/2014 Lecture 8 Scan and its Uses 1 Scan Today, we start by learning a very useful primitive. First, lets start by thinking about what other primitives we have learned so far? The
More informationOn the Range Maximum-Sum Segment Query Problem
On the Range Maximum-Sum Segment Query Problem Kuan-Yu Chen 1 and Kun-Mao Chao 1,2,3, 1 Department of Computer Science and Information Engineering 2 Graduate Institute of Biomedical Electronics and Bioinformatics
More informationHypercubes. (Chapter Nine)
Hypercubes (Chapter Nine) Mesh Shortcomings: Due to its simplicity and regular structure, the mesh is attractive, both theoretically and practically. A problem with the mesh is that movement of data is
More informationDynamic Programming. CS 374: Algorithms & Models of Computation, Fall Lecture 11. October 1, 2015
CS 374: Algorithms & Models of Computation, Fall 2015 Dynamic Programming Lecture 11 October 1, 2015 Chandra & Manoj (UIUC) CS374 1 Fall 2015 1 / 32 Dynamic Programming Dynamic Programming is smart recursion
More informationLecture 9 March 4, 2010
6.851: Advanced Data Structures Spring 010 Dr. André Schulz Lecture 9 March 4, 010 1 Overview Last lecture we defined the Least Common Ancestor (LCA) and Range Min Query (RMQ) problems. Recall that an
More information1 Dynamic Programming
Recitation 13 Dynamic Programming Parallel and Sequential Data Structures and Algorithms, 15-210 (Fall 2013) November 20, 2013 1 Dynamic Programming Dynamic programming is a technique to avoid needless
More informationLectures 12 and 13 Dynamic programming: weighted interval scheduling
Lectures 12 and 13 Dynamic programming: weighted interval scheduling COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski Lectures 12-13: Dynamic Programming 1 Overview Last week: Graph
More informationCS 231: Algorithmic Problem Solving
CS 231: Algorithmic Problem Solving Naomi Nishimura Module 5 Date of this version: June 14, 2018 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides
More informationOn Modularity Clustering. Group III (Ying Xuan, Swati Gambhir & Ravi Tiwari)
On Modularity Clustering Presented by: Presented by: Group III (Ying Xuan, Swati Gambhir & Ravi Tiwari) Modularity A quality index for clustering a graph G=(V,E) G=(VE) q( C): EC ( ) EC ( ) + ECC (, ')
More informationChapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.
Chapter 8 out of 7 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal 8 Matrices Definitions and Basic Operations Matrix algebra is also known
More informationElements of Dynamic Programming. COSC 3101A - Design and Analysis of Algorithms 8. Discovering Optimal Substructure. Optimal Substructure - Examples
Elements of Dynamic Programming COSC 3A - Design and Analysis of Algorithms 8 Elements of DP Memoization Longest Common Subsequence Greedy Algorithms Many of these slides are taken from Monica Nicolescu,
More informationGraph Algorithms Using Depth First Search
Graph Algorithms Using Depth First Search Analysis of Algorithms Week 8, Lecture 1 Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Graph Algorithms Using Depth
More informationMemoization/Dynamic Programming. The String reconstruction problem. CS124 Lecture 11 Spring 2018
CS124 Lecture 11 Spring 2018 Memoization/Dynamic Programming Today s lecture discusses memoization, which is a method for speeding up algorithms based on recursion, by using additional memory to remember
More informationAlgorithms IV. Dynamic Programming. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms IV Dynamic Programming Guoqiang Li School of Software, Shanghai Jiao Tong University Dynamic Programming Shortest Paths in Dags, Revisited Shortest Paths in Dags, Revisited The special distinguishing
More informationRecitation 12. Dynamic Programming Announcements. SegmentLab has been released and is due Apr 14.
Recitation 12 Dynamic Programming 12.1 Announcements SegmentLab has been released and is due Apr 14. 73 74 RECITATION 12. DYNAMIC PROGRAMMING 12.2 Matrix Chain Product Definition 12.1. In the matrix chain
More informationPresentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Dynamic Programming
Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 25 Dynamic Programming Terrible Fibonacci Computation Fibonacci sequence: f = f(n) 2
More informationChapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part
More informationGreedy Algorithms. CLRS Chapters Introduction to greedy algorithms. Design of data-compression (Huffman) codes
Greedy Algorithms CLRS Chapters 16.1 16.3 Introduction to greedy algorithms Activity-selection problem Design of data-compression (Huffman) codes (Minimum spanning tree problem) (Shortest-path problem)
More informationEvolutionary tree reconstruction (Chapter 10)
Evolutionary tree reconstruction (Chapter 10) Early Evolutionary Studies Anatomical features were the dominant criteria used to derive evolutionary relationships between species since Darwin till early
More informationAlgorithm Design Techniques part I
Algorithm Design Techniques part I Divide-and-Conquer. Dynamic Programming DSA - lecture 8 - T.U.Cluj-Napoca - M. Joldos 1 Some Algorithm Design Techniques Top-Down Algorithms: Divide-and-Conquer Bottom-Up
More information17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer
Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are
More informationDynamic Programming Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Dynamic Programming What is Dynamic Programming? Technique for avoiding redundant work in recursive algorithms Works best with optimization problems that have a nice underlying structure Can often be used
More informationOptimization II: Dynamic Programming
Chapter 12 Optimization II: Dynamic Programming In the last chapter, we saw that greedy algorithms are efficient solutions to certain optimization problems. However, there are optimization problems for
More information2.3 Optimal paths. E. Amaldi Foundations of Operations Research Politecnico di Milano 1
. Optimal paths E. Amaldi Foundations of Operations Research Politecnico di Milano Optimal (minimum or maximum) paths have a wide range of applications: Google maps, GPS navigators planning and management
More informationData Structure and Algorithm II Homework #2 Due: 13pm, Monday, October 31, === Homework submission instructions ===
Data Structure and Algorithm II Homework #2 Due: 13pm, Monday, October 31, 2011 === Homework submission instructions === Submit the answers for writing problems (including your programming report) through
More informationLecturers: Sanjam Garg and Prasad Raghavendra March 20, Midterm 2 Solutions
U.C. Berkeley CS70 : Algorithms Midterm 2 Solutions Lecturers: Sanjam Garg and Prasad aghavra March 20, 207 Midterm 2 Solutions. (0 points) True/False Clearly put your answers in the answer box in front
More informationDiscrete Optimization 2010 Lecture 5 Min-Cost Flows & Total Unimodularity
Discrete Optimization 2010 Lecture 5 Min-Cost Flows & Total Unimodularity Marc Uetz University of Twente m.uetz@utwente.nl Lecture 5: sheet 1 / 26 Marc Uetz Discrete Optimization Outline 1 Min-Cost Flows
More informationWe augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real
14.3 Interval trees We augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real numbers ], with Interval ]represents the set Open and half-open intervals
More informationTheory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck
Theory of Computing Lecture 4/5 MAS 714 Hartmut Klauck How fast can we sort? There are deterministic algorithms that sort in worst case time O(n log n) Do better algorithms exist? Example [Andersson et
More information15-750: Parallel Algorithms
5-750: Parallel Algorithms Scribe: Ilari Shafer March {8,2} 20 Introduction A Few Machine Models of Parallel Computation SIMD Single instruction, multiple data: one instruction operates on multiple data
More informationWrite an algorithm to find the maximum value that can be obtained by an appropriate placement of parentheses in the expression
Chapter 5 Dynamic Programming Exercise 5.1 Write an algorithm to find the maximum value that can be obtained by an appropriate placement of parentheses in the expression x 1 /x /x 3 /... x n 1 /x n, where
More informationUnit-5 Dynamic Programming 2016
5 Dynamic programming Overview, Applications - shortest path in graph, matrix multiplication, travelling salesman problem, Fibonacci Series. 20% 12 Origin: Richard Bellman, 1957 Programming referred to
More informationCS141: Intermediate Data Structures and Algorithms Dynamic Programming
CS141: Intermediate Data Structures and Algorithms Dynamic Programming Amr Magdy Programming? In this context, programming is a tabular method Other examples: Linear programing Integer programming 2 Rod
More informationDynamic Programming Algorithms
CSC 364S Notes University of Toronto, Fall 2003 Dynamic Programming Algorithms The setting is as follows. We wish to find a solution to a given problem which optimizes some quantity Q of interest; for
More informatione-pg PATHSHALA- Computer Science Design and Analysis of Algorithms Module 14 Component-I (A) - Personal Details
e-pg PATHSHALA- Computer Science Design and Analysis of Algorithms Module 14 Component-I (A) - Personal Details Role Name Designation Principal Investigator Dr.T.V.Geetha Senior Professor, Department of
More informationCS473-Algorithms I. Lecture 11. Greedy Algorithms. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 11 Greedy Algorithms 1 Activity Selection Problem Input: a set S {1, 2,, n} of n activities s i =Start time of activity i, f i = Finish time of activity i Activity i takes place
More informationCSci 231 Final Review
CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.
More informationEncoding Data Structures
Encoding Data Structures Rajeev Raman University of Leicester ERATO-ALSIP special seminar RMQ problem Given a static array A[1..n], pre-process A to answer queries: RMQ(l, r) : return max l i r A[i]. 47
More informationCS6100: Topics in Design and Analysis of Algorithms
CS6100: Topics in Design and Analysis of Algorithms Guarding and Triangulating Polygons John Augustine CS6100 (Even 2012): Guarding and Triangulating Polygons The Art Gallery Problem A simple polygon is
More informationCSE 101 Homework 5. Winter 2015
CSE 0 Homework 5 Winter 205 This homework is due Friday March 6th at the start of class. Remember to justify your work even if the problem does not explicitly say so. Writing your solutions in L A TEXis
More informationCS 170 DISCUSSION 8 DYNAMIC PROGRAMMING. Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17
CS 170 DISCUSSION 8 DYNAMIC PROGRAMMING Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17 DYNAMIC PROGRAMMING Recursive problems uses the subproblem(s) solve the current one. Dynamic
More informationData structures for totally monotone matrices
Data structures for totally monotone matrices Submatrix maximum queries in (inverse) Monge matrices Input: n x n (inverse) Monge matrix M represented implicitly (constant time oracle access) Output: data
More informationAlgorithms (IX) Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms (IX) Guoqiang Li School of Software, Shanghai Jiao Tong University Q: What we have learned in Algorithm? Algorithm Design Algorithm Design Basic methodologies: Algorithm Design Algorithm Design
More informationComputer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer
Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Divide and Conquer Divide and-conquer is a very common and very powerful algorithm design technique. The general idea:
More information2.3 Algorithms Using Map-Reduce
28 CHAPTER 2. MAP-REDUCE AND THE NEW SOFTWARE STACK one becomes available. The Master must also inform each Reduce task that the location of its input from that Map task has changed. Dealing with a failure
More informationDynamic Programming Homework Problems
CS 1510 Dynamic Programming Homework Problems 1. Consider the recurrence relation T(0) = T(1) = 2 and for n > 1 n 1 T(n) = T(i)T(i 1) i=1 We consider the problem of computing T(n) from n. (a) Show that
More informationCSE 101- Winter 18 Discussion Section Week 6
CSE 101- Winter 18 Discussion Section Week 6 Administrative Introducing 1:1 Sessions: https://docs.google.com/spreadsheets/d/1kgxt_rzbzlibbdijiczs_ o1wxdwa9hhvxccprn8_bwk/edit?usp=sharing Please see the
More informationPhylogenetic Trees Lecture 12. Section 7.4, in Durbin et al., 6.5 in Setubal et al. Shlomo Moran, Ilan Gronau
Phylogenetic Trees Lecture 12 Section 7.4, in Durbin et al., 6.5 in Setubal et al. Shlomo Moran, Ilan Gronau. Maximum Parsimony. Last week we presented Fitch algorithm for (unweighted) Maximum Parsimony:
More informationDist(Vertex u, Vertex v, Graph preprocessed) return u.dist v.dist
Design and Analysis of Algorithms 5th September, 2016 Practice Sheet 3 Solutions Sushant Agarwal Solutions 1. Given an edge-weighted undirected connected chain-graph G = (V, E), all vertices having degree
More informationRange Minimum Queries Part Two
Range Minimum Queries Part Two Recap from Last Time The RMQ Problem The Range Minimum Query (RMQ) problem is the following: Given a fixed array A and two indices i j, what is the smallest element out of
More informationOn the Relationships between Zero Forcing Numbers and Certain Graph Coverings
On the Relationships between Zero Forcing Numbers and Certain Graph Coverings Fatemeh Alinaghipour Taklimi, Shaun Fallat 1,, Karen Meagher 2 Department of Mathematics and Statistics, University of Regina,
More informationLecture 3. Brute Force
Lecture 3 Brute Force 1 Lecture Contents 1. Selection Sort and Bubble Sort 2. Sequential Search and Brute-Force String Matching 3. Closest-Pair and Convex-Hull Problems by Brute Force 4. Exhaustive Search
More informationComputer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Dynamic Programming
Computer Science 385 Design and Analysis of Algorithms Siena College Spring 29 Topic Notes: Dynamic Programming We next consider dynamic programming, a technique for designing algorithms to solve problems
More informationSubsequence Definition. CS 461, Lecture 8. Today s Outline. Example. Assume given sequence X = x 1, x 2,..., x m. Jared Saia University of New Mexico
Subsequence Definition CS 461, Lecture 8 Jared Saia University of New Mexico Assume given sequence X = x 1, x 2,..., x m Let Z = z 1, z 2,..., z l Then Z is a subsequence of X if there exists a strictly
More information1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors
1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors on an EREW PRAM: See solution for the next problem. Omit the step where each processor sequentially computes the AND of
More informationDynamic Programming. December 15, CMPE 250 Dynamic Programming December 15, / 60
Dynamic Programming December 15, 2016 CMPE 250 Dynamic Programming December 15, 2016 1 / 60 Why Dynamic Programming Often recursive algorithms solve fairly difficult problems efficiently BUT in other cases
More information