CSE 202: Design and Analysis of Algorithms Lecture 5

Size: px
Start display at page:

Download "CSE 202: Design and Analysis of Algorithms Lecture 5"

Transcription

1 CSE 202: Design and Analysis of Algorithms Lecture 5 Instructor: Kamalika Chaudhuri

2 Announcements Kamalika s Office hours today moved to tomorrow, 12:15-1:15pm Homework 1 due now Midterm on Feb 14

3 Algorithm Design Paradigms Exhaustive Search Greedy Algorithms: Build a solution incrementally piece by piece Divide and Conquer: Divide into parts, solve each part, combine results Dynamic Programming: Divide into subtasks, perform subtask by size. Combine smaller subtasks to larger ones Hill-climbing: Start with a solution, improve it

4 Divide and Conquer Integer Multiplication Closest pair of points on a Plane Strassen s algorithm for matrix multiplication

5 Integer Multiplication: The Grade School Way How to multiply two n-bit numbers? 1.Create array of n intermediate sums 2. Add up the sums Time per addition = O(n) Total time = O(n 2 ). [22] [5] [110] Can we do better?

6 A Simple Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R

7 A Simple Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R

8 A Simple Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Operations: 1. 4 multiplications of n/2 bit #s 2. Shifting by n bits 3. 3 additions

9 A Simple Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Operations: 1. 4 multiplications of n/2 bit #s 2. Shifting by n bits 3. 3 additions Recurrence: T(n) = 4T(n/2) + O(n)

10 A Simple Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R What is the base case? Operations: 1. 4 multiplications of n/2 bit #s 2. Shifting by n bits 3. 3 additions Recurrence: T(n) = 4T(n/2) + O(n) T(n) = O(n 2 )

11 A Better Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Need: xlyl, xryr, (xryl + xlyr) Computed by 3 multiplications as: (xryl + xlyr) = (xl + xr)(yl + yr) - xlyl - xryr

12 A Better Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Need: xlyl, xryr, (xryl + xlyr) Operations: 1. 3 multiplications of n/2 bit #s 2. Shifting by n bits 3. 6 additions Computed by 3 multiplications as: (xryl + xlyr) = (xl + xr)(yl + yr) - xlyl - xryr

13 A Better Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Need: xlyl, xryr, (xryl + xlyr) Operations: 1. 3 multiplications of n/2 bit #s 2. Shifting by n bits 3. 6 additions Computed by 3 multiplications as: (xryl + xlyr) = (xl + xr)(yl + yr) - xlyl - xryr Recurrence: T(n) = 3T(n/2) + O(n)

14 A Better Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Need: xlyl, xryr, (xryl + xlyr) Operations: 1. 3 multiplications of n/2 bit #s 2. Shifting by n bits 3. 6 additions Computed by 3 multiplications as: (xryl + xlyr) = (xl + xr)(yl + yr) - xlyl - xryr Recurrence: T(n) = 3T(n/2) + O(n) T(n) = O(n 1.59 )

15 A Better Divide and Conquer Problem: How to multiply two n-bit numbers x and y? x = y = x L x R y L y R x = x L 2 n/2 + x R y = y L 2 n/2 + y R xy = (x L 2 n/2 + x R )(y L 2 n/2 + y R ) = x L y L 2 n + (x R y L + x L y R ) 2 n/2 + x R y R Need: xlyl, xryr, (xryl + xlyr) Operations: 1. 3 multiplications of n/2 bit #s 2. Shifting by n bits 3. 6 additions Computed by 3 multiplications as: (xryl + xlyr) = (xl + xr)(yl + yr) - xlyl - xryr Best: O(n log n 2 O(log * n) ) [Furer07]) Recurrence: T(n) = 3T(n/2) + O(n) T(n) = O(n 1.59 )

16 Divide and Conquer Integer Multiplication Closest pair of points on a Plane Strassen s algorithm for matrix multiplication

17 Closest Pair of Points on a Plane Given a set P of n points on the plane, find the two points p and q in P s.t d(p, q) is minimum p q

18 Closest Pair of Points on a Plane Given a set P of n points on the plane, find the two points p and q in P s.t d(p, q) is minimum p q Naive solution = O(n 2 )

19 What about one dimension? Given a set P of n points on the line, find the two points p and q in P s.t d(p, q) is minimum p q

20 What about one dimension? Given a set P of n points on the line, find the two points p and q in P s.t d(p, q) is minimum p q Property: The closest points are adjacent in sorted order

21 What about one dimension? Given a set P of n points on the line, find the two points p and q in P s.t d(p, q) is minimum p q Property: The closest points are adjacent in sorted order Algorithm 1 1. Sort the points 2. Find a point pi in the sorted set s.t d(pi, pi+1) is minimum

22 What about one dimension? Given a set P of n points on the line, find the two points p and q in P s.t d(p, q) is minimum p q Property: The closest points are adjacent in sorted order Algorithm 1 1. Sort the points 2. Find a point pi in the sorted set s.t d(pi, pi+1) is minimum Running Time = O(n log n)

23 Does this work in 2D? b (a, b) : closest in x-coordinate p (a, q) : closest in y-coordinate q (p, q) : closest a Sorting the points by x or y coordinate, and looking at adjacent pairs does not work!

24 A Divide and Conquer Approach L R lx Find-Closest-Pair(Q): 1. Find the median x coordinate lx 2. L = Points to the left of lx 3. R = Rest of the points 4. Find-closest-pair(L) 5. Find-closest-pair(R) 6. Combine the results How to combine? Problem Case: p in L, q in R (or vice versa)

25 A Divide and Conquer Approach L R lx Find-Closest-Pair(Q): 1. Find the median x coordinate lx 2. L = Points to the left of lx 3. R = Rest of the points 4. Find-closest-pair(L) 5. Find-closest-pair(R) 6. Combine the results How to combine? 1. Naive combination Time = O(n 2 ) 2. Can we do better?

26 A Property of Closest Points Let: t1 = min x, y in L d(x, y) t2 = min x, y in R d(x, y) t = min (t1, t2) If d(a, b) < t, where a is in L, b in R, then, a and b lie within distance t of lx lx L R

27 A Property of Closest Points Let: t1 = min x, y in L d(x, y) t2 = min x, y in R d(x, y) t = min (t1, t2) If d(a, b) < t, where a is in L, b in R, then, a and b lie within distance t of lx lx L a >t R

28 A Property of Closest Points Let: t1 = min x, y in L d(x, y) t2 = min x, y in R d(x, y) t = min (t1, t2) If d(a, b) < t, where a is in L, b in R, then, a and b lie within distance t of lx lx b L a >t R >t

29 A Property of Closest Points Let: t1 = min x, y in L d(x, y) t2 = min x, y in R d(x, y) t = min (t1, t2) If d(a, b) < t, where a is in L, b in R, then, a and b lie within distance t of lx lx b L a >t R >t t t We can safely rule out all points in the grey regions!

30 Another Property Let: t1 = min x, y in L d(x, y) t2 = min x, y in R d(x, y) t = min (t1, t2) Sy = all points within distance t of lx in sorted order of y coords If d(a, b) < t, a in L, b in R, then a and b occur within 15 positions of each other in Sy L t1 t2 R t/2 a lx lx Boxes Fact: Each box in figure can contain at most one point. If d(a,b) < t, a in L, b in R, a, b are > 15 positions apart then, there are >= 3 rows between a and b Thus, d(a, b) >= 3t/2. Contradiction! t/2 t b

31 A Divide and Conquer Approach Property: If a in L, b in R, and if d(a, b) < t, then a and b occur within 15 positions of each other in Sy How to combine? L Find-Closest-Pair(Q): 1. Find the median x coordinate lx 2. L = Points to the left of lx 3. R = Rest of the points 4. (a1, b1, t1) = Find-closest-pair(L) 5. (a2, b2, t2) = Find-closest-pair(R) 6. t = min(t1, t2) 7. Combine the results lx R S = points in Q within distance t of Ix Sy = sort S by y coords For p in Sy Find distance from p to next 15 points Let (a, b) be the pair with min such distance If d(a, b) < t: Return (a, b, d(a, b)) Else if t1 < t2: Return (a1, b1, t1) Else: Return (a2, b2, t2)

32 A Divide and Conquer Approach Property: If a in L, b in R, and if d(a, b) < t, then a and b occur within 15 positions of each other in Sy Find-Closest-Pair(Qx, Qy): 1. Find the median x coordinate lx 2. L = Points to the left of lx 3. R = Rest of the points 4. (a1, b1, t1) = Find-closest-pair(Lx, Ly) 5. (a2, b2, t2) = Find-closest-pair(Rx, Ry) 6. t = min(t1, t2) 7. Combine the results Implementing Divide + Combine: 1. Maintain sorted lists of the input points: Px = sorted by x, Py = sorted by y 2. Computing Lx,Ly,Rx, Ry from Qx, Qy: O( Q ) time 2. Computing Sy from Qy : O( S ) time 3. Combination procedure: O( Sy ) time How to combine? S = points in Q within distance t of Ix Sy = sort S by y coords For p in Sy Find distance from p to next 15 points Let (a, b) be the pair with min such distance If d(a, b) < t: Return (a, b, d(a, b)) Else if t1 < t2: Return (a1, b1, t1) Else: Return (a2, b2, t2)

33 A Divide and Conquer Approach Property: If a in L, b in R, and if d(a, b) < t, then a and b occur within 15 positions of each other in Sy Find-Closest-Pair(Qx, Qy): 1. Find the median x coordinate lx 2. L = Points to the left of lx 3. R = Rest of the points 4. (a1, b1, t1) = Find-closest-pair(Lx, Ly) 5. (a2, b2, t2) = Find-closest-pair(Rx, Ry) 6. t = min(t1, t2) 7. Combine the results Implementing Divide + Combine: T(n) = 2 T(n/2) + cn T(n) = (n log n) Θ How to combine? S = points in Q within distance t of Ix Sy = sort S by y coords For p in Sy Find distance from p to next 15 points Let (a, b) be the pair with min such distance If d(a, b) < t: Return (a, b, d(a, b)) Else if t1 < t2: Return (a1, b1, t1) Else: Return (a2, b2, t2)

34 Summary: Closest Pair of Points Given a set P of n points on the plane, find the two points p and q in P s.t d(p, q) is minimum Find-Closest-Pair(Qx,Qy): 1. Find the median x coordinate lx 2. L = Points to the left of lx 3. R = Rest of the points 4. (a1, b1, t1) = Find-closest-pair(Lx, Ly) 5. (a2, b2, t2) = Find-closest-pair(Rx, Ry) 6. t = min(t1, t2) 7. Let Sy = points within distance t of Ix sorted by y 8. For each p in Sy Find distance from p to next 15 points in Sy Let (a, b) be the closest such pair 9. Report the closest pair out of: (a, b), (a1, b1), (a2, b2) Recurrence: T(n) = 2T(n/2) + cn T(n) = O(n log n) What is a base case?

35 Divide and Conquer Integer Multiplication Closest pair of points on a Plane Strassen s algorithm for matrix multiplication

36 Matrix Multiplication Problem: Given two n x n matrices X and Y, compute Z = XY Zij = Σ j Xik Ykj i X = (i,j) X Y Z Naive Method: O(n 3 ) time

37 A Simple Divide and Conquer Problem: Given two n x n matrices X and Y, compute Z = XY X = A C B D Y = E G F H Z = AE + BG CE + DG AF + BH CF + DH Algorithm 1: Operations: A..H: n/2 x n/2 1. Compute AE, BG, CE, DG, AF, BH, CF, DH 2. Compute AE + BG, CE + DG, AF + BH, CF + DH 8 n/2 x n/2 matrix multiplications, 4 additions Recurrence: T(n) = 8 T(n/2) + O(n 2 ) T(n) = O(n 3 )

38 Strassen s Algorithm Problem: Given two n x n matrices X and Y, compute Z = XY X = A C B D Y = E G F H Z = P5 + P4 - P2 + P6 P3 + P4 P1 + P2 P1 + P5 - P3 - P7 A..H: n/2 x n/2 P1 = A(F - H) P2 = (A + B)H P3 = (C + D)E P4 = D(G - E) P5 = (A + D)(E + H) P6 = (B - D)(G + H) P7 = (A - C)(E + F) Operations: 7 n/2 x n/2 matrix multiplications, O(1) additions Recurrence: T(n) = 7 T(n/2) + O(n 2 ) T(n) = O(n 2.81 )

39 Strassen s Algorithm Problem: Given two n x n matrices X and Y, compute Z = XY X = A C B D Y = E G F H Z = P5 + P4 - P2 + P6 P3 + P4 P1 + P2 P1 + P5 - P3 - P7 A..H: n/2 x n/2 P1 = A(F - H) P2 = (A + B)H P3 = (C + D)E P4 = D(G - E) P5 = (A + D)(E + H) P6 = (B - D)(G + H) P7 = (A - C)(E + F) Operations: 7 n/2 x n/2 matrix multiplications, O(1) additions Recurrence: T(n) = 7 T(n/2) + O(n 2 ) T(n) = O(n 2.81 )

40 Algorithm Design Paradigms Exhaustive Search Greedy Algorithms: Build a solution incrementally piece by piece Divide and Conquer: Divide into parts, solve each part, combine results Dynamic Programming: Divide into subtasks, perform subtask by size. Combine smaller subtasks to larger ones Hill-climbing: Start with a solution, improve it

41 Dynamic Programming (DP): A Simple Example Problem: Compute the n-th Fibonacci number Recursive Solution function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) Running Time: T(n) = T(n-1) + T(n-2) + 1

42 Dynamic Programming (DP): A Simple Example Problem: Compute the n-th Fibonacci number Recursive Solution function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) Running Time: T(n) = T(n-1) + T(n-2) + 1 T(n) = O(c n ) Running time: O(c n )

43 Dynamic Programming (DP): A Simple Example Problem: Compute the n-th Fibonacci number Recursive Solution function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) Running Time: T(n) = T(n-1) + T(n-2) + 1 T(n) = O(c n ) Running time: O(c n ) Dynamic Programming Solution function Fib2(n) Create an array fib[1..n] fib[1] = 1 fib[2] = 1 for i = 3 to n: fib[i] = fib[i-1] + fib[i-2] return fib[n]

44 Dynamic Programming (DP): A Simple Example Problem: Compute the n-th Fibonacci number Recursive Solution function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) Running Time: T(n) = T(n-1) + T(n-2) + 1 T(n) = O(c n ) Running time: O(c n ) Dynamic Programming Solution function Fib2(n) Create an array fib[1..n] fib[1] = 1 fib[2] = 1 for i = 3 to n: fib[i] = fib[i-1] + fib[i-2] return fib[n] Running Time: T(n) = O(n) Running time: O(n)

45 Why does DP do better? Problem: Compute the n-th Fibonacci number Recursive Solution function Fib1(n) if n = 1 return 1 if n = 2 return 1 return Fib1(n-1) + Fib1(n-2) F(5) Running time: O(c n ) F(4) F(3) Dynamic Programming Solution function Fib2(n) Create an array fib[1..n] fib[1] = 1 fib[2] = 1 for i = 3 to n: fib[i] = fib[i-1] + fib[i-2] return fib[n] Running time: O(n) F(2) F(3) F(2) F(2) F(1) F(1) Recursion Tree

46 Dynamic Programming Main Steps: 1. Divide the problem into subtasks 2. Define the subtasks recursively (express larger subtasks in terms of smaller ones) 3. Find the right order for solving the subtasks (but do not solve them recursively!)

47 Dynamic Programming Dynamic Programming Solution function Fib2(n) Create an array fib[1..n] fib[1] = 1 fib[2] = 1 for i = 3 to n: fib[i] = fib[i-1] + fib[i-2] return fib[n] Running time: O(n) Main Steps: 1. Divide the problem into subtasks: compute fib[i] 2. Define the subtasks recursively (express larger subtasks in terms of smaller ones) 3. Find the right order for solving the subtasks (i = 1,..,n)

48 Dynamic Programming String Reconstruction...

CSE 202: Design and Analysis of Algorithms Lecture 4

CSE 202: Design and Analysis of Algorithms Lecture 4 CSE 202: Design and Analysis of Algorithms Lecture 4 Instructor: Kamalika Chaudhuri Greedy Algorithms Direct argument - MST Exchange argument - Caching Greedy approximation algorithms Greedy Approximation

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 13 Divide and Conquer Closest Pair of Points Convex Hull Strassen Matrix Mult. Adam Smith 9/24/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova,

More information

Introduction to Algorithms

Introduction to Algorithms Lecture 1 Introduction to Algorithms 1.1 Overview The purpose of this lecture is to give a brief overview of the topic of Algorithms and the kind of thinking it involves: why we focus on the subjects that

More information

CS 173, Running Time Analysis, Counting, and Dynamic Programming. Tandy Warnow

CS 173, Running Time Analysis, Counting, and Dynamic Programming. Tandy Warnow CS 173, Running Time Analysis, Counting, and Dynamic Programming Tandy Warnow CS 173 September 25, 2018 Tandy Warnow Today Topics: Results from survey Midterm Very basic counting Analyzing running times

More information

Divide and Conquer. Divide and Conquer

Divide and Conquer. Divide and Conquer October 6, 2017 Divide and Conquer Chapter 2 of Dasgupta et al. 1 Divide and Conquer Divide: If the input size is too large to deal with in a straightforward manner, divide the data into two or more disjoint

More information

CSC Design and Analysis of Algorithms

CSC Design and Analysis of Algorithms CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

Data Structures and Algorithms CSE 465

Data Structures and Algorithms CSE 465 Data Structures and Algorithms CSE 465 LECTURE 4 More Divide and Conquer Binary Search Exponentiation Multiplication Sofya Raskhodnikova and Adam Smith Review questions How long does Merge Sort take on

More information

Union Find 11/2/2009. Union Find. Union Find via Linked Lists. Union Find via Linked Lists (cntd) Weighted-Union Heuristic. Weighted-Union Heuristic

Union Find 11/2/2009. Union Find. Union Find via Linked Lists. Union Find via Linked Lists (cntd) Weighted-Union Heuristic. Weighted-Union Heuristic Algorithms Union Find 16- Union Find Union Find Data Structures and Algorithms Andrei Bulatov In a nutshell, Kruskal s algorithm starts with a completely disjoint graph, and adds edges creating a graph

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

CSE 421 Algorithms: Divide and Conquer

CSE 421 Algorithms: Divide and Conquer CSE 42 Algorithms: Divide and Conquer Larry Ruzzo Thanks to Paul Beame, Kevin Wayne for some slides Outline: General Idea algorithm design paradigms: divide and conquer Review of Merge Sort Why does it

More information

Divide and Conquer 1

Divide and Conquer 1 Divide and Conquer A Useful Recurrence Relation Def. T(n) = number of comparisons to mergesort an input of size n. Mergesort recurrence. T(n) if n T n/2 T n/2 solve left half solve right half merging n

More information

Test 1 Review Questions with Solutions

Test 1 Review Questions with Solutions CS3510 Design & Analysis of Algorithms Section A Test 1 Review Questions with Solutions Instructor: Richard Peng Test 1 in class, Wednesday, Sep 13, 2017 Main Topics Asymptotic complexity: O, Ω, and Θ.

More information

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego CSE 22 Divide-and-conquer algorithms Fan Chung Graham UC San Diego Announcements Homework due today before the class. About homework, write your own homework, allowing oral discussion with one fixed partner.

More information

Data Structures and Algorithms CMPSC 465

Data Structures and Algorithms CMPSC 465 Data Structures and Algorithms CMPSC 465 LECTURES 7-8 More Divide and Conquer Multiplication Adam Smith S. Raskhodnikova and A. Smith; based on slides by E. Demaine and C. Leiserson John McCarthy (1927

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine

More information

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול Advanced Algorithms Problem solving Techniques. Divide and Conquer הפרד ומשול 1 Divide and Conquer A method of designing algorithms that (informally) proceeds as follows: Given an instance of the problem

More information

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 4 Divide-and-Conquer Copyright 2007 Pearson Addison-Wesley. All rights reserved. Divide-and-Conquer The most-well known algorithm design strategy: 2. Divide instance of problem into two or more

More information

Design and Analysis of Algorithms - - Assessment

Design and Analysis of Algorithms - - Assessment X Courses» Design and Analysis of Algorithms Week 1 Quiz 1) In the code fragment below, start and end are integer values and prime(x) is a function that returns true if x is a prime number and false otherwise.

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Number of Inversions Formal problem: Given: array,,,, of distinct elements Objective: Compute number of inversions 0 Example: 4, 1,

More information

Programming Assignment: recursion, recursion, recursion Due date: Thursday, July 26 at 11:29 am

Programming Assignment: recursion, recursion, recursion Due date: Thursday, July 26 at 11:29 am Programming Assignment: recursion, recursion, recursion Due date: Thursday, July 26 at 11:29 am For this project, you will implement several of static methods in a class called Recursive. You will be provided

More information

Lecture 4 CS781 February 3, 2011

Lecture 4 CS781 February 3, 2011 Lecture 4 CS78 February 3, 2 Topics: Data Compression-Huffman Trees Divide-and-Conquer Solving Recurrence Relations Counting Inversions Closest Pair Integer Multiplication Matrix Multiplication Data Compression

More information

Multithreaded Algorithms Part 1. Dept. of Computer Science & Eng University of Moratuwa

Multithreaded Algorithms Part 1. Dept. of Computer Science & Eng University of Moratuwa CS4460 Advanced d Algorithms Batch 08, L4S2 Lecture 11 Multithreaded Algorithms Part 1 N. H. N. D. de Silva Dept. of Computer Science & Eng University of Moratuwa Announcements Last topic discussed is

More information

Master Theorem, Introduction to Graphs

Master Theorem, Introduction to Graphs Master Theorem, Introduction to Graphs CSE21 Winter 2017, Day 10 (B00), Day 6-7 (A00) February 1, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Divide & Conquer: General Strategy Divide the problem of

More information

Recall from Last Time: Big-Oh Notation

Recall from Last Time: Big-Oh Notation CSE 326 Lecture 3: Analysis of Algorithms Today, we will review: Big-Oh, Little-Oh, Omega (Ω), and Theta (Θ): (Fraternities of functions ) Examples of time and space efficiency analysis Covered in Chapter

More information

Outline. CS38 Introduction to Algorithms. Fast Fourier Transform (FFT) Fast Fourier Transform (FFT) Fast Fourier Transform (FFT)

Outline. CS38 Introduction to Algorithms. Fast Fourier Transform (FFT) Fast Fourier Transform (FFT) Fast Fourier Transform (FFT) Outline CS8 Introduction to Algorithms Lecture 9 April 9, 0 Divide and Conquer design paradigm matrix multiplication Dynamic programming design paradigm Fibonacci numbers weighted interval scheduling knapsack

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

Union Find. Data Structures and Algorithms Andrei Bulatov

Union Find. Data Structures and Algorithms Andrei Bulatov Union Find Data Structures and Algorithms Andrei Bulatov Algorithms Union Find 6-2 Union Find In a nutshell, Kruskal s algorithm starts with a completely disjoint graph, and adds edges creating a graph

More information

CS Divide and Conquer

CS Divide and Conquer CS483-07 Divide and Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/

More information

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18 CS 124 Quiz 2 Review 3/25/18 1 Format You will have 83 minutes to complete the exam. The exam may have true/false questions, multiple choice, example/counterexample problems, run-this-algorithm problems,

More information

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

Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher

Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher Date of Performance:... Actual Date of Completion:... Expected Date of Completion:... ----------------------------------------------------------------------------------------------------------------

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original

More information

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego CSE 22 Divide-and-conquer algorithms Fan Chung Graham UC San Diego A useful fact about trees Any tree on n vertices contains a vertex v whose removal separates the remaining graph into two parts, one of

More information

ALGORITHM DESIGN DYNAMIC PROGRAMMING. University of Waterloo

ALGORITHM DESIGN DYNAMIC PROGRAMMING. University of Waterloo ALGORITHM DESIGN DYNAMIC PROGRAMMING University of Waterloo LIST OF SLIDES 1-1 List of Slides 1 2 Dynamic Programming Approach 3 Fibonacci Sequence (cont.) 4 Fibonacci Sequence (cont.) 5 Bottom-Up vs.

More information

Divide-and-Conquer. Dr. Yingwu Zhu

Divide-and-Conquer. Dr. Yingwu Zhu Divide-and-Conquer Dr. Yingwu Zhu Divide-and-Conquer The most-well known algorithm design technique: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances independently

More information

Divide-and-Conquer Algorithms

Divide-and-Conquer Algorithms Divide-and-Conquer Algorithms Divide and Conquer Three main steps Break input into several parts, Solve the problem in each part recursively, and Combine the solutions for the parts Contribution Applicable

More information

1 Closest Pair Problem

1 Closest Pair Problem 1 Closest Pair Problem Computational Geometry, Lectures 3,4 Closest Pair Problem Scribe Varun Nayyar Given a set of n points determine points a,b such that the interpoint distance ( Euclidean ) is the

More information

Algorithms for Data Science

Algorithms for Data Science Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra

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

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq

More information

Lecture 7: Divide & Conquer 2. Integer Multiplication. & Matrix Multiplication. CS 341: Algorithms. Tuesday, Jan 29 th 2019

Lecture 7: Divide & Conquer 2. Integer Multiplication. & Matrix Multiplication. CS 341: Algorithms. Tuesday, Jan 29 th 2019 Lecture 7: Divide & Conquer 2 Integer Multiplication & Matrix Multiplication CS 341: Algorithms Tuesday, Jan 29 th 2019 1 Outline For Today 1. Integer Multiplication 2. Matrix Multiplication 2 Outline

More information

Algorithm Design Techniques part I

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

CS Divide and Conquer

CS Divide and Conquer CS483-07 Divide and Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/

More information

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication Shayan Oveis Gharan 1 Finding the Closest Pair of Points Closest Pair of Points (non geometric) Given n points and arbitrary distances

More information

CS141: Intermediate Data Structures and Algorithms Dynamic Programming

CS141: 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 information

Divide-and-Conquer. Combine solutions to sub-problems into overall solution. Break up problem of size n into two equal parts of size!n.

Divide-and-Conquer. Combine solutions to sub-problems into overall solution. Break up problem of size n into two equal parts of size!n. Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 25 Pearson-Addon Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively.

More information

Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b

Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b simas@cs.aau.dk Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees

More information

n = 1 What problems are interesting when n is just 1?

n = 1 What problems are interesting when n is just 1? What if n=1??? n = 1 What problems are interesting when n is just 1? Sorting? No Median finding? No Addition? How long does it take to add one pair of numbers? Multiplication? How long does it take to

More information

Programming & Data Structure Laboratory. Day 2, July 24, 2014

Programming & Data Structure Laboratory. Day 2, July 24, 2014 Programming & Data Structure Laboratory Day 2, July 24, 2014 Loops Pre and post test loops for while do-while switch-case Pre-test loop and post-test loop Condition checking True Loop Body False Loop Body

More information

RUNNING TIME ANALYSIS. Problem Solving with Computers-II

RUNNING TIME ANALYSIS. Problem Solving with Computers-II RUNNING TIME ANALYSIS Problem Solving with Computers-II Performance questions 4 How efficient is a particular algorithm? CPU time usage (Running time complexity) Memory usage Disk usage Network usage Why

More information

Today: Amortized Analysis (examples) Multithreaded Algs.

Today: Amortized Analysis (examples) Multithreaded Algs. Today: Amortized Analysis (examples) Multithreaded Algs. COSC 581, Algorithms March 11, 2014 Many of these slides are adapted from several online sources Reading Assignments Today s class: Chapter 17 (Amortized

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

Cilk, Matrix Multiplication, and Sorting

Cilk, Matrix Multiplication, and Sorting 6.895 Theory of Parallel Systems Lecture 2 Lecturer: Charles Leiserson Cilk, Matrix Multiplication, and Sorting Lecture Summary 1. Parallel Processing With Cilk This section provides a brief introduction

More information

Dynamic Programming in Haskell

Dynamic Programming in Haskell Dynamic Programming in Haskell Thomas Sutton, Anchor 2015-05-27 Introduction Introduction This is a talk in two parts: 1. First I ll introduce dynamic programming and a framework for implementing DP algorithms

More information

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

Notes in Computational Geometry Voronoi Diagrams

Notes in Computational Geometry Voronoi Diagrams Notes in Computational Geometry Voronoi Diagrams Prof. Sandeep Sen and Prof. Amit Kumar Indian Institute of Technology, Delhi Voronoi Diagrams In this lecture, we study Voronoi Diagrams, also known as

More information

So far... Finished looking at lower bounds and linear sorts.

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

Problem solving paradigms

Problem solving paradigms Problem solving paradigms Bjarki Ágúst Guðmundsson Tómas Ken Magnússon Árangursrík forritun og lausn verkefna School of Computer Science Reykjavík University Today we re going to cover Problem solving

More information

5.4 Closest Pair of Points

5.4 Closest Pair of Points 5.4 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Fundamental geometric primitive. Graphics, computer vision, geographic information

More information

Rank. Selection Problem

Rank. Selection Problem Rank Rank of an element is its position in ascending key order. rank(2) = 0 rank(15) = 5 rank(20) = 7 [2,6,7,8,10,15,18,20,25,30,35,40] Selection Problem Given n unsorted elements, determine the k th smallest

More information

Selection Problem. Rank. Divide-And-Conquer Selection. Selection By Sorting

Selection Problem. Rank. Divide-And-Conquer Selection. Selection By Sorting Rank Rank of an element is its position in ascending key order. rank(2) = 0 rank(15) = 5 rank(20) = 7 [2,6,7,8,10,15,18,20,25,30,35,40] Selection Problem Given n unsorted elements, determine the k th smallest

More information

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

Algorithms with numbers (1) CISC4080, Computer Algorithms CIS, Fordham Univ.! Instructor: X. Zhang Spring 2017

Algorithms with numbers (1) CISC4080, Computer Algorithms CIS, Fordham Univ.! Instructor: X. Zhang Spring 2017 Algorithms with numbers (1) CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Spring 2017 Acknowledgement The set of slides have used materials from the following resources Slides for

More information

Midterm 1. CS Intermediate Data Structures and Algorithms. October 23, 2013

Midterm 1. CS Intermediate Data Structures and Algorithms. October 23, 2013 Midterm 1 CS 141 - Intermediate Data Structures and Algorithms October 23, 2013 By taking this exam, I affirm that all work is entirely my own. I understand what constitutes cheating, and that if I cheat

More information

Divide and Conquer. Algorithm Fall Semester

Divide and Conquer. Algorithm Fall Semester Divide and Conquer Algorithm 2014 Fall Semester Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances

More information

7.3 Divide-and-Conquer Algorithm and Recurrence Relations

7.3 Divide-and-Conquer Algorithm and Recurrence Relations 73 Divide-and-Conquer Algorithm and Recurrence Relations Many recursive algorithms take a problem with a given input and divide it into one or more smaller problems This reduction is repeatedly applied

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

CS 4800: Algorithms & Data. Lecture 1 January 10, 2017

CS 4800: Algorithms & Data. Lecture 1 January 10, 2017 CS 4800: Algorithms & Data Lecture 1 January 10, 2017 Huy L. Nguyen Email: hu.nguyen@northeastern.edu Office hours: Tuesday 1:20 3:20, WVH 358 Research: Algorithms for massive data sets ( big data ) Theoretical

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Session 24. Earth Day, 2009 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3137 Announcements Homework 6 due before last class: May 4th Final Review May

More information

CSE 202: Design and Analysis of Algorithms Lecture 3

CSE 202: Design and Analysis of Algorithms Lecture 3 CSE 202: Design and Analysis of Algorithms Lecture 3 Instructor: Kamalika Chaudhuri Announcement Homework 1 out Due on Mon April 11 in class No late homeworks will be accepted Greedy Algorithms Direct

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK UNIT-III. SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II PART A (2 Marks)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK UNIT-III. SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II PART A (2 Marks) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK UNIT-III SUB CODE: CS2251 DEPT: CSE SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II PART A (2 Marks) 1. Write any four examples

More information

Unit-2 Divide and conquer 2016

Unit-2 Divide and conquer 2016 2 Divide and conquer Overview, Structure of divide-and-conquer algorithms, binary search, quick sort, Strassen multiplication. 13% 05 Divide-and- conquer The Divide and Conquer Paradigm, is a method of

More information

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT. Chapter 3:- Divide and Conquer Compiled By:- Assistant Professor, SVBIT. Outline Introduction Multiplying large Integers Problem Problem Solving using divide and conquer algorithm - Binary Search Sorting

More information

The power of logarithmic computations. Recursive x y. Calculate x y. Can we reduce the number of multiplications?

The power of logarithmic computations. Recursive x y. Calculate x y. Can we reduce the number of multiplications? Calculate x y The power of logarithmic computations // Pre: x 0, y 0 // Returns x y int power(int x, int y) { int p = 1; for (int i = 0; i < y; ++i) p = p x; return p; Jordi Cortadella Department of Computer

More information

The Knapsack Problem an Introduction to Dynamic Programming. Slides based on Kevin Wayne / Pearson-Addison Wesley

The Knapsack Problem an Introduction to Dynamic Programming. Slides based on Kevin Wayne / Pearson-Addison Wesley The Knapsack Problem an Introduction to Dynamic Programming Slides based on Kevin Wayne / Pearson-Addison Wesley Different Problem Solving Approaches Greedy Algorithms Build up solutions in small steps

More information

Introduction to Multithreaded Algorithms

Introduction to Multithreaded Algorithms Introduction to Multithreaded Algorithms CCOM5050: Design and Analysis of Algorithms Chapter VII Selected Topics T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein. Introduction to algorithms, 3 rd

More information

Algorithms: Lecture 7. Chalmers University of Technology

Algorithms: Lecture 7. Chalmers University of Technology Algorithms: Lecture 7 Chalmers University of Technology Today s Lecture Divide & Conquer Counting Inversions Closest Pair of Points Multiplication of large integers Intro to the forthcoming problems Graphs:

More information

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort)

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort) MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication (if time, Shell's Sort) MA/CSSE 473 Day 17 Student Questions Exam 2 specification Levitin 3 rd Edition Closest

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes ) CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16 In-Class Midterm ( 11:35 AM 12:50 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures or, Classical Algorithms of the 50s, 60s, 70s Richard Mayr Slides adapted from Mary Cryan (2015/16) with small changes. School of Informatics University of Edinburgh ADS

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms Dynamic Programming Well known algorithm design techniques: Brute-Force (iterative) ti algorithms Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic

More information

QB LECTURE #1: Algorithms and Dynamic Programming

QB LECTURE #1: Algorithms and Dynamic Programming QB LECTURE #1: Algorithms and Dynamic Programming Adam Siepel Nov. 16, 2015 2 Plan for Today Introduction to algorithms Simple algorithms and running time Dynamic programming Soon: sequence alignment 3

More information

Dynamic Programming Part One

Dynamic Programming Part One Dynamic Programming Part One Announcements Problem Set Four due right now if you're using a late period. Solutions will be released at end of lecture. Problem Set Five due Monday, August 5. Feel free to

More information

Artificial Intelligence

Artificial Intelligence Artificial Intelligence Shortest Path Problem G. Guérard Department of Nouvelles Energies Ecole Supérieur d Ingénieurs Léonard de Vinci Lecture 3 GG A.I. 1/42 Outline 1 The Shortest Path Problem Introduction

More information

Divide & Conquer Algorithms

Divide & Conquer Algorithms Divide & Conquer Algorithms Calculating Powers of a Number Problem: Compute a n, where n N. Naive algorithm: Θ(n). Calculating Powers of a Number Problem: Compute a n, where n N. Naive algorithm: Θ(n).

More information

CSE 260 Lecture 19. Parallel Programming Languages

CSE 260 Lecture 19. Parallel Programming Languages CSE 260 Lecture 19 Parallel Programming Languages Announcements Thursday s office hours are cancelled Office hours on Weds 2p to 4pm Jing will hold OH, too, see Moodle Scott B. Baden /CSE 260/ Winter 2014

More information

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment.

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment. CSE 3101: Introduction to the Design and Analysis of Algorithms Instructor: Suprakash Datta (datta[at]cse.yorku.ca) ext 77875 Lectures: Tues, BC 215, 7 10 PM Office hours: Wed 4-6 pm (CSEB 3043), or by

More information

Dynamic Programming 1

Dynamic Programming 1 Dynamic Programming 1 Jie Wang University of Massachusetts Lowell Department of Computer Science 1 I thank Prof. Zachary Kissel of Merrimack College for sharing his lecture notes with me; some of the examples

More information

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conuer Algorithm Design Techniue Divide-and-Conuer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

CSC 505, Spring 2005 Week 6 Lectures page 1 of 9

CSC 505, Spring 2005 Week 6 Lectures page 1 of 9 CSC 505, Spring 2005 Week 6 Lectures page 1 of 9 Objectives: learn general strategies for problems about order statistics learn how to find the median (or k-th largest) in linear average-case number of

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

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough. Midterm Review CSE 2011 Winter 2011 17 February 2011 1 Algorithm Analysis Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough. Given

More information

Algorithms and Data Structures, or

Algorithms and Data Structures, or Algorithms and Data Structures, or... Classical Algorithms of the 50s, 60s and 70s Mary Cryan A&DS Lecture 1 1 Mary Cryan Our focus Emphasis is Algorithms ( Data Structures less important). Most of the

More information

Transformation. Computer Graphics October. Dr Anton Gerdelan

Transformation. Computer Graphics October. Dr Anton Gerdelan Transformation Computer Graphics 4052 6 October Dr Anton Gerdelan gerdela@scss.tcd.ie Simplest Example Easiest way to scale our triangle? Easiest way to move our triangle? Demo time First Maths Revision

More information

I/O Model. Cache-Oblivious Algorithms : Algorithms in the Real World. Advantages of Cache-Oblivious Algorithms 4/9/13

I/O Model. Cache-Oblivious Algorithms : Algorithms in the Real World. Advantages of Cache-Oblivious Algorithms 4/9/13 I/O Model 15-853: Algorithms in the Real World Locality II: Cache-oblivious algorithms Matrix multiplication Distribution sort Static searching Abstracts a single level of the memory hierarchy Fast memory

More information

EE/CSCI 451 Spring 2018 Homework 8 Total Points: [10 points] Explain the following terms: EREW PRAM CRCW PRAM. Brent s Theorem.

EE/CSCI 451 Spring 2018 Homework 8 Total Points: [10 points] Explain the following terms: EREW PRAM CRCW PRAM. Brent s Theorem. EE/CSCI 451 Spring 2018 Homework 8 Total Points: 100 1 [10 points] Explain the following terms: EREW PRAM CRCW PRAM Brent s Theorem BSP model 1 2 [15 points] Assume two sorted sequences of size n can be

More information

Chain Matrix Multiplication

Chain 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

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1 Overview CSE 101: Design and Analysis of Algorithms Lecture 1 CSE 101: Design and analysis of algorithms Course overview Logistics CSE 101, Fall 2018 2 First, relevant prerequisites Advanced Data Structures

More information