Algorithms for Data Science

Size: px
Start display at page:

Download "Algorithms for Data Science"

Transcription

1 Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015

2 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra s algorithm) Correctness Implementations 3 Segmented least squares An exponential recursive algorithm 4 A Dynamic Programming (DP) solution A quadratic iterative algorithm 5 Obtaining efficient algorithms by applying the DP principle

3 Today 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra s algorithm) Correctness Implementations 3 Segmented least squares An exponential recursive algorithm 4 A Dynamic Programming (DP) solution A quadratic iterative algorithm 5 Obtaining efficient algorithms by applying the DP principle

4 Review of the last lecture Data compression Lossless data compression Symbol codes Uniquely decodable symbol codes Prefix codes and binary trees An optimal prefix code for lossless compression: the Huffman algorithm The greedy principle for algorithm design Data structure: binary min-heap

5 Today 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra s algorithm) Correctness Implementations 3 Segmented least squares An exponential recursive algorithm 4 A Dynamic Programming (DP) solution A quadratic iterative algorithm 5 Obtaining efficient algorithms by applying the DP principle

6 Weighted graphs Edge weights represent distances (or time, cost, etc.) Consider a path P = (v 0,..., v k ). The length of P is the sum of the weights of its edges: k 1 w(p ) = w(v i, v i+1 ). i=0 In weighted graphs, a shortest path from u to v is a path of minimum length among all paths from u to v.

7 Notation s-t path: a path from s to t. dist(u, v): the length of the shortest u-v path; dist(u, v) = { min P w(p ), if exists u-v path, otherwise dist(v): the length of the shortest s-v path, when s is fixed. We may also refer to w(p ) as the weight or cost of P.

8 Single-source shortest-paths problem Input: a weighted, directed graph G = (V, E, w), where function w : E R maps edges to real-valued weights; a source (origin) vertex s V. Output: for every vertex v V 1. the length of a shortest s-v path; 2. a shortest s-v path.

9 Given an algorithm A for single-source shortest-paths We can also solve single-pair shortest-path problem single-destination shortest-paths problem: find a shortest path from every vertex to a destination t all-pairs shortest-paths: find a shortest path between every pair of vertices

10 ]

11 Graphs with non-negative weights Input a weighted, directed graph G = (V, E, w); function w : E R + assigns non-negative real-valued weights to edges; a source (origin) vertex s V. Output: for every vertex v V 1. the length of a shortest s-v path; 2. a shortest s-v path.

12 Dijkstra s algorithm (Input: G = (V, E, w), s V ) Output: arrays dist, prev with n entries such that 1. dist(v) stores the length of the shortest s-v path 2. prev(v) stores the node before v in the shortest s-v path At all times, maintain a set S of nodes for which the distance from s has been determined. Initially, dist(s) = 0, S = {s}. Each time, add to S the node v V S that 1. has an edge from some node in S; 2. minimizes the following quantity among all nodes v V S Set prev(v) = u. d(v) = min {dist(u) + w(u, v)} u S:(u,v) E

13 An example weighted directed graph 1 a 1 8 c e s 5 b d 3 f 1

14 Dijkstra s output for example graph (1) (2) a c (5) e s b d f (4) (3) (4) The distances (in parentheses) and reverse shortest paths.

15 Another way of showing optimality of greedy algorithms Greedy principle: a local decision rule is applied at every step. Dijkstra s algorithm is greedy: always form the shortest new s-v path by first following a path to some node u in S, and then a single edge (u, v). Proof of optimality: it always stays ahead of any other solution; when a path to a node v is selected, that path is shorter than every other possible s-v path.

16 Correctness of Dijkstra s algorithm At all times, the algorithm maintains a set S of nodes for which it has determined a shortest-path distance from s. Claim 1. Consider the set S at any point in the algorithm s execution. For each u in S, the path P u is a shortest s-u path. Optimality of the algorithm follows from the claim (why?).

17 Proof of Claim 1 By induction on the size of S. Base case: S = 1, dist(s) = 0. Hypothesis: suppose the claim is true for S = k, that is, for every u S, P u is a shortest s-u path. Step: let v be the k + 1-st node added to S. We want to show that P v, which is P u for some u S, followed by the edge (u, v), is a shortest s-v path. Consider any other s-v path, call it P. P must leave S somewhere since v S: let y v be the first node of P in V S and x S the node before y in P. Since the algorithm added v in this iteration and not y, it must be that d(v) d(y). So just the subpath s x y in P is longer than P v! Hence P is longer as well (why?).

18 Implementation Dijkstra-v1(G = (V, E, w), s V ) Initialize(G, s) S = {s} while S V do Select a node v V S with at least one edge from S so that d(v) = {dist[u] + w(u, v)} S = S {v} dist[v] = d(v) prev[v] = u end while Initialize(G, s) for v V do dist[v] = prev[v] = NIL end for dist[s] = 0 min u S,(u,v) E

19 Improved implementation (I) Idea: Keep a conservative overestimate of the true length of the shortest s-v path in dist[v] as follows: when u is added to S, update dist[v] for all v with (u, v) E. Dijkstra-v2(G = (V, E, w), s V ) Initialize(G, s) S = while S V do Pick u so that dist[u] is minimum among all nodes in V S S = S {u} for (u, v) E do Update(u, v) end for end while Update(u, v) if dist[v] > dist[u] + w(u, v) then dist[v] = dist[u] + w(u, v) prev[v] = u end if

20 Improved implementation (II): binary min-heap Idea: Use a priority queue implemented as a binary min-heap: store vertex u with key dist[u]. Required operations: Insert, ExtractMin; DecreaseKey for Update; each takes O(log n) time. Dijkstra-v3(G = (V, E, w), s V ) Initialize(G, s) Q = {V ; dist} S = while Q do u = ExtractMin(Q) S = S {u} for (u, v) E do Update(u, v) end for end while Running time: O(n log n + m log n) = O(m log n) When is Dijkstra-v3() better than Dijkstra-v2()?

21 Today 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra s algorithm) Correctness Implementations 3 Segmented least squares An exponential recursive algorithm 4 A Dynamic Programming (DP) solution A quadratic iterative algorithm 5 Obtaining efficient algorithms by applying the DP principle

22 Linear least squares fitting A foundational problem in statistics: find a line of best fit through some data points.

23 Linear least squares fitting Input: a set P of n data points (x 1, y 1 ), (x 2, y 2 ),..., (x n, y n ); we assume x 1 < x 2 <... < x n. Output: the line L defined as y = ax + b that minimizes the error Error(L, P ) = n (y i ax i b) 2 (1) i=1

24 Linear least squares fitting: solution Given a set P of data points, we can use calculus to show that the line L given by y = ax + b that minimizes Error(L, P ) = n (y i ax i b) 2 (2) i=1 satisfies a = n i x iy i ( i x i)( i y i) n i x2 i ( i x i) 2 (3) i b = y i a i x i (4) n How fast can we compute a, b?

25 What if the data changes direction?

26 What if the data changes direction more than once?

27 How to detect change in the data Any single line would have large error. Idea 1: hardcode number of lines to 2 (or some fixed m). Fails for the dataset on the previous slide. Idea 2: pass an arbitrary set of lines through the points and seek the set of lines that minimizes the error. Trivial solution: have a different line pass through each pair of consecutive points in P. Idea 3: fit the points well, using as few lines as possible. Trade-off between complexity and error of the model

28 Formalizing the problem Input: data set P = {p 1,..., p n } of points on the plane. A segment S = {p i, p i+1,..., p j } is a contiguous subset of the input. Let Σ be a partition of P into m Σ segments S 1, S 2,..., S mσ. For every segment S k, use (2), (3), (4) to compute a line L k that minimizes Error(L k, S k ). Let C > 0 a fixed multiplier. The penalty of the partition is Error(L k, S k ) + m Σ C S k Σ

29 Segmented least squares This problem is an instance of change detection in data mining and statistics. Input: A set P of n data points p i = (x i, y i ) as before. Output: A segmentation Σ = {S 1, S 2,..., S mσ } of P whose penalty Error(L k, S k ) + m Σ C S k Σ is minimum.

30 A brute force approach We can find the optimal segmentation (that is, the one incurring the minimum penalty) by exhaustive search. Enumerate every possible segmentation and compute its penalty. Output the one that incurs the minimum penalty. O(2 n ) partitions

31 A crucial observation regarding the last data point Consider the last point p n in the data set. p n belongs to a single segment in the optimal partition. That segment starts at an earlier point p i, for some 1 i n. This suggests a recursive solution: if we knew where the last segment starts, then we could remove it and recursively solve the problem on the remaining points {p 1,..., p i 1 }.

32 A recursive approach Let OP T (n) denote the penalty of the optimal segmentation for points p 1,..., p n. Then, if the last segment of the optimal segmentation is {p i,..., p n }, the penalty of the optimal solution is OP T (n) = Error(L, {p i,..., p n }) + C + OP T (i 1). But we don t know where the last segment starts! How do we find the point p i? We set { } OP T (n) = min Error(L, {p i,..., p n })+C+OP T (i 1). 1 i n

33 A recurrence for the optimal solution Notation: let e i,j = Error(L, {p i,..., p j }), for 1 i j n. Then { } OP T (n) = min e i,n + C + OP T (i 1). 1 i n If we apply the above expression recursively to remove the last segment, we obtain the recurrence { } OP T (j) = min e i,j + C + OP T (i 1) (5) 1 i j Remark We can precompute and store all e i,j using equations (2), (3), (4) in O(n 3 ) time. Can be improved to O(n 2 ). 2. The natural recursive algorithm arising from recurrence (5) is not efficient (think about its recursion tree!).

34 Exponential-time recursion Notation: T (n) = time to compute optimal segmentation of n points. Then T (n) T (n 1) + T (n 2). Can show that T (n) F n, the n-th Fibonacci number (by strong induction on n). From Problem 5a in Homework 1, F n = Ω(2 n/2 ). Hence T (n) = Ω(2 n/2 ). The recursive algorithm requires Ω(2 n/2 ) time.

35 Today 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra s algorithm) Correctness Implementations 3 Segmented least squares An exponential recursive algorithm 4 A Dynamic Programming (DP) solution A quadratic iterative algorithm 5 Obtaining efficient algorithms by applying the DP principle

36 Are we really that far from an efficient solution? Recall Fibonacci problem from HW1: exponential recursive algorithm, polynomial iterative solution How? 1. Overlapping subproblems: spectacular redundancy in computations of recursion tree 2. Easy-to-compute recurrence for combining the smaller subproblems: F n = F n 1 + F n 2 3. Iterative, bottom-up computations: we computed the subproblems from smallest (F 0, F 1 ) to largest (F n ), iteratively. 4. Small number of subproblems: only solved n 1 subproblems.

37 Elements of DP in segmented least squares 1. Overlapping subproblems 2. An easy-to-compute recurrence (5) for combining solutions to the smaller subproblems into a solution to a larger subproblem in O(n) time (once smaller subproblems have been solved). 3. Iterative, bottom-up computations: compute the subproblems from smallest (0 points) to largest (n points), iteratively. 4. Small number of subproblems: we only need to solve n subproblems.

38 A dynamic programming approach { } OP T (j) = min e i,j + C + OP T (i 1) 1 i j The optimal solution for the subproblem on p 1,..., p j contains optimal solutions to smaller subproblems. Recurrence 5 provides an ordering of the subproblems from smaller to larger, with the subproblem of size 0 being the smallest and the subproblem of size n the largest. Thus there are n + 1 subproblems in total. Solving the j-th subproblem requires Θ(j) = O(n) time. Hence the overall running time is O(n 2 ). Boundary conditions: OP T (0) = 0. Segment p k,..., p j appears in the optimal solution only if the minimum in the expression above is achieved for i = k.

39 An iterative algorithm for segmented least squares Let M be an array of n entries. M[i] stores the penalty of the optimal segmentation of the first i data points. SegmentedLS(n, P ) M[0] = 0 for all pairs i j do Compute e i,j for segment p i,..., p j using (2), (3), (4) end for for j = 1 to n do M[j] = min 1 i j {e i,j + C + M[i 1]} end for Return M[n] Running time: time required to fill in dynamic programming array M is O(n 3 ) + O(n 2 ). Can be brought down to O(n 2 ).

40 Reconstructing an optimal segmentation Suppose we want the optimal solution in addition to its value, that is, the actual segmentation that achieves the minimum penalty M[n]. We can trace back through the dynamic programming array M to compute the optimal segmentation. Initial call: OPTSegmentation(n) OPTSegmentation(j) if (j == 0) then return else Find 1 i j such that M[j] = e i,j + C + M[i 1] OPTSegmentation(i 1) Output segment {p i,..., p j } end if

41 Today 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra s algorithm) Correctness Implementations 3 Segmented least squares An exponential recursive algorithm 4 A Dynamic Programming (DP) solution A quadratic iterative algorithm 5 Obtaining efficient algorithms by applying the DP principle

42 Obtaining efficient algorithms using DP 1. Optimal substructure: the optimal solution to the problem contains optimal solutions for the subproblems. 2. A recurrence for the overall optimal solution in terms of the optimal solutions to appropriate subproblems. The recurrence should provide a natural ordering of the subproblems from smaller to larger and require polynomial work for combining solutions to the subproblems. 3. Iterative, bottom-up computation of subproblems, from smaller to larger. 4. Small number of subproblems (polynomial in n).

43 Dynamic programming vs Divide & Conquer They both combine solutions to subproblems to generate the overall solution. However, divide and conquer starts with a large problem and divides it into small pieces. While dynamic programming works from the bottom up, solving the smallest subproblems first and building optimal solutions to steadily larger problems.

Algorithms for Data Science

Algorithms for Data Science Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Shortest paths in weighted graphs (Bellman-Ford, Floyd-Warshall) Outline 1 Shortest paths in graphs with

More information

Analysis of Algorithms, I

Analysis of Algorithms, I Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, March 8, 2016 Outline 1 Recap Single-source shortest paths in graphs with real edge weights:

More information

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CSC 373 Lecture # 3 Instructor: Milad Eftekhar Huffman encoding: Assume a context is available (a document, a signal, etc.). These contexts are formed by some symbols (words in a document, discrete samples from a signal, etc). Each symbols s i is occurred

More information

(Refer Slide Time: 00:18)

(Refer Slide Time: 00:18) Programming, Data Structures and Algorithms Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 11 Lecture 58 Problem: single source shortest

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 6 Greedy Graph Algorithms Shortest paths Adam Smith 9/8/14 The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle Does

More information

Dijkstra s Shortest Path Algorithm

Dijkstra s Shortest Path Algorithm Dijkstra s Shortest Path Algorithm DPV 4.4, CLRS 24.3 Revised, October 23, 2014 Outline of this Lecture Recalling the BFS solution of the shortest path problem for unweighted (di)graphs. The shortest path

More information

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 600.363 Introduction to Algorithms / 600.463 Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 14.1 Introduction Today we re going to talk about algorithms for computing shortest

More information

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2 Breadth-First Search, Slides for CIS DPV Chapter Jim Royer EECS October, 00 Definition In an undirected graph, the distance between two vertices is the length of the shortest path between them. (If there

More information

1 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.)

1 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 information

Shortest Path Problem

Shortest Path Problem Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths

More information

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast

More information

Description of The Algorithm

Description of The Algorithm Description of The Algorithm Dijkstra s algorithm works by solving the sub-problem k, which computes the shortest path from the source to vertices among the k closest vertices to the source. For the dijkstra

More information

Shortest path problems

Shortest path problems Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths

More information

1 Dijkstra s Algorithm

1 Dijkstra s Algorithm Lecture 11 Dijkstra s Algorithm Scribes: Himanshu Bhandoh (2015), Virginia Williams, and Date: November 1, 2017 Anthony Kim (2016), G. Valiant (2017), M. Wootters (2017) (Adapted from Virginia Williams

More information

Lecture 11: Analysis of Algorithms (CS ) 1

Lecture 11: Analysis of Algorithms (CS ) 1 Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest

More information

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck Theory of Computing Lecture 7 MAS 714 Hartmut Klauck Shortest paths in weighted graphs We are given a graph G (adjacency list with weights W(u,v)) No edge means W(u,v)=1 We look for shortest paths from

More information

CS 4349 Lecture October 23rd, 2017

CS 4349 Lecture October 23rd, 2017 CS 4349 Lecture October 23rd, 2017 Main topics for #lecture include #minimum_spanning_trees and #SSSP. Prelude Homework 7 due Wednesday, October 25th. Don t forget about the extra credit. Minimum Spanning

More information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019 CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction

More information

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G. 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G. A shortest s-t path is a path from vertex to vertex, whose sum of edge weights is minimized. (b) Give the pseudocode

More information

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University Algorithms (V) Path in Graphs Guoqiang Li School of Software, Shanghai Jiao Tong University Review of the Previous Lecture Exploring Graphs EXPLORE(G, v) input : G = (V, E) is a graph; v V output: visited(u)

More information

Chapter 6. Dynamic Programming

Chapter 6. Dynamic Programming Chapter 6 Dynamic Programming We began our study of algorithmic techniques with greedy algorithms, which in some sense form the most natural approach to algorithm design. Faced with a new computational

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle

More information

CSE 417 Dynamic Programming (pt 4) Sub-problems on Trees

CSE 417 Dynamic Programming (pt 4) Sub-problems on Trees CSE 417 Dynamic Programming (pt 4) Sub-problems on Trees Reminders > HW4 is due today > HW5 will be posted shortly Dynamic Programming Review > Apply the steps... 1. Describe solution in terms of solution

More information

Algorithms Dr. Haim Levkowitz

Algorithms Dr. Haim Levkowitz 91.503 Algorithms Dr. Haim Levkowitz Fall 2007 Lecture 4 Tuesday, 25 Sep 2007 Design Patterns for Optimization Problems Greedy Algorithms 1 Greedy Algorithms 2 What is Greedy Algorithm? Similar to dynamic

More information

Greedy Algorithms CHAPTER 16

Greedy Algorithms CHAPTER 16 CHAPTER 16 Greedy Algorithms In dynamic programming, the optimal solution is described in a recursive manner, and then is computed ``bottom up''. Dynamic programming is a powerful technique, but it often

More information

CS173 Longest Increasing Substrings. Tandy Warnow

CS173 Longest Increasing Substrings. Tandy Warnow CS173 Longest Increasing Substrings Tandy Warnow CS 173 Longest Increasing Substrings Tandy Warnow Today s material The Longest Increasing Subsequence problem DP algorithm for finding a longest increasing

More information

1 The Shortest Path Problem

1 The Shortest Path Problem CS161 Lecture 11 Single Source Shortest Paths Scribed by: Romil Verma (2015), Virginia Date: May 8, 2016 1 The Shortest Path Problem In this lecture, we ll discuss the shortest path problem. Assume we

More information

Unit-5 Dynamic Programming 2016

Unit-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 information

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve

More information

memoization or iteration over subproblems the direct iterative algorithm a basic outline of dynamic programming

memoization or iteration over subproblems the direct iterative algorithm a basic outline of dynamic programming Dynamic Programming 1 Introduction to Dynamic Programming weighted interval scheduling the design of a recursive solution memoizing the recursion 2 Principles of Dynamic Programming memoization or iteration

More information

CMSC 451: Dynamic Programming

CMSC 451: Dynamic Programming CMSC 41: Dynamic Programming Slides By: Carl Kingsford Department of Computer Science University of Maryland, College Park Based on Sections 6.1&6.2 of Algorithm Design by Kleinberg & Tardos. Dynamic Programming

More information

6.1 Minimum Spanning Trees

6.1 Minimum Spanning Trees CS124 Lecture 6 Fall 2018 6.1 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

More information

Chapter 6. Dynamic Programming

Chapter 6. Dynamic Programming Chapter 6 Dynamic Programming CS 573: Algorithms, Fall 203 September 2, 203 6. Maximum Weighted Independent Set in Trees 6..0. Maximum Weight Independent Set Problem Input Graph G = (V, E) and weights

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 07 Single-Source Shortest Paths (Chapter 24) Stephen Scott and Vinodchandran N. Variyam sscott@cse.unl.edu 1/36 Introduction

More information

Single Source Shortest Path

Single Source Shortest Path Single Source Shortest Path A directed graph G = (V, E) and a pair of nodes s, d is given. The edges have a real-valued weight W i. This time we are looking for the weight and the shortest path from s

More information

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees CSE1 Introduction to Algorithms Lecture 1 Minimum Spanning Trees Antoine Vigneron antoine@unist.ac.kr Ulsan National Institute of Science and Technology July 11, 201 Antoine Vigneron (UNIST) CSE1 Lecture

More information

12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares

12 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 information

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg CSE 1 Greedy Alg: Union Find/Dijkstra s Alg Shayan Oveis Gharan 1 Dijkstra s Algorithm Dijkstra(G, c, s) { d s 0 foreach (v V) d[v] //This is the key of node v foreach (v V) insert v onto a priority queue

More information

Scribe: Virginia Williams, Sam Kim (2016), Mary Wootters (2017) Date: May 22, 2017

Scribe: Virginia Williams, Sam Kim (2016), Mary Wootters (2017) Date: May 22, 2017 CS6 Lecture 4 Greedy Algorithms Scribe: Virginia Williams, Sam Kim (26), Mary Wootters (27) Date: May 22, 27 Greedy Algorithms Suppose we want to solve a problem, and we re able to come up with some recursive

More information

Design and Analysis of Algorithms 演算法設計與分析. Lecture 7 April 6, 2016 洪國寶

Design 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 information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS 4 Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming and data-structures CS/ENGRD 20 SUMMER 208 Lecture 3: Shortest Path http://courses.cs.cornell.edu/cs20/208su Graph Algorithms Search Depth-first search Breadth-first search

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 018 D/Q Greed SP s DP LP, Flow B&B, Backtrack Metaheuristics P, NP Design and Analysis of Algorithms Lecture 8: Greed Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Optimization

More information

Greedy Algorithms CLRS Laura Toma, csci2200, Bowdoin College

Greedy Algorithms CLRS Laura Toma, csci2200, Bowdoin College Greedy Algorithms CLRS 16.1-16.2 Laura Toma, csci2200, Bowdoin College Overview. Sometimes we can solve optimization problems with a technique called greedy. A greedy algorithm picks the option that looks

More information

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016 CS125 Lecture 2 Fall 2016 2.1 Greedy Algorithms We will start talking about methods high-level plans for constructing algorithms. One of the simplest is just to have your algorithm be greedy. Being greedy,

More information

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20. Title Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis Nesrine Damak Fakultät für Informatik TU München 20. September 2010 Nesrine Damak: Classical Shortest-Path Algorithms 1/ 35

More information

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4. Weighted Graphs 1 Outline (single-source) shortest path Dijkstra (Section 4.4) Bellman-Ford (Section 4.6) (all-pairs) shortest path Floyd-Warshall (Section 6.6) minimum spanning tree Kruskal (Section 5.1.3)

More information

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Dynamic Programming I Date: 10/6/16

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Dynamic Programming I Date: 10/6/16 600.463 Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Dynamic Programming I Date: 10/6/16 11.1 Introduction Dynamic programming can be very confusing until you ve used it a

More information

Module 27: Chained Matrix Multiplication and Bellman-Ford Shortest Path Algorithm

Module 27: Chained Matrix Multiplication and Bellman-Ford Shortest Path Algorithm Module 27: Chained Matrix Multiplication and Bellman-Ford Shortest Path Algorithm This module 27 focuses on introducing dynamic programming design strategy and applying it to problems like chained matrix

More information

Chapter 3 Dynamic programming

Chapter 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 information

Algorithmic Paradigms

Algorithmic Paradigms Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into two or more sub -problems, solve each sub-problem

More information

Framework for Design of Dynamic Programming Algorithms

Framework 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 information

Algorithms 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 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 information

The Shortest Path Problem

The Shortest Path Problem The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring

More information

Lecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009

Lecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009 Solving Shortest Path Problem: Dijkstra s Algorithm October 23, 2009 Outline Lecture 18 Focus on Dijkstra s Algorithm Importance: Where it has been used? Algorithm s general description Algorithm steps

More information

Algorithms for Minimum Spanning Trees

Algorithms for Minimum Spanning Trees Algorithms & Models of Computation CS/ECE, Fall Algorithms for Minimum Spanning Trees Lecture Thursday, November, Part I Algorithms for Minimum Spanning Tree Sariel Har-Peled (UIUC) CS Fall / 6 Sariel

More information

Lecture I: Shortest Path Algorithms

Lecture I: Shortest Path Algorithms Lecture I: Shortest Path Algorithms Dr Kieran T. Herley Department of Computer Science University College Cork October 201 KH (21/10/1) Lecture I: Shortest Path Algorithms October 201 1 / 28 Background

More information

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review 1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,

More information

Minimum Spanning Trees

Minimum Spanning Trees CS124 Lecture 5 Spring 2011 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

More information

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 6: BFS and Dijkstra s BREADTH FIRST SEARCH (BFS) Given a graph G and a starting vertex s, BFS computes

More information

CMSC 451: Lecture 10 Dynamic Programming: Weighted Interval Scheduling Tuesday, Oct 3, 2017

CMSC 451: Lecture 10 Dynamic Programming: Weighted Interval Scheduling Tuesday, Oct 3, 2017 CMSC 45 CMSC 45: Lecture Dynamic Programming: Weighted Interval Scheduling Tuesday, Oct, Reading: Section. in KT. Dynamic Programming: In this lecture we begin our coverage of an important algorithm design

More information

Single Source Shortest Path (SSSP) Problem

Single Source Shortest Path (SSSP) Problem Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = (V, E); an edge weight function w : E R, and a start vertex s V. Find: for each vertex u V, δ(s,

More information

Solution for Homework set 3

Solution for Homework set 3 TTIC 300 and CMSC 37000 Algorithms Winter 07 Solution for Homework set 3 Question (0 points) We are given a directed graph G = (V, E), with two special vertices s and t, and non-negative integral capacities

More information

CS473-Algorithms I. Lecture 10. Dynamic Programming. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS473-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 information

Practice Problems for the Final

Practice Problems for the Final ECE-250 Algorithms and Data Structures (Winter 2012) Practice Problems for the Final Disclaimer: Please do keep in mind that this problem set does not reflect the exact topics or the fractions of each

More information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra s algorithm for shortest paths when no edges have negative weight. Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm

More information

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 8: Negative Edges DIJKSTRA S ALGORITHM WITH DIFFERENT PRIORITY QUEUES. Runtime of Array: O V 2 Runtime

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 12 Dynamic programming Longest common subsequence Optimal substructure Overlapping subproblems Prof. Charles E. Leiserson Dynamic programming Design technique,

More information

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, Notes 7 for CS 170

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, Notes 7 for CS 170 UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, 003 Notes 7 for CS 170 1 Dijkstra s Algorithm Suppose each edge (v, w) of our graph has a

More information

Dynamic Programming II

Dynamic 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 information

IN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech

IN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech IN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech License CC BY-NC-SA 2.0 http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Outline Previously on IN101 Python s anatomy Functions,

More information

CS4800: Algorithms & Data Jonathan Ullman

CS4800: Algorithms & Data Jonathan Ullman CS4800: Algorithms & Data Jonathan Ullman Lecture 13: Shortest Paths: Dijkstra s Algorithm, Heaps DFS(?) Feb 0, 018 Navigation s 9 15 14 5 6 3 18 30 11 5 0 16 4 6 6 3 19 t Weighted Graphs A graph with

More information

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs). Lecture 13 Graph Algorithms I 13.1 Overview This is the first of several lectures on graph algorithms. We will see how simple algorithms like depth-first-search can be used in clever ways (for a problem

More information

CS 231: Algorithmic Problem Solving

CS 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 information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no

More information

09 B: Graph Algorithms II

09 B: Graph Algorithms II Correctness and Complexity of 09 B: Graph Algorithms II CS1102S: Data Structures and Algorithms Martin Henz March 19, 2010 Generated on Thursday 18 th March, 2010, 00:20 CS1102S: Data Structures and Algorithms

More information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that

More information

Last week: Breadth-First Search

Last week: Breadth-First Search 1 Last week: Breadth-First Search Set L i = [] for i=1,,n L 0 = {w}, where w is the start node For i = 0,, n-1: For u in L i : For each v which is a neighbor of u: If v isn t yet visited: - mark v as visited,

More information

Lecture 13: Chain Matrix Multiplication

Lecture 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 information

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment Class: V - CE Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology Sub: Design and Analysis of Algorithms Analysis of Algorithm: Assignment

More information

Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University

Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University U Kang 1 In This Lecture Shortest path problem Main idea of Dijkstra s algorithm Cost analysis of Dijkstra s algorithm

More information

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5 Dijkstra s Algorithm and Priority Queue Implementations CSE 101: Design and Analysis of Algorithms Lecture 5 CSE 101: Design and analysis of algorithms Dijkstra s algorithm and priority queue implementations

More information

Elements of Dynamic Programming. COSC 3101A - Design and Analysis of Algorithms 8. Discovering Optimal Substructure. Optimal Substructure - Examples

Elements 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 information

Lecture 4: Dynamic programming I

Lecture 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 information

1 Non greedy algorithms (which we should have covered

1 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 information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths. Nishant Mehta Lectures 10 and 11 Shortest Paths Nishant Mehta Lectures 0 and Communication Speeds in a Computer Network Find fastest way to route a data packet between two computers 6 Kbps 4 0 Mbps 6 6 Kbps 6 Kbps Gbps 00 Mbps 8 6 Kbps

More information

Outline. Computer Science 331. Definitions: Paths and Their Costs. Computation of Minimum Cost Paths

Outline. Computer Science 331. Definitions: Paths and Their Costs. Computation of Minimum Cost Paths Outline Computer Science 33 Computation of Minimum-Cost Paths Dijkstra s Mike Jacobson Department of Computer Science University of Calgary Lecture #34 Dijkstra s to Find Min-Cost Paths 3 Example 4 5 References

More information

Introduction to Optimization

Introduction to Optimization Introduction to Optimization Dynamic Programming November, 0 École Centrale Paris, Châtenay-Malabry, France Dimo Brockhoff INRIA Lille Nord Europe Course Overview Dimo Brockhoff, INRIA Introduction to

More information

Analysis of Algorithms Prof. Karen Daniels

Analysis of Algorithms Prof. Karen Daniels UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 2 Tuesday, 2/2/10 Design Patterns for Optimization Problems Greedy Algorithms Algorithmic Paradigm Context

More information

Lectures 12 and 13 Dynamic programming: weighted interval scheduling

Lectures 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 information

1 Dynamic Programming

1 Dynamic Programming CS161 Lecture 13 Dynamic Programming and Greedy Algorithms Scribe by: Eric Huang Date: May 13, 2015 1 Dynamic Programming The idea of dynamic programming is to have a table of solutions of subproblems

More information

Algorithms (I) Introduction. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Algorithms (I) Introduction. Guoqiang Li. School of Software, Shanghai Jiao Tong University Algorithms (I) Introduction Guoqiang Li School of Software, Shanghai Jiao Tong University Instructor and Teaching Assistants Guoqiang LI Instructor and Teaching Assistants Guoqiang LI Homepage: http://basics.sjtu.edu.cn/

More information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths. Nishant Mehta Lectures 10 and 11 Shortest Paths Nishant Mehta Lectures 0 and Finding the Fastest Way to Travel between Two Intersections in Vancouver Granville St and W Hastings St Homer St and W Hastings St 6 Granville St and W Pender

More information

Week 11: Minimum Spanning trees

Week 11: Minimum Spanning trees Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,

More information

Subsequence 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. 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 information

CS 561, Lecture 10. Jared Saia University of New Mexico

CS 561, Lecture 10. Jared Saia University of New Mexico CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging

More information

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:

More information

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns Pruet Boonma pruet@eng.cmu.ac.th Department of Computer Engineering Faculty of Engineering, Chiang Mai University Based on Slides by

More information

Tutorial 6-7. Dynamic Programming and Greedy

Tutorial 6-7. Dynamic Programming and Greedy Tutorial 6-7 Dynamic Programming and Greedy Dynamic Programming Why DP? Natural Recursion may be expensive. For example, the Fibonacci: F(n)=F(n-1)+F(n-2) Recursive implementation memoryless : time= 1

More information