Divide & Conquer Algorithms
|
|
- Gervase Lane
- 5 years ago
- Views:
Transcription
1 Divide & Conquer Algorithms
2 Calculating Powers of a Number Problem: Compute a n, where n N. Naive algorithm: Θ(n).
3 Calculating Powers of a Number Problem: Compute a n, where n N. Naive algorithm: Θ(n). Divide-and-conquer algorithm: a n = a n/2 a n/2 a (n 1)/2 a (n 1)/2 a if n is even; if n is odd.
4 Calculating Powers of a Number Problem: Compute a n, where n N. Naive algorithm: Θ(n). Divide-and-conquer algorithm: a n = a n/2 a n/2 a (n 1)/2 a (n 1)/2 a if n is even; if n is odd. T(n) = T(n/2) + Θ(1) T(n) = Θ(lgn).
5 Fibonacci Numbers Recursive definition: F n = 0 if n = 0 1 if n = 1 F n 1 + F n 2 if n
6 Fibonacci Numbers Recursive definition: F n = 0 if n = 0 1 if n = 1 F n 1 + F n 2 if n Naive recursive algorithm: Ω(φ n ) (exp. time) where φ =(1+ 5)/ 2 is the golden ratio.
7 Fibonacci Numbers Recursive definition: F n = 0 if n = 0 1 if n = 1 F n 1 + F n 2 if n Naive recursive algorithm: Ω(φ n ) (exp. time) where φ =(1+ 5)/ 2 is the golden ratio. Appendix B
8 Computing Fibonacci Numbers Bottom-up: Compute F 0, F 1, F 2,, F n in order, forming each number by summing the two previous. Running time: Θ(n). Naive recursive squaring: F n = φ n / 5 rounded to the nearest integer. Recursive squaring: Θ(lg n) time. This method is unreliable, since floating-point arithmetic is prone to round-off errors. Appendix B
9 Strassen algorithm - Wikipedia, the free encyclopedia 9/28/16, 9:42 PM The left column represents 2x2 matrix multiplication. Naïve matrix multiplication requires one multiplication for each "1" of the left column. Each of the other columns represents a single one of the 7 multiplications in the algorithm, and the sum of2x2 thematrix columns gives thenaïve full matrix The left column represents multiplication. matrix multiplication requires one multiplication for each "1" of the left co multiplication on the left. Each of the other columns represents a single one of the 7 multiplications in the algorithm, and the sum of the columns gives the full m multiplication on the left. Matrix Multiplication Let A, B be two square matrices over a ring R. We want to calculate the matrix product C as A, B be two square a ring R. We want to calculate the matrix product C as The left column represents 2x2 matrix multiplication. Naïve matrix multiplication requires Let one multiplication for eachmatrices "1" of theover left column. Each of the other columns represents a single one of the 7 multiplications in the algorithm, and the sum of the columns gives the full matrix multiplication onrepresents the left. 2x2 matrix multiplication. Naïve matrix multiplication requires one multiplication for each "1" of the left column. The left column Each of the other columns represents a single one of the 7 multiplications in the algorithm, and the sum of the columns gives the full matrix n 2n we fill the missing rows and If the matrices B are not of type 2n 2n we fill the missing rows and columns zeros. IfLet the are not ofover typea 2ring columns multiplication ona, thebleft. A,matrices B be two square matrices R. We want to calculate the matrix product C asa,zeros. We partition A, B and C into equally sized block matrices We A, B and matrices C into equally sized block Letpartition A, B be two square over a ring R. We wantmatrices to calculate the matrix product C as If the matrices A, B are not of type 2n 2n we fill the missing rows and columns zeros. We partition A, A, B and intoofequally If the matrices B arec not type 2nsized 2n block we fillmatrices the missing rows and columns zeros. We partition A, B and C into equally sized block matrices then then then then With this construction we have not reduced the number of multiplications. We still need 8 multiplications to calculate t matrices, the same number of multiplications we need when using standard matrix multiplication. NowWe comes important part. We define matrices With this construction we have not reduced the number of multiplications. stillthe need 8 multiplications to new calculate the Ci,j matrices, same number multiplications we need when using We standard matrix multiplication. With this the construction we haveofnot reduced the number of multiplications. still need 8 multiplications to calculate the Ci,j matrices, the same number of multiplications we need when using standard matrix multiplication. With this construction we have not reduced the number of multiplications. We still need 8 multiplications to calculate the Ci,j Now comes the important part. We define new matrices matrices, thethe same numberpart. of multiplications need when using standard matrix multiplication. Now comes important We define newwe matrices Now comes the important part. We define new matrices P Page 2 of 6 Page 2 of 6 Page 2 of 6
10 Matrix Multiplication SQUARE-MATRIX-MULTIPLY-RECURSIVE.A; B/ 1 n D A:rows 2 letc be a new n n matrix 3 if n == 1 4 c 11 D a 11 b 11 5 else partition A, B,andC as in equations (4.9) 6 C 11 D SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 11 ;B 11 / C SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 12 ;B 21 / 7 C 12 D SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 11 ;B 12 / C SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 12 ;B 22 / 8 C 21 D SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 21 ;B 11 / C SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 22 ;B 21 / 9 C 22 D SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 21 ;B 12 / C SQUARE-MATRIX-MULTIPLY-RECURSIVE.A 22 ;B 22 / 10 return C This pseudocode glosses over one subtle but important implementation ( time of SQUARE-MATRIX-MULTIPLY-RE (.1/ if n D 1; T.n/ D 8T.n=2/ C.n 2 / if n>1: As we shall see from the master method i solution. Thus, this sim hall see from the T.n/ D.n 3 / an the straightfor e we continue on
11 the factor of 8 in equation (4.16) or the factor of 2 in recurrence (4.1), the recursion tree would just be linear, rather than bushy, and each level would contribute only one term to the sum. Bear in mind, therefore, that although asymptotic notation subsumes constant multiplicative factors, recursive notation such as T.n=2/ does not. Strassen s method The key to Strassen s method is to make the recursion tree slightly less bushy. That is, instead of performing eight recursive multiplications of n=2! n=2 matrices, it performs only seven. The cost of eliminating one matrix multiplication will be several new additions of n=2! n=2 matrices, but still only a constant number of additions. As before, the constant number of matrix additions will be subsumed by -notation when we set up the recurrence equation to characterize the running Strassen algorithm - Wikipedia, the free encyclopedia time. Strassen s method is not at all obvious. (This might be the biggest understatewith this construction webook.) have not reduced the number of multiplications. We still need 8 multiplications to calculate the Ci,j ment in this It has four steps: then Strassen algorithm 9/28/16, 9:42 PM matrices, the same number of multiplications we need when using standard matrix multiplication. 1. Divide the input matrices A and B and output matrix C into n=2! n=2 subma- trices, as inpart. equation (4.9).new Thismatrices step takes.1/ time by index calculation, just Now comes the important We define as in S QUARE -M ATRIX -M ULTIPLY-R ECURSIVE. only using 7 multiplications (one for each Mk) instead of 8. We may now express the Ci,j in terms of Mk, like this: 2. Create 10 matrices S1 ; S2 ; : : : ; S10, each of which is n=2! n=2 and is the sum or difference of two matrices created in step 1. We can create all 10 matrices in.n2 / time. Strassen algorithm - Wikipedia, the free encyclopedia 3. Using the submatrices created in step 1 and the 10 matrices created in step 2, recursively compute seven matrix products P1 ; P2 ; : : : ; P7. Each matrix Pi is n=2! n=2. 9/28/16, 9:42 PM Page 2 of 6 4. Compute the desired submatrices C11 ; C12 ; C21 ; C22 of the result matrix C by We iterate this division process n times (recursively) until the submatrices degenerate into numbers (elements of the ring R). adding and subtracting various combinations of the Pi matrices. We can comresulting product will be padded zeroes just like A and B, and should be stripped of the corresponding rows and 2 pute all four (one submatrices.n / time. The only using 7 multiplications for eachinm We may now express the Ci,j in terms of Mk, like this: k) instead of 8. columns. We shall see the details of steps 2 4 in a moment, but we already have enough information to set up a recurrence for the running time of Strassen s method.oflet us Practical implementations Strassen's algorithm switch to standard methods of matrix multiplication for small enough assume that once the matrix size n gets down tosubmatrices, 1, we performfor a simple which scalar those mulalgorithms are more efficient. The particular crossover point for which Strassen's algorithm is 80 Chapter 4 Divide-and-Conquer tiplication, just as in line 4 of S QUARE -M ATRIX -M ULTIPLY ECURSIVE When more efficient-r depends on.the specific implementation and hardware. Earlier authors had estimated that Strassen's algorithm is n > 1, steps 1, 2, and 4 take a total of.n2 / time, and step 3 requires us to perfaster for matrices widths from 32 to 128 for optimized implementations.[1] However, it has been observed that this form seven multiplications of n=2off! n=2 Hence, we obtain the following We have traded onematrices. matrix multiplication for a constant number matrix ad- and a 2010 study found that even a single step of Strassen's algorithm is crossover point has been increasing in of recent years, for theditions. running time T.n/ of Strassen s Once we understand recurrences and their solutions, we shall see that this We iterate thisrecurrence division process n times (recursively) until often the algorithm: submatrices degenerate into numbers (elements of the R). optimized traditional multiplication, until matrix sizes not beneficial on current architectures, compared to aring highly ( actually a lower asymptotic running time. Byof thethe master method rows and The resulting product will be tradeoff padded zeroes A and B,1000 and or should stripped corresponding.1/ if nleads D just 1 ;tolike exceed more,beand even for matrix sizes of several thousand the benefit is typically marginal at best (around 10% or lg 7 (4.18) T.n/ D in Section 4.5, recurrence (4.18) has the solution T.n/ D.n /. columns. [2] 7T.n=2/ C.n2 / if n > 1 : less). We now proceed to describe the details. In step 2, we create the following 10 Practical implementations of Strassen's matrices: algorithm switch to standard methods of matrix multiplication for small enough submatrices, for which those algorithms are more efficient. The particular crossover point for which Strassen's algorithm is Asymptotic complexity D implementation B12! B22 ; 1 more efficient depends on thesspecific and hardware. Earlier authors had estimated that Strassen's algorithm is C A12 ; faster for matrices widthss2fromd32 A to11128 for optimized implementations.[1] However, it has been observed that this The standard matrix multiplication takes approximately 2N3 (where N = 2n) arithmetic operations (additions and S3 Din recent A21 Cyears, A22 ; and a 2010 crossover point has been increasing study found that even a single step of Strassen's algorithm is 3). thetraditional asymptotic complexity isuntil Θ(Nmatrix often not beneficial on currentsarchitectures, to amultiplications); highly optimized multiplication, sizes D B21!compared B11 ; 4 exceed 1000 or more, and even matrix of ;several thousand the benefit is typically marginal at best (around 10% or S5for D A11sizes C A22 The number of additions and multiplications required in the Strassen algorithm can be calculated as follows: let f(n) be the S6 D B11 C B22 ; number of operations for a 2n 2n matrix. Then by recursive application of the Strassen algorithm, we see that S7 D A12! A22 ; f(n) = 7f(n 1) + ℓ4n, for some constant ℓ that depends on the number of additions performed at each application of the Asymptotic complexity S8 D B21 C B22 ; algorithm. Hence f(n) = (7 + o(1))n, i.e., the asymptotic complexity for multiplying matrices of size N = 2n using the S9 D A11! A21 ; Strassen algorithmn is 3 (where The standard matrix multiplication takesb11 approximately 2N N = 2 ) arithmetic operations (additions and S10 D C B12 : 3 multiplications); the asymptotic complexity is Θ(N ).. Since we must add or subtract n=2 " n=2 matrices 10 times, this step does indeed take.n2 / time. The number of additions and multiplications required in the Strassen algorithm can be calculated as follows: let f(n) be the The reduction in matrices the number of times arithmetic operations In step 3, we recursively multiply n=2"n=2 seven to compute the however comes at the price of a somewhat reduced numerical n n less).[2]
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 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 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 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 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 informationMidterm 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 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 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. 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 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 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 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 informationData 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 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 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 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 informationPROGRAM EFFICIENCY & COMPLEXITY ANALYSIS
Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?
More informationThe divide-and-conquer paradigm involves three steps at each level of the recursion: Divide the problem into a number of subproblems.
2.3 Designing algorithms There are many ways to design algorithms. Insertion sort uses an incremental approach: having sorted the subarray A[1 j - 1], we insert the single element A[j] into its proper
More informationThe 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 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 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 informationMatrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:
Matrices A Matrix is an array of numbers: We talk about one matrix, or several matrices. There are many things we can do with them... Adding A Matrix (This one has 2 Rows and 3 Columns) To add two matrices:
More informationAlgorithms: Efficiency, Analysis, techniques for solving problems using computer approach or methodology but not programming
Chapter 1 Algorithms: Efficiency, Analysis, and dod Order Preface techniques for solving problems using computer approach or methodology but not programming language e.g., search Collie Collean in phone
More informationComputer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer
Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Divide and Conquer Divide and-conquer is a very common and very powerful algorithm design technique. The general idea:
More informationCSC 8301 Design and Analysis of Algorithms: Recursive Analysis
CSC 8301 Design and Analysis of Algorithms: Recursive Analysis Professor Henry Carter Fall 2016 Housekeeping Quiz #1 New TA office hours: Tuesday 1-3 2 General Analysis Procedure Select a parameter for
More informationA 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted.
CS6402 Design and Analysis of Algorithms _ Unit II 2.1 UNIT II BRUTE FORCE AND DIVIDE-AND-CONQUER 2.1 BRUTE FORCE Brute force is a straightforward approach to solving a problem, usually directly based
More information17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer
Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are
More informationAssignment 1 (concept): Solutions
CS10b Data Structures and Algorithms Due: Thursday, January 0th Assignment 1 (concept): Solutions Note, throughout Exercises 1 to 4, n denotes the input size of a problem. 1. (10%) Rank the following functions
More informationCS302 Topic: Algorithm Analysis #2. Thursday, Sept. 21, 2006
CS302 Topic: Algorithm Analysis #2 Thursday, Sept. 21, 2006 Analysis of Algorithms The theoretical study of computer program performance and resource usage What s also important (besides performance/resource
More informationLecture 2: Getting Started
Lecture 2: Getting Started Insertion Sort Our first algorithm is Insertion Sort Solves the sorting problem Input: A sequence of n numbers a 1, a 2,..., a n. Output: A permutation (reordering) a 1, a 2,...,
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 informationIntroduction 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 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 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 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 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 informationChapter 2 Divid d e-an -Conquer 1
Chapter 2 Divide-and-Conquerid d 1 A top-down approach Patterned after the strategy employed by Napoleon Divide an instance of a problem recursively into two or more smaller instances until the solutions
More informationINTRODUCTION. An easy way to express the idea of an algorithm (very much like C/C++, Java, Pascal, Ada, )
INTRODUCTION Objective: - Algorithms - Techniques - Analysis. Algorithms: Definition: Pseudocode: An algorithm is a sequence of computational steps that tae some value, or set of values, as input and produce
More informationCS 140 : Numerical Examples on Shared Memory with Cilk++
CS 140 : Numerical Examples on Shared Memory with Cilk++ Matrix-matrix multiplication Matrix-vector multiplication Hyperobjects Thanks to Charles E. Leiserson for some of these slides 1 Work and Span (Recap)
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 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 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 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 informationMore Complicated Recursion CMPSC 122
More Complicated Recursion CMPSC 122 Now that we've gotten a taste of recursion, we'll look at several more examples of recursion that are special in their own way. I. Example with More Involved Arithmetic
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 informationL.J. Institute of Engineering & Technology Semester: VIII (2016)
Subject Name: Design & Analysis of Algorithm Subject Code:1810 Faculties: Mitesh Thakkar Sr. UNIT-1 Basics of Algorithms and Mathematics No 1 What is an algorithm? What do you mean by correct algorithm?
More informationECE G205 Fundamentals of Computer Engineering Fall Exercises in Preparation to the Midterm
ECE G205 Fundamentals of Computer Engineering Fall 2003 Exercises in Preparation to the Midterm The following problems can be solved by either providing the pseudo-codes of the required algorithms or the
More informationDense Matrix Algorithms
Dense Matrix Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text Introduction to Parallel Computing, Addison Wesley, 2003. Topic Overview Matrix-Vector Multiplication
More informationMultithreaded 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 informationAlgorithm Analysis and Design
Algorithm Analysis and Design Dr. Truong Tuan Anh Faculty of Computer Science and Engineering Ho Chi Minh City University of Technology VNU- Ho Chi Minh City 1 References [1] Cormen, T. H., Leiserson,
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 informationUniversity of the Western Cape Department of Computer Science
University of the Western Cape Department of Computer Science Algorithms and Complexity CSC212 Paper II Final Examination 13 November 2015 Time: 90 Minutes. Marks: 100. UWC number Surname, first name Mark
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 informationLecture 4: Dynamic programming I
Lecture : Dynamic programming I Dynamic programming is a powerful, tabular method that solves problems by combining solutions to subproblems. It was introduced by Bellman in the 950 s (when programming
More informationDivide and Conquer. Algorithm D-and-C(n: input size)
Divide and Conquer Algorithm D-and-C(n: input size) if n n 0 /* small size problem*/ Solve problem without futher sub-division; else Divide into m sub-problems; Conquer the sub-problems by solving them
More informationRecall 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 informationChapter 3 Dynamic programming
Chapter 3 Dynamic programming 1 Dynamic programming also solve a problem by combining the solutions to subproblems. But dynamic programming considers the situation that some subproblems will be called
More informationDynamic Programming. Design and Analysis of Algorithms. Entwurf und Analyse von Algorithmen. Irene Parada. Design and Analysis of Algorithms
Entwurf und Analyse von Algorithmen Dynamic Programming Overview Introduction Example 1 When and how to apply this method Example 2 Final remarks Introduction: when recursion is inefficient Example: Calculation
More informationAnalysis of Algorithms. CSE Data Structures April 10, 2002
Analysis of Algorithms CSE 373 - Data Structures April 10, 2002 Readings and References Reading Chapter 2, Data Structures and Algorithm Analysis in C, Weiss Other References 10-Apr-02 CSE 373 - Data Structures
More informationCS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014
CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014 Study: Chapter 4 Analysis of Algorithms, Recursive Algorithms, and Recurrence Equations 1. Prove the
More informationCSE 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 informationAlgorithms: Dynamic Programming
Algorithms: Dynamic Programming Amotz Bar-Noy CUNY Spring 2012 Amotz Bar-Noy (CUNY) Dynamic Programming Spring 2012 1 / 58 Dynamic Programming General Strategy: Solve recursively the problem top-down based
More informationIntroduction 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 informationHypercubes. (Chapter Nine)
Hypercubes (Chapter Nine) Mesh Shortcomings: Due to its simplicity and regular structure, the mesh is attractive, both theoretically and practically. A problem with the mesh is that movement of data is
More informationEECS 477: Introduction to algorithms. Lecture 6
EECS 477: Introduction to algorithms. Lecture 6 Prof. Igor Guskov guskov@eecs.umich.edu September 24, 2002 1 Lecture outline Finish up with asymptotic notation Asymptotic analysis of programs Analyzing
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 informationProgramming II (CS300)
1 Programming II (CS300) Chapter 08 : Algorithm Analysis MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Algorithm Analysis 2 Introduction Running Time Big-Oh Notation Keep in Mind Introduction Algorithm Analysis
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 informationFreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx
1 of 9 FreeMat Tutorial FreeMat is a general purpose matrix calculator. It allows you to enter matrices and then perform operations on them in the same way you would write the operations on paper. This
More informationTwelve Simple Algorithms to Compute Fibonacci Numbers
arxiv:1803.07199v2 [cs.ds] 13 Apr 2018 Twelve Simple Algorithms to Compute Fibonacci Numbers Ali Dasdan KD Consulting Saratoga, CA, USA alidasdan@gmail.com April 16, 2018 Abstract The Fibonacci numbers
More informationEE/CSCI 451 Midterm 1
EE/CSCI 451 Midterm 1 Spring 2018 Instructor: Xuehai Qian Friday: 02/26/2018 Problem # Topic Points Score 1 Definitions 20 2 Memory System Performance 10 3 Cache Performance 10 4 Shared Memory Programming
More informationData Structures and Algorithms (CSCI 340)
University of Wisconsin Parkside Fall Semester 2008 Department of Computer Science Prof. Dr. F. Seutter Data Structures and Algorithms (CSCI 340) Homework Assignments The numbering of the problems refers
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 informationSankalchand 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 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 informationFundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.
Fundamental mathematical techniques reviewed: Mathematical induction Recursion Typically taught in courses such as Calculus and Discrete Mathematics. Techniques introduced: Divide-and-Conquer Algorithms
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 informationEXAMPLE 1. Change each of the following fractions into decimals.
CHAPTER 1. THE ARITHMETIC OF NUMBERS 1.4 Decimal Notation Every rational number can be expressed using decimal notation. To change a fraction into its decimal equivalent, divide the numerator of the fraction
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 informationThe divide and conquer strategy has three basic parts. For a given problem of size n,
1 Divide & Conquer One strategy for designing efficient algorithms is the divide and conquer approach, which is also called, more simply, a recursive approach. The analysis of recursive algorithms often
More information! Addition! Multiplication! Bigger Example - RSA cryptography
! Addition! Multiplication! Bigger Example - RSA cryptography Modular Arithmetic Modular Exponentiation Primality Testing (Fermat s little theorem) Probabilistic algorithm Euclid s Algorithm for gcd (greatest
More informationMultiple-choice (35 pt.)
CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need
More informationCSC Design and Analysis of Algorithms. Lecture 5. Decrease and Conquer Algorithm Design Technique. Decrease-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 5 Decrease and Conquer Algorithm Design Technique Decrease-and-Conquer This algorithm design technique is based on exploiting a relationship between
More informationDivide-and-Conquer. Divide-and conquer is a general algorithm design paradigm:
Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9
More informationCOMP 3403 Algorithm Analysis Part 2 Chapters 4 5. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University
COMP 3403 Algorithm Analysis Part 2 Chapters 4 5 Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University Chapter 4 Decrease and Conquer Chapter 4 43 Chapter 4: Decrease and Conquer Idea:
More informationAlgorithms - Ch2 Sorting
Algorithms - Ch2 Sorting (courtesy of Prof.Pecelli with some changes from Prof. Daniels) 1/28/2015 91.404 - Algorithms 1 Algorithm Description Algorithm Description: -Pseudocode see conventions on p. 20-22
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 informationAdvanced Algorithms Class Notes for Monday, November 10, 2014
Advanced Algorithms Class Notes for Monday, November 10, 2014 Bernard Moret Divide-and-Conquer: Matrix Multiplication Divide-and-conquer is especially useful in computational geometry, but also in numerical
More informationCS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes
CS583 Lecture 01 Jana Kosecka some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes Course Info course webpage: - from the syllabus on http://cs.gmu.edu/
More informationx = 12 x = 12 1x = 16
2.2 - The Inverse of a Matrix We've seen how to add matrices, multiply them by scalars, subtract them, and multiply one matrix by another. The question naturally arises: Can we divide one matrix by another?
More informationTheory and Algorithms Introduction: insertion sort, merge sort
Theory and Algorithms Introduction: insertion sort, merge sort Rafael Ramirez rafael@iua.upf.es Analysis of algorithms The theoretical study of computer-program performance and resource usage. What s also
More informationDivide and Conquer Algorithms
CSE341T 09/13/2017 Lecture 5 Divide and Conquer Algorithms We have already seen a couple of divide and conquer algorithms in this lecture. The reduce algorithm and the algorithm to copy elements of the
More informationAnalysis of Multithreaded Algorithms
Analysis of Multithreaded Algorithms Marc Moreno Maza University of Western Ontario, London, Ontario (Canada) CS4402-9535 (Moreno Maza) Analysis of Multithreaded Algorithms CS4402-9535 1 / 27 Plan 1 Matrix
More informationMATH 423 Linear Algebra II Lecture 17: Reduced row echelon form (continued). Determinant of a matrix.
MATH 423 Linear Algebra II Lecture 17: Reduced row echelon form (continued). Determinant of a matrix. Row echelon form A matrix is said to be in the row echelon form if the leading entries shift to the
More informationIntroduction to Algorithms
Introduction to Algorithms An algorithm is any well-defined computational procedure that takes some value or set of values as input, and produces some value or set of values as output. 1 Why study algorithms?
More informationEND-TERM EXAMINATION
(Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt
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 informationSection 7.3 Divide-and-Conquer Algorithms and Recurrence Relations. 0,a m. - Division into thirds gives m = 3
Section 7.3 Divide-and-Conquer Algorithms and Recurrence Relations The form: a n = αa n/m + f (n) The sequence: {a m 0,a m 1,a m 2,...,a m k,...} n = mk for some k. - Division of the problem in half gives
More informationDATA STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary
More informationDivide and Conquer. Design and Analysis of Algorithms Andrei Bulatov
Divide and Conquer Design and Analysis of Algorithms Andrei Bulatov Algorithms Divide and Conquer 4-2 Divide and Conquer, MergeSort Recursive algorithms: Call themselves on subproblem Divide and Conquer
More information