Lecture 7: Divide & Conquer 2. Integer Multiplication. & Matrix Multiplication. CS 341: Algorithms. Tuesday, Jan 29 th 2019
|
|
- Candace Fox
- 5 years ago
- Views:
Transcription
1 Lecture 7: Divide & Conquer 2 Integer Multiplication & Matrix Multiplication CS 341: Algorithms Tuesday, Jan 29 th
2 Outline For Today 1. Integer Multiplication 2. Matrix Multiplication 2
3 Outline For Today 1. Integer Multiplication 2. Matrix Multiplication 3
4 Integer Multiplication u Input: 2 n-digit integers, X, Y u Output Z XY u E.g: X 2345 and Y 6789 then Z u Will work in base 10 b/c it is easier to think about base 10 u Same argument & analysis as in base 2 (done in handout) u Warning: There is no intuition to the DC algorithm we ll see 4
5 Grade School Algorithm x
6 Grade School Algorithm x shift by 1 digit 6
7 Grade School Algorithm x shift by 1 digit shift by 2 digits 7
8 Grade School Algorithm + x shift by 1 digit shift by 2 digits shift by 3 digits u Multiplying two digits > 1 operation u Addition of two digits > 1 operation u Shift by 1 digit > 1 operation (shift by x digits, x ops) TOTAL WORK: O(n 2 ) Observe that even the total work for shifting is ( n-1) O(n 2 )! 8
9 Question: Can we do better? u Upshot: A set of mysterious looking multiplications, additions and subtractions giving the correct answer! u X (a10 n/2 + b); Y (c10 n/2 + d) a c b d each of a, b, c, d is of size n/2 u Ex: a23, b45, so *10 n/ u XY ac10 n + ad10 n/2 + bc10 n/2 + bd u XY ac10 n + (ad + bc)10 n/2 + bd Call this expression ( ) 9
10 DC-Multiplication-1 procedure DC-Mult1(X, Y both n digit numbers): Base Case: if (X or Y is single digit): set a, b, c, d defined as before O(n) ac DC-Mult(a, c) shifts: O(n) ad DC-Mult(a, d) 3 additions of n digit numbers: O(n) bc DC-Mult(b, c) bd DC-Mult(b, d) return ac10 n + (ad + bc)10 n/2 + bd Total Work Outside of Recursive Calls: O(n) Recurrence: 4T(n/2) + O(n) Total Runtime: O(n 2 ) Not better than Grade School Algorithm 10
11 Observation Observation: We care about only 3 quantities in ( ): ac10 n + (ad + bc)10 n/2 + bd (1) ac > with 10 n padding (2) (ad + bc) > with 10 n/2 padding (3) bd > with 10 padding Question: If we care about 3 quantities, can we get these quantities with only 3 recursive calls? 11
12 Karatsuba-Ofman Algorithm (1962) ac10 n + (ad + bc)10 n/2 + bd (1) ac as before (2) bd as before (3) (a + b) (c + d) (ac + ad + bc + bd) Observation: (3) (2) (1) (ac+ad+bc+bd)-ac bd ad + bc procedure KO(X, Y both n digit numbers): Base Case: if (X or Y is single digit): set a, b, c, d defined as before ac KO(a, c) bd KO(b, d) X KO(a+b, c+d) return (ac)10 n + (X-ac-bd)10 n/2 + bd 12
13 Karatsuba-Ofman Algorithm (1962) procedure KO(X, Y both n digit numbers): Base Case: if (X or Y is single digit): set a, b, c, d defined as before O(n) ac KO(a, c) bd KO(b, d) O(n) X KO(a+b, c+d) return (ac)10 n + (X ac - bd)10 n/2 + bd O(n) Total Work Outside of Recursive Calls: O(n) Recurrence: 3T(n/2) + O(n) Total Runtime: O(n log_2(3) n 1.59 ) 13
14 Facts About Multiplication Fact 1: (By Toom & Stephen Cook): Can generalize KO to divide X and Y into k pieces instead of 2 (Math gets very messy) and get O(n log_k(2k-1) ) > O(n 1+ε ) for any ε > 1 Stephen Cook is a Canadian Computer Scientist UToronto. Fact 2: Best known alg: O(nlog(n)loglog(n)) (Schonhage & Strassen) 14
15 Outline For Today 1. Integer Multiplication 2. Matrix Multiplication 15
16 Matrix Multiplication u Input: 2 n x n matrices A, B u Output: C AxB j a 11 a 12 a 1n b 11 b 12 b 1n c 11 c 12 c 1n i a 21 a 22 a 2n b 21 b 22 b 2n X c 21 c 22 c 2n c ij a n1 a n2 a nn n b n1 b n2 b nn c n1 c n2 c nn c ij a ik b kj (a i1 b 1 j + a i2 b 2 j a in b nj ) k1 Q: By definition, how many multip. and additions needed to compute c ij? A: n multiplications, n-1 additions Then there are O(n 3 ) basic operations (by definition) to compute C. u Warning: Again, no intuition to the DC algorithm we ll see! 16
17 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
18 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
19 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
20 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
21 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
22 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
23 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
24 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn
25 Standard Algorithm a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn procedure StandardMM(A, B nxn matrices): C int[n][n]; for i 1 n: for j 1 n: C[i][j] 0; for k1 n: C[i][j] + a ik b kj return C Runtime: O(n 3 )
26 Question: Can we Divide & Conquer? a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n X b n1 b n2 b nn c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn 26
27 Question: Can we Divide & Conquer? A 11 A 12 B 11 B 12 C 11 C 12 X A 21 A 22 B 21 B 22 C 21 C 22 u Where A 11,, A 22, B 11,, B 22, & C 11,, C 22 are n/2 x n/2 matrices. Fact: When you split matrices into blocks & multiply, the blocks behave as they are atomic elements. n C ij A ik B kj (A i1 B 1 j + A i2 B 2 j A in B nj ) k1 where + is matrix addition operation (coordinate-wise addition) 27
28 Matrix Addition a 11 a 12 a 1n b 11 b 12 b 1n c 11 c 12 c 1n a 21 a 22 a 2n a n1 a n2 a nn b 21 b 22 b 2n + b n1 b n2 b nn c 21 c 22 c 2n c n1 c n2 c nn 28
29 Matrix Addition a 11 a 12 a 1n b 11 b 12 b 1n c 11 c 12 c 1n a 21 a 22 a 2n a n1 a n2 a nn b 21 b 22 b 2n + b n1 b n2 b nn c 21 c 22 c 2n c n1 c n2 c nn 29
30 Matrix Addition a 11 a 12 a 1n b 11 b 12 b 1n c 11 c 12 c 1n a 21 a 22 a 2n a n1 a n2 a nn b 21 b 22 b 2n + b n1 b n2 b nn c 21 c 22 c 2n c n1 c n2 c nn O(n 2 ) operation 30
31 Example of Block Multiplication X *3 + 4*2 + 3*5 + 2*
32 Example of Block Multiplication X *2 + 4*4 + 3*2 + 2*
33 Example of Block Multiplication X *3 + 5*2 + 4*5 + 2*
34 Example of Block Multiplication X *2 + 5*4 + 4*2 + 2*
35 Example of Block Multiplication X A 11 B X A 12 B X
36 DC-1 Matrix Multiplication A 11 A 12 B 11 B 12 C 11 C 12 X A 21 A 22 B 21 B 22 C 21 C 22 procedure DC1-MM(A, B nxn matrices): C 11 DC1-MM(A 11, B 11 ) + DC1-MM(A 12, B 21 ) 36
37 DC-1 Matrix Multiplication A 11 A 12 B 11 B 12 C 11 C 12 X A 21 A 22 B 21 B 22 C 21 C 22 procedure DC1-MM(A, B nxn matrices): C 11 DC1-MM(A 11, B 11 ) + DC1-MM(A 12, B 21 ) C 12 DC1-MM(A 11, B 12 ) + DC1-MM(A 12, B 22 ) 37
38 DC-1 Matrix Multiplication A 11 A 12 B 11 B 12 C 11 C 12 X A 21 A 22 B 21 B 22 C 21 C 22 procedure DC1-MM(A, B nxn matrices): C 11 DC1-MM(A 11, B 11 ) + DC1-MM(A 12, B 21 ) C 21 DC1-MM(A 11, B 12 ) + DC1-MM(A 12, B 22 ) C 21 DC1-MM(A 21, B 11 ) + DC1-MM(A 22, B 21 ) 38
39 DC-1 Matrix Multiplication A 11 A 12 B 11 B 12 C 11 C 12 X A 21 A 22 B 21 B 22 C 21 C 22 procedure DC1-MM(A, B nxn matrices): C 11 DC1-MM(A 11, B 11 ) + DC1-MM(A 12, B 21 ) C 21 DC1-MM(A 11, B 12 ) + DC1-MM(A 12, B 22 ) C 12 DC1-MM(A 21, B 11 ) + DC1-MM(A 22, B 21 ) C 22 DC1-MM(A 21, B 12 ) + DC1-MM(A 22, B 22 ) return C C 11 C 21 C 12 C 22 Outside recursion: 4 additions of n/2xn/2 matrices4n 2 /4n 2 work Runtime: T(n) 8T(n/2) + O(n 2 ) O(n 3 ) (by Master Thm) So not faster than standard method! 39
40 Strassen s (Mysterious) Algorithm (1969) A 11 A 12 B 11 B 12 C 11 Z 5 + Z 4 -Z 2 + Z 6 C 12 Z 1 + Z 2 X A 21 A 22 B 21 B 22 C 21 Z 3 + Z 4 C 22 Z 5 + Z 1 - Z 3 Z 7 Z 1 A 11 (B 12 B 22 ) Z 2 (A 11 + A 12 )B 22 Z 3 (A 21 + A 22 )B 11 Z 4 A 22 (B 21 + B 11 ) Z 5 (A 11 + A 22 )(B 11 + B 22 ) Z 6 (A 12 - A 22 )(B 21 + B 22 ) Z 7 (A 11 A 21 )(B 11 + B 12 ) Exercise: Check the rest of the quadrants to believe Strassen! Ex: C 12 Z 1 + Z 2 A 11 B 12 A 11 B 22 + A 11 B 22 + A 12 B 22 A 11 B 12 + A 12 B 22 40
41 Strassen s (Mysterious) Algorithm A 11 A 12 B 11 B 12 C 11 Z 5 + Z 4 -Z 2 + Z 6 C 12 Z 1 + Z 2 X A 21 A 22 B 21 B 22 C 21 Z 3 + Z 4 C 22 Z 5 + Z 1 - Z 3 Z 7 procedure Strassen(A, B nxn matrices): Z 1 Strassen(A 11, (B 12 B 22 )); Z 2 Strassen((A 11 + A 12 ), B 22 ) Z 3 Strassen((A 21 + A 22 ), B 11 ); Z 4 Strassen(A 22, (B 21 + B 11 )) Z 5 Strassen((A 11 + A 22 ), (B 11 + B 22 )) Z 6 Strassen((A 12 - A 22 ), (B 21 + B 22 )) Z 7 Strassen((A 11 A 21 ), (B 11 + B 12 )) C 11 Z 5 + Z 4 -Z 2 + Z 6 ; C 12 Z 1 + Z 2 ; C 21 Z 3 + Z 4 ; C 22 Z 5 + Z 1 - Z 3 Z 7 return C C 11 C 21 C 12 C 22 Runtime: T(n) 7T(n/2) + O(n 2 ) O(n log_2(7) n 2.81 ) (by Master Thm) (Asymptotically) much faster than standard algorithm! 41
42 History of Matrix Multiplication Runtime Year Authors O(n 3 ) until 1969 N/A O(n 2.81 ) 1969 Strassen O(n ) 1978 Pan O(n ) 1979 Bini et. al. O(n ) 1981 Schoenhage O(n ) 1982 Romani O(n ) 1983 Coppersmith & Winograd O(n ) 1986 Strassen O(n ) 1989 Coppersmith and Winograd O(n ) 2011 Stothers O(n ) 2012 V. Williams O(n ) 2013 Le Gall 42
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 informationAdvanced 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 informationn = 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 informationChapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part
More informationCSC 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 informationCS473 - 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 informationLecture 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 informationCSC 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 informationCSE 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 informationCSE 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 information2/26/2016. Divide and Conquer. Chapter 6. The Divide and Conquer Paradigm
Divide and Conquer Chapter 6 Divide and Conquer A divide and conquer algorithm divides the problem instance into a number of subinstances (in most cases 2), recursively solves each subinsance separately,
More informationDivide-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 informationDivide-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 informationAttendance (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 informationCase Study: Matrix Multiplication. 6.S898: Advanced Performance Engineering for Multicore Applications February 22, 2017
Case Study: Matrix Multiplication 6.S898: Advanced Performance Engineering for Multicore Applications February 22, 2017 1 4k-by-4k Matrix Multiplication Version Implementation Running time (s) GFLOPS Absolute
More informationChapter 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 information7.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 informationCS303 (Spring 2008) Solutions to Assignment 7
CS303 (Spring 008) Solutions to Assignment 7 Problem 1 Here is our implementation of a class for long numbers. It includes addition, subtraction, and both ways of multiplying. The rest of the code, not
More informationDivide-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 informationD-BAUG Informatik I. Exercise session: week 5 HS 2018
1 D-BAUG Informatik I Exercise session: week 5 HS 2018 Homework 2 Questions? Matrix and Vector in Java 3 Vector v of length n: Matrix and Vector in Java 3 Vector v of length n: double[] v = new double[n];
More informationAlgorithm 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 informationDivide 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 informationCSE 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 informationCSE 202: Design and Analysis of Algorithms Lecture 5
CSE 202: Design and Analysis of Algorithms Lecture 5 Instructor: Kamalika Chaudhuri Announcements Kamalika s Office hours today moved to tomorrow, 12:15-1:15pm Homework 1 due now Midterm on Feb 14 Algorithm
More informationCS 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 informationParallel Algorithms CSE /22/2015. Outline of this lecture: 1 Implementation of cilk for. 2. Parallel Matrix Multiplication
CSE 539 01/22/2015 Parallel Algorithms Lecture 3 Scribe: Angelina Lee Outline of this lecture: 1. Implementation of cilk for 2. Parallel Matrix Multiplication 1 Implementation of cilk for We mentioned
More informationCSE 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 informationUnit-5 Dynamic Programming 2016
5 Dynamic programming Overview, Applications - shortest path in graph, matrix multiplication, travelling salesman problem, Fibonacci Series. 20% 12 Origin: Richard Bellman, 1957 Programming referred to
More informationTest 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 informationCS 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 informationAlgorithm Design Techniques part I
Algorithm Design Techniques part I Divide-and-Conquer. Dynamic Programming DSA - lecture 8 - T.U.Cluj-Napoca - M. Joldos 1 Some Algorithm Design Techniques Top-Down Algorithms: Divide-and-Conquer Bottom-Up
More informationMaster 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 informationMultithreaded Algorithms Part 2. Dept. of Computer Science & Eng University of Moratuwa
CS4460 Advanced d Algorithms Batch 08, L4S2 Lecture 12 Multithreaded Algorithms Part 2 N. H. N. D. de Silva Dept. of Computer Science & Eng University of Moratuwa Outline: Multithreaded Algorithms Part
More informationAMS526: Numerical Analysis I (Numerical Linear Algebra)
AMS526: Numerical Analysis I (Numerical Linear Algebra) Lecture 1: Course Overview; Matrix Multiplication Xiangmin Jiao Stony Brook University Xiangmin Jiao Numerical Analysis I 1 / 21 Outline 1 Course
More informationDivide 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 informationDynamic Programming part 2
Dynamic Programming part 2 Week 7 Objectives More dynamic programming examples - Matrix Multiplication Parenthesis - Longest Common Subsequence Subproblem Optimal structure Defining the dynamic recurrence
More informationChapter 2: Divide and Conquer
Chapter : Divide and Conquer Anna Brandenberger, Anton Malakhveitchouk January 6, 018 This is the second chapter of the augmented transcript of a lecture given by Luc Devroye on the 11th of January 018
More informationLecture 13: Chain Matrix Multiplication
Lecture 3: Chain Matrix Multiplication CLRS Section 5.2 Revised April 7, 2003 Outline of this Lecture Recalling matrix multiplication. The chain matrix multiplication problem. A dynamic programming algorithm
More informationLecture 5: Matrices. Dheeraj Kumar Singh 07CS1004 Teacher: Prof. Niloy Ganguly Department of Computer Science and Engineering IIT Kharagpur
Lecture 5: Matrices Dheeraj Kumar Singh 07CS1004 Teacher: Prof. Niloy Ganguly Department of Computer Science and Engineering IIT Kharagpur 29 th July, 2008 Types of Matrices Matrix Addition and Multiplication
More informationMultithreaded Programming in. Cilk LECTURE 2. Charles E. Leiserson
Multithreaded Programming in Cilk LECTURE 2 Charles E. Leiserson Supercomputing Technologies Research Group Computer Science and Artificial Intelligence Laboratory Massachusetts Institute of Technology
More informationLecture 17: Array Algorithms
Lecture 17: Array Algorithms CS178: Programming Parallel and Distributed Systems April 4, 2001 Steven P. Reiss I. Overview A. We talking about constructing parallel programs 1. Last time we discussed sorting
More informationRectangular Matrix Multiplication Revisited
JOURNAL OF COMPLEXITY, 13, 42 49 (1997) ARTICLE NO. CM970438 Rectangular Matrix Multiplication Revisited Don Coppersmith IBM Research, T. J. Watson Research Center, Yorktown Heights, New York 10598 Received
More informationParallelizing The Matrix Multiplication. 6/10/2013 LONI Parallel Programming Workshop
Parallelizing The Matrix Multiplication 6/10/2013 LONI Parallel Programming Workshop 2013 1 Serial version 6/10/2013 LONI Parallel Programming Workshop 2013 2 X = A md x B dn = C mn d c i,j = a i,k b k,j
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA
INTERNAL ASSESSMENT TEST 2 Date : 30/3/15 Max Marks : 50 Name of faculty : Sabeeha Sultana Subject & Code : ADA(13MCA41) Answer any five full question: 1.Illustrate Mergesort for the dataset 8,3,2,9,7,1,5,4.
More informationDIVIDE & CONQUER. Problem of size n. Solution to sub problem 1
DIVIDE & CONQUER Definition: Divide & conquer is a general algorithm design strategy with a general plan as follows: 1. DIVIDE: A problem s instance is divided into several smaller instances of the same
More informationChapter 11. Gauss and Karatsuba Multiplication Multiplication of complex numbers
Chapter 11 Gauss and Karatsuba Multiplication Copyright Oliver Serang, 2018 University of Montana Department of Computer Science 11.1 Multiplication of complex numbers As we remember from grade school,
More informationDivide-and-Conquer: Matrix Multiplication Strassen s Algorithm. Matrix Multiplication Problem. Step 1: Straightforward Solution.
Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar Divide-and-Conquer: Matrix Multiplication Strassen s Algorithm Matrix Multiplication Problem Matrix Multiplication Given two matrices:
More informationAlgorithm Engineering
Algorithm Engineering Paolo D Alberto Electrical and Computer Engineering Carnegie Mellon University Personal Research Background Embedded and High Performance Computing Compiler: Static and Dynamic Theory
More informationAlgorithms. Algorithms 6.5 REDUCTIONS. introduction designing algorithms establishing lower bounds classifying problems intractability
Algorithms ROBERT SEDGEWICK KEVIN WAYNE 6.5 REDUCTIONS Algorithms F O U R T H E D I T I O N ROBERT SEDGEWICK KEVIN WAYNE introduction designing algorithms establishing lower bounds classifying problems
More informationGRADE 7 MATH LEARNING GUIDE
GRADE 7 MATH Lesson 9: Properties of the Operations on Rational Numbers Time:.5 hours Pre-requisite Concepts: Operations on rational numbers About the Lesson: The purpose of this lesson is to use properties
More informationTRUNCATION SCHEMES FOR RECURSIVE MULTIPLIERS
39 th Asilomar Conference on Signals, Systems and Computers TRUNCATION SCHEMES FOR RECURSIVE MULTIPLIERS Pedram Mokrian,, Huapeng Wu, Majid Ahmadi Research Centre for Integrated Microsystems Department
More informationCS 231: Algorithmic Problem Solving
CS 231: Algorithmic Problem Solving Naomi Nishimura Module 5 Date of this version: June 14, 2018 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides
More informationEfficient Sequential Algorithms, Comp309. Problems. Part 1: Algorithmic Paradigms
Efficient Sequential Algorithms, Comp309 Part 1: Algorithmic Paradigms University of Liverpool References: T. H. Cormen, C. E. Leiserson, R. L. Rivest Introduction to Algorithms, Second Edition. MIT Press
More informationThat is, does the algorithm s output always satisfy the input to output specification that we desire?
CS 125 Course Notes 1 Fall 2016 Welcome to CS 125, a course on algorithms and computational complexity. First, what do these terms means? An algorithm is a recipe or a well-defined procedure for performing
More informationDivide & Conquer Design Technique
Divide & Conquer Design Technique Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY 1 The Divide & Conquer strategy can be described in general terms as follows: A
More informationUNIT-2 DIVIDE & CONQUER
Overview: Divide and Conquer Master theorem Master theorem based analysis for Binary Search Merge Sort Quick Sort Divide and Conquer UNIT-2 DIVIDE & CONQUER Basic Idea: 1. Decompose problems into sub instances.
More information1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors
1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors on an EREW PRAM: See solution for the next problem. Omit the step where each processor sequentially computes the AND of
More informationCS473-Algorithms I. Lecture 10. Dynamic Programming. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 1 Dynamic Programming 1 Introduction An algorithm design paradigm like divide-and-conquer Programming : A tabular method (not writing computer code) Divide-and-Conquer (DAC):
More informationAlgorithms 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 informationMergesort again. 1. Split the list into two equal parts
Quicksort Mergesort again 1. Split the list into two equal parts 5 3 9 2 8 7 3 2 1 4 5 3 9 2 8 7 3 2 1 4 Mergesort again 2. Recursively mergesort the two parts 5 3 9 2 8 7 3 2 1 4 2 3 5 8 9 1 2 3 4 7 Mergesort
More informationMA/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 information12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares
12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares Optimal substructure Dynamic programming is typically applied to optimization problems. An optimal solution to the original
More informationTiming GMP s Integer Multiplication Algorithm
Applied Symbolic Computation (CS 567) Assignment 3 Zexi Liu 12/08/2010 1 NxN limb 1 multiplications and squares are done using one of seven algorithms, as the size N increases Algorithm Basecase Karatsuba
More informationAlgorithms 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 informationAlgorithms, Fall 2007 Lectures Avrim Blum Department of Computer Science Carnegie Mellon University
15-451 Algorithms, Fall 2007 Lectures 1-15 Avrim Blum Department of Computer Science Carnegie Mellon University October 15, 2007 Contents 1 Introduction to Algorithms 3 1.1 Overview..........................................
More informationAlgorithms Lectures 1-10
15-451 Algorithms Lectures 1-10 Author: Avrim Blum Instructors: Avrim Blum Manuel Blum Department of Computer Science Carnegie Mellon University August 23, 2011 Contents 1 Introduction to Algorithms 2
More informationReview for Midterm Exam
Review for Midterm Exam 1 Policies and Overview midterm exam policies overview of problems, algorithms, data structures overview of discrete mathematics 2 Sample Questions on the cost functions of algorithms
More informationOutline. 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 informationCS 361 Algorithms & Data Structures Lecture 1. Prof. Tom Hayes University of New Mexico
CS 361 Algorithms & Data Structures Lecture 1 Prof. Tom Hayes University of New Mexico 8-21-2012 1 Who we are Prof. Tom Hayes, hayes@cs.unm.edu Office: FEC 149 Hours: TuW 2:00-2:50 and by appt Phone: 277-9328
More informationn! = 1 * 2 * 3 * 4 * * (n-1) * n
The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems which are
More informationCSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 17: Divide and Conquer Design examples.
CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 17: Divide and Conquer Design examples. DIVIDE AND CONQUER EXAMPLES (GREATEST OVERLAP.) Given a list
More informationMatrix Multiplication
Matrix Multiplication Nur Dean PhD Program in Computer Science The Graduate Center, CUNY 05/01/2017 Nur Dean (The Graduate Center) Matrix Multiplication 05/01/2017 1 / 36 Today, I will talk about matrix
More informationMerge Sort. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong
Department of Computer Science and Engineering Chinese University of Hong Kong In this lecture, we will design the merge sort which sorts n elements in O(n log n) time. The algorithm illustrates a technique
More informationAlgorithms and Data Structures. Algorithms and Data Structures. Algorithms and Data Structures. Algorithms and Data Structures
Richard Mayr Slides adapted from Mary Cryan (2015/16) with some changes. School of Informatics University of Edinburgh ADS (2018/19) Lecture 1 slide 1 ADS (2018/19) Lecture 1 slide 3 ADS (2018/19) Lecture
More informationCOMPUTER SCIENCE TRIPOS
CST.2010.1.1 COMPUTER SCIENCE TRIPOS Part IA NATURAL SCIENCES TRIPOS Part IA (Paper CS/1) POLITICS, PSYCHOLOGY, AND SOCIOLOGY TRIPOS Part I (Paper 7) Monday 31 May 2010 1.30 to 4.30 COMPUTER SCIENCE Paper
More informationAlgorithms 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 informationScribe: Sam Keller (2015), Seth Hildick-Smith (2016), G. Valiant (2017) Date: January 25, 2017
CS 6, Lecture 5 Quicksort Scribe: Sam Keller (05), Seth Hildick-Smith (06), G. Valiant (07) Date: January 5, 07 Introduction Today we ll study another sorting algorithm. Quicksort was invented in 959 by
More informationFinite Math - J-term Homework. Section Inverse of a Square Matrix
Section.5-77, 78, 79, 80 Finite Math - J-term 017 Lecture Notes - 1/19/017 Homework Section.6-9, 1, 1, 15, 17, 18, 1, 6, 9, 3, 37, 39, 1,, 5, 6, 55 Section 5.1-9, 11, 1, 13, 1, 17, 9, 30 Section.5 - Inverse
More informationCSC236 Week 4. Larry Zhang
CSC236 Week 4 Larry Zhang 1 Announcements PS2 is out Larry s office hours in the reading week: as usual Tuesday 12-2, Wednesday 2-4 2 NEW TOPIC Recursion To really understand the math of recursion, and
More informationUnit-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 informationChapter 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 informationMatrix Multiplication and All Pairs Shortest Paths (2002; Zwick)
Matrix Multiplication and All Pairs Shortest Paths (2002; Zwick) Tadao Takaoka, University of Canterbury www.cosc.canterbury.ac.nz/tad.takaoka INDEX TERMS: all pairs shortest path problem, matrix multiplication,
More informationTo add or subtract, just add or subtract the numbers in the same column and row and place answer accordingly.
Math 3 Variable Manipulation Part 2 Systems with Matrices MATRICES An alternative method to solving system of equations is using Matrices. However, before we can solve systems of equations using matrices,
More informationDijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the
Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the Floyd-Warshall algorithm in O(n 3 ) time. Neither of
More informationPlotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1
CS241 - week 1 review Special classes of algorithms: logarithmic: O(log n) linear: O(n) quadratic: O(n 2 ) polynomial: O(n k ), k 1 exponential: O(a n ), a > 1 Classifying algorithms is generally done
More informationSolutions to Exam Data structures (X and NV)
Solutions to Exam Data structures X and NV 2005102. 1. a Insert the keys 9, 6, 2,, 97, 1 into a binary search tree BST. Draw the final tree. See Figure 1. b Add NIL nodes to the tree of 1a and color it
More informationRun Times. Efficiency Issues. Run Times cont d. More on O( ) notation
Comp2711 S1 2006 Correctness Oheads 1 Efficiency Issues Comp2711 S1 2006 Correctness Oheads 2 Run Times An implementation may be correct with respect to the Specification Pre- and Post-condition, but nevertheless
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationProcedia - Social and Behavioral Sciences 195 ( 2015 ) World Conference on Technology, Innovation and Entrepreneurship
Available online at www.sciencedirect.com ScienceDirect Procedia - Social and Behavioral Sciences 195 ( 2015 ) 1959 1965 World Conference on Technology, Innovation and Entrepreneurship Investigation of
More informationCS/COE 0447 Example Problems for Exam 2 Spring 2011
CS/COE 0447 Example Problems for Exam 2 Spring 2011 1) Show the steps to multiply the 4-bit numbers 3 and 5 with the fast shift-add multipler. Use the table below. List the multiplicand (M) and product
More informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationDivide & 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 informationScientific Computing. Algorithm Analysis
ECE257 Numerical Methods and Scientific Computing Algorithm Analysis Today s s class: Introduction to algorithm analysis Growth of functions Introduction What is an algorithm? A sequence of computation
More information15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015
15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015 Dynamic Programming is a powerful technique that allows one to solve many different types
More informationLecture 8. Dynamic Programming
Lecture 8. Dynamic Programming T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018
More informationData 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 informationCE 601: Numerical Methods Lecture 5. Course Coordinator: Dr. Suresh A. Kartha, Associate Professor, Department of Civil Engineering, IIT Guwahati.
CE 601: Numerical Methods Lecture 5 Course Coordinator: Dr. Suresh A. Kartha, Associate Professor, Department of Civil Engineering, IIT Guwahati. Elimination Methods For a system [A]{x} = {b} where [A]
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ More Math
CS/COE 1501 cs.pitt.edu/~bill/1501/ More Math Exponentiation x y Can easily compute with a simple algorithm: Runtime? ans = 1 i = y while i > 0: ans = ans * x i-- 2 Just like with multiplication, let s
More informationSolving Linear Recurrence Relations (8.2)
EECS 203 Spring 2016 Lecture 18 Page 1 of 10 Review: Recurrence relations (Chapter 8) Last time we started in on recurrence relations. In computer science, one of the primary reasons we look at solving
More informationDivide-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