Recurrences (CLRS )


 Mabel Harper
 1 years ago
 Views:
Transcription
1 Recurrences (CLRS ) Last time we discussed divideandconquer algorithms Divide and Conquer To Solve P: 1. Divide P into smaller problems P 1,P 2,P 3...P k. 2. Conquer by solving the (smaller) subproblems recursively. 3. Combine solutions to P 1,P 2,...P k into solution for P. Analysis of divideandconquer algorithms and in general of recursive algorithms leads to recurrences. Mergesort lead to the recurrence T(n) = 2T(n/2) + n { Θ(1) If n = 1 or rather, T(n) = T( n 2 ) + T( n 2 ) + Θ(n) If n > 1 but we will often cheat and just solve the simple formula (equivalent to assuming that n = 2 k for some constant k, and leaving out base case and constant in Θ). Methods for solving recurrences 1. Substitution method 2. Iteration method Recursiontree method (Master method)
2 1 Solving Recurrences with the Substitution Method Idea: Make a guess for the form of the solution and prove by induction. Can be used to prove both upper bounds O() and lower bounds Ω(). Let s solve T(n) = 2T(n/2) + n using substitution Guess T(n) cn log n for some constant c (that is, T(n) = O(n log n)) Proof: Base case: we need to show that our guess holds for some base case (not necessarily n = 1, some small n is ok). Ok, since function constant for small constant n. Assume holds for n/2: T(n/2) c n 2 log n 2 (Question: Why not n 1?) Prove that holds for n: T(n) cn log n T(n) = 2T(n/2) + n 2(c n 2 log n 2 ) + n = cn log n 2 + n = cn log n cn log 2 + n = cn log n cn + n So ok if c 1 Similarly it can be shown that T(n) = Ω(n log n) Exercise! Similarly it can be shown that T(n) = T( n 2 ) + T( n 2 ) + n is Θ(n lg n). Exercise! The hard part of the substitution method is often to make a good guess. How do we make a good (i.e. tight) guess??? Unfortunately, there s no recipe for this one. Try iteratively O(n 3 ),Ω(n 3 ),O(n 2 ),Ω(n 2 ) and so on. Try solving by iteration to get a feeling of the growth.
3 2 Solving Recurrences with the Iteration/Recursiontree Method In the iteration method we iteratively unfold the recurrence until we see the pattern. The iteration method does not require making a good guess like the substitution method (but it is often more involved than using induction). Example: Solve T(n) = 8T(n/2) + n 2 (T(1) = 1) T(n) = n 2 + 8T(n/2) = n 2 + 8(8T( n 2 2 ) + (n 2 )2 ) = n T( n 22) + 8(n2 4 )) = n 2 + 2n T( n 2 2) = n 2 + 2n (8T( n 2 3 ) + ( n 2 2 )2 ) = n 2 + 2n T( n 2 3) + 82 ( n2 4 2 )) = n 2 + 2n n T( n 2 3) =... = n 2 + 2n n n n Recursion depth: How long (how many iterations) it takes until the subproblem has constant size? i times where n 2 i = 1 i = log n What is the last term? 8 i T(1) = 8 log n T(n) = n 2 + 2n n n n log n 1 n log n = log n 1 log n 1 = n 2 2 k n log n 2 k + (2 3 ) log n Now log n 1 2 k is a geometric sum so we have log n 1 2 k = Θ(2 log n 1 ) = Θ(n) (2 3 ) log n = (2 log n ) 3 = n 3 T(n) = n 2 Θ(n) + n 3 = Θ(n 3 )
4 2.1 Recursion tree A different way to look at the iteration method: is the recursiontree, discussed in the book (4.2). we draw out the recursion tree with cost of single call in each node running time is sum of costs in all nodes if you are careful drawing the recursion tree and summing up the costs, the recursion tree is a direct proof for the solution of the recurrence, just like iteration and substitution Example: T(n) = 8T(n/2) + n 2 (T(1) = 1) 1) T(n) 2) n 2 3) n 2 T(n/2) T(n/2) (n/2) 2 (n/2) 2 T(n/4) T(n/4) log n) n 2 n 2 + (n/2) 2 (n/2) 2 8(n/2) 2= 2n2 + (n/4) 2 (n/4) 2 82 (n/4) 2= 2n2 + T(1) T(1) T(1) + log n 8 T(1) T(n) = n 2 + 2n n n n log n 1 n log n
5 3 Matrix Multiplication Let X and Y be n n matrices x 11 x 12 x 1n x 21 x 22 x 1n X = x 31 x 32 x 1n x n1 x n2 x nn We want to compute Z = X Y z ij = n k=1 X ik Y kj Naive method uses n 2 n = Θ(n 3 ) operations Divideandconquer solution: { } { } A B E F Z = = C D G H { (A E + B G) (A F + B H) (C E + D G) (C F + D H) The above naturally leads to divideandconquer solution: Divide X and Y into 8 submatrices A, B, C, and D. Do 8 matrix multiplications recursively. Compute Z by combining results (doing 4 matrix additions). Lets assume n = 2 c for some constant c and let A, B, C and D be n/2 n/2 matrices Running time of algorithm is T(n) = 8T(n/2) + Θ(n 2 ) T(n) = Θ(n 3 ) But we already discussed a (simpler/naive) O(n 3 ) algorithm! Can we do better? 3.1 Strassen s Algorithm Strassen observed the following: { } { } { A B E F (S1 + S Z = = 2 S 4 + S 6 ) (S 4 + S 5 ) C D G H (S 6 + S 7 ) (S 2 + S 3 + S 5 S 7 ) where } } S 1 = (B D) (G + H) S 2 = (A + D) (E + H) S 3 = (A C) (E + F) S 4 = (A + B) H S 5 = A (F H) S 6 = D (G E) S 7 = (C + D) E
6 Lets test that S 6 + S 7 is really C E + D G S 6 + S 7 = D (G E) + (C + D) E = DG DE + CE + DE = DG + CE This leads to a divideandconquer algorithm with running time T(n) = 7T(n/2) + Θ(n 2 ) We only need to perform 7 multiplications recursively. Division/Combination can still be performed in Θ(n 2 ) time. Lets solve the recurrence using the iteration method T(n) = 7T(n/2) + n 2 = n 2 + 7(7T( n 2 2 ) + (n 2 )2 ) = n 2 + ( 7 2 2)n T( n 2 2) = n 2 + ( 7 2 2)n (7T( n 2 3) + ( n 2 2)2 ) = n 2 + ( 7 2 2)n2 + ( 7 2 2)2 n T( n 2 3) = n 2 + ( 7 2 2)n2 + ( 7 2 2)2 n 2 + ( 7 2 2)3 n ( 7 2 2)log n 1 n log n = log n 1 i=0 ( 7 2 2)i n log n = n 2 Θ(( 7 2 2)log n 1 ) + 7 log n = n 2 Θ( 7log n n (2 2 ) log n) + 7log = n 2 Θ( 7log n n 2 ) + 7log n = Θ(7 log n ) Now we have the following: Or in general: a log k n = n log k a 7 log n = 7 log 7 n log 7 2 = (7 log 7 n ) (1/ log 7 2) = n (1/ log 7 2) = n log 2 7 log 2 2 = n log 7
7 So the solution is T(n) = Θ(n log7 ) = Θ(n ) Note: We are hiding a much bigger constant in Θ() than before. Currently best known bound is O(n ) (another method). Lower bound is (trivially) Ω(n 2 ). 4 Master Method We have solved several recurrences using substitution and iteration. we solved several recurrences of the form T(n) = at(n/b) + n c (T(1) = 1). Strassen s algorithm T(n) = 7T(n/2) + n 2 (a = 7,b = 2, and c = 2) Mergesort T(n) = 2T(n/2) + n (a = 2,b = 2, and c = 1). It would be nice to have a general solution to the recurrence T(n) = at(n/b) + n c. We do! T(n) = at ( ) n b + n c a 1,b 1,c > 0 Θ(n log b a ) a > b c T(n) = Θ(n c log b n) a = b c Θ(n c ) a < b c Proof (Iteration method) T(n) = at ( n) b + n c ( (n = n c ) ( )) c + a b + at n b 2 = n c + ( ) ( ) a b n c + a 2 T n c b 2 = n c + ( a ) (( ) c ( )) b n c + a 2 n c b + at n 2 b 3 = n c + ( a ) b n c + ( a ) ( ) 2 c b n c + a 3 T n c b 3 =... = n c + ( a = n c log b n 1 = n c log b n 1 ) b n c + ( a ) 2 c b n c + ( a ) 3 c b n c + ( a ) 4 c b n c ( a ) logb n 1 c b n c + a log c b n T(1) ( a ) k b + a log c b n ( a b c ) k + n log b a Recall geometric sum n x k = xn+1 1 x 1 = Θ(x n )
8 a < b c a < b c a b < 1 log b n 1 c a < b c log b a < log b b c = c T(n) = n c log b n 1 ( a ) k b + n log c b a = n c Θ(1) + n log b a = Θ(n c ) ( a b c ) k + ( a b c ) k = 1 1 ( a b c ) = Θ(1) a = b c a = b c a b = 1 log b n 1 ( a ) k c b = log b n 1 c 1 = Θ(log b n) a = b c log b a = log b b c = c T(n) = log b n 1 ( a ) k b + n log c b a = n c Θ(log b n) + n log b a = Θ(n c log b n) a > b c a > b c a b c > 1 log b n 1 T(n) = n c Θ ( ) a log b n n c + n log b a = Θ(n log b a ) + n log b a = Θ(n log b a ) ( a ) ( k ( b = Θ a ) logb n ) ( ) ( ) c b = Θ a log b n = Θ a log b n c (b c ) log b n n c Note: Book states and proves the result slightly differently (don t read it). 5 Changing variables Sometimes reucurrences can be reduced to simpler ones by changing variables Example: Solve T(n) = 2T( n) + log n Let m = log n 2 m = n n = 2 m/2 T(n) = 2T( n) + log n T(2 m ) = 2T(2 m/2 ) + m Let S(m) = T(2 m ) T(2 m ) = 2T(2 m/2 ) + m S(m) = 2S(m/2) + m S(m) = O(m log m) T(n) = T(2 m ) = S(m) = O(m log m) = O(log n log log n)
9 6 Other recurrences Some important/typical bounds on recurrences not covered by master method: Logarithmic: Θ(log n) Recurrence: T(n) = 1 + T(n/2) Typical example: Recurse on half the input (and throw half away) Variations: T(n) = 1 + T(99n/100) Linear: Θ(N) Recurrence: T(n) = 1 + T(n 1) Typical example: Single loop Variations: T(n) = 1 + 2T(n/2),T(n) = n + T(n/2),T(n) = T(n/5) + T(7n/10 + 6) + n Quadratic: Θ(n 2 ) Recurrence: T(n) = n + T(n 1) Typical example: Nested loops Exponential: Θ(2 n ) Recurrence: T(n) = 2T(n 1)
Divide And Conquer Algorithms
CSE341T/CSE549T 09/10/2014 Lecture 5 Divide And Conquer Algorithms Recall in last lecture, we looked at one way of parallelizing matrix multiplication. At the end of the lecture, we saw the reduce SUM
More informationCS473  Algorithms I
CS473  Algorithms I Lecture 4 The DivideandConquer Design Paradigm View in slideshow mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine
More informationIntro. to the DivideandConquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4
Intro. to the DivideandConquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4 I. Algorithm Design and DivideandConquer There are various strategies we
More informationMany algorithms, particularly divide and conquer algorithms, have time complexities which are naturally
Recurrence Relations Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally modeled by recurrence relations. A recurrence relation is an equation which
More informationDivideandConquer Algorithms Part Four
DivideandConquer Algorithms Part Four Announcements Problem Set 2 due right now. Can submit by Monday at 2:15PM using one late period. Problem Set 3 out, due July 22. Play around with divideandconquer
More informationToday s Outline. Exercise. Binary Search Analysis. Linear Search Analysis. Asymptotic Analysis. Analyzing Code. Announcements. Asymptotic Analysis
Today s Outline Announcements Assignment #1 due Thurs, Oct 7 at 11:45pm Asymptotic Analysis Asymptotic Analysis CSE 7 Data Structures & Algorithms Ruth Anderson Autumn 2010 Exercise Analyzing Code bool
More informationWeek 7: Divide and Conquer
Agenda: Divide and Conquer technique Multiplication of large integers Exponentiation Matrix multiplication 1 2 Divide and Conquer : To solve a problem we can break it into smaller subproblems, solve each
More informationBinary Search. Search for x in a sorted array A.
Divide and Conquer A general paradigm for algorithm design; inspired by emperors and colonizers. Threestep process: 1. Divide the problem into smaller problems. 2. Conquer by solving these problems. 3.
More informationthe recursiontree method
the recursion method recurrence into a 1 recurrence into a 2 MCS 360 Lecture 39 Introduction to Data Structures Jan Verschelde, 22 November 2010 recurrence into a The for consists of two steps: 1 Guess
More informationPolynomials and the Fast Fourier Transform (FFT) Battle Plan
Polynomials and the Fast Fourier Transform (FFT) Algorithm Design and Analysis (Wee 7) 1 Polynomials Battle Plan Algorithms to add, multiply and evaluate polynomials Coefficient and pointvalue representation
More informationDivide and Conquer. Textbook Reading Chapters 4, 7 & 33.4
Divide d Conquer Textook Reading Chapters 4, 7 & 33.4 Overview Design principle Divide d conquer Proof technique Induction, induction, induction Analysis technique Recurrence relations Prolems Sorting
More informationRecursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1
Recursion Slides by Christopher M Bourke Instructor: Berthe Y Choueiry Fall 007 Computer Science & Engineering 35 Introduction to Discrete Mathematics Sections 717 of Rosen cse35@cseunledu Recursive Algorithms
More informationThe Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n1)!
The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >
More informationAlgorithms. Margaret M. Fleck. 18 October 2010
Algorithms Margaret M. Fleck 18 October 2010 These notes cover how to analyze the running time of algorithms (sections 3.1, 3.3, 4.4, and 7.1 of Rosen). 1 Introduction The main reason for studying bigo
More informationThe UnionFind Problem Kruskal s algorithm for finding an MST presented us with a problem in datastructure design. As we looked at each edge,
The UnionFind Problem Kruskal s algorithm for finding an MST presented us with a problem in datastructure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints
More informationCSC148 Lecture 8. Algorithm Analysis Binary Search Sorting
CSC148 Lecture 8 Algorithm Analysis Binary Search Sorting Algorithm Analysis Recall definition of Big Oh: We say a function f(n) is O(g(n)) if there exists positive constants c,b such that f(n)
More informationCSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Today Registration should be done. Homework 1 due 11:59 pm next Wednesday, January 14 Review math essential
More informationClosest Pair Problem
Closest Pair Problem Given n points in ddimensions, find two whose mutual distance is smallest. Fundamental problem in many applications as well as a key step in many algorithms. p q A naive algorithm
More informationDynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction
Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach
More informationAppendix: Solving Recurrences [Fa 10] Wil Wheaton: Embrace the dark side! Sheldon: That s not even from your franchise!
Change is certain. Peace is followed by disturbances; departure of evil men by their return. Such recurrences should not constitute occasions for sadness but realities for awareness, so that one may be
More informationMatrixChain Multiplication
MatrixChain Multiplication Let A be an n by m matrix, let B be an m by p matrix, then C = AB is an n by p matrix. C = AB can be computed in O(nmp) time, using traditional matrix multiplication. Suppose
More informationFormat of DivideandConquer algorithms:
CS 360: Data Structures and Algorithms DivideandConquer (part 1) Format of DivideandConquer algorithms: Divide: Split the array or list into smaller pieces Conquer: Solve the same problem recursively
More informationRecurrences and the Complexity of Divide and Conquer Algorithms
2006 Antonio Crznig Recurrences nd the Complexity of Divide nd Conquer Algorithms Antonio Crznig Fculty of Informtics Università dell Svizzer itlin October 12, 2010 2006 Antonio Crznig Outline Anlysis
More informationLecture 1: Course overview, circuits, and formulas
Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik
More informationCMSC 451 Design and Analysis of Computer Algorithms 1
CMSC 4 Design and Analysis of Computer Algorithms David M. Mount Department of Computer Science University of Maryland Fall 003 Copyright, David M. Mount, 004, Dept. of Computer Science, University of
More informationFaster deterministic integer factorisation
David Harvey (joint work with Edgar Costa, NYU) University of New South Wales 25th October 2011 The obvious mathematical breakthrough would be the development of an easy way to factor large prime numbers
More informationLecture 3: Finding integer solutions to systems of linear equations
Lecture 3: Finding integer solutions to systems of linear equations Algorithmic Number Theory (Fall 2014) Rutgers University Swastik Kopparty Scribe: Abhishek Bhrushundi 1 Overview The goal of this lecture
More informationThe Running Time of Programs
CHAPTER 3 The Running Time of Programs In Chapter 2, we saw two radically different algorithms for sorting: selection sort and merge sort. There are, in fact, scores of algorithms for sorting. This situation
More informationLecture 12: Chain Matrix Multiplication
Lecture 12: Chain Matrix Multiplication CLRS Section 15.2 Outline of this Lecture Recalling matrix multiplication. The chain matrix multiplication problem. A dynamic programming algorithm for chain matrix
More informationcsci 210: Data Structures Recursion
csci 210: Data Structures Recursion Summary Topics recursion overview simple examples Sierpinski gasket Hanoi towers Blob check READING: GT textbook chapter 3.5 Recursion In general, a method of defining
More informationQuicksort is a divideandconquer sorting algorithm in which division is dynamically carried out (as opposed to static division in Mergesort).
Chapter 7: Quicksort Quicksort is a divideandconquer sorting algorithm in which division is dynamically carried out (as opposed to static division in Mergesort). The three steps of Quicksort are as follows:
More informationDivideandconquer algorithms
Chapter 2 Divideandconquer algorithms The divideandconquer strategy solves a problem by: 1 Breaking it into subproblems that are themselves smaller instances of the same type of problem 2 Recursively
More informationInduction. Margaret M. Fleck. 10 October These notes cover mathematical induction and recursive definition
Induction Margaret M. Fleck 10 October 011 These notes cover mathematical induction and recursive definition 1 Introduction to induction At the start of the term, we saw the following formula for computing
More informationRandomized algorithms
Randomized algorithms March 10, 2005 1 What are randomized algorithms? Algorithms which use random numbers to make decisions during the executions of the algorithm. Why would we want to do this?? Deterministic
More informationCSE 5311 Homework 3 Solution
CSE 5311 Homework 3 Solution Problem 15.11 Show that equation (15.4) follows from equation (15.3) and the initial condition T (0) = 1. We can verify that T (n) = n is a solution to the given recurrence
More informationCS 102: SOLUTIONS TO DIVIDE AND CONQUER ALGORITHMS (ASSGN 4)
CS 10: SOLUTIONS TO DIVIDE AND CONQUER ALGORITHMS (ASSGN 4) Problem 1. a. Consider the modified binary search algorithm so that it splits the input not into two sets of almostequal sizes, but into three
More informationAnalysis of Algorithms I: Optimal Binary Search Trees
Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search
More informationIntroduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24
Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24 The final exam will cover seven topics. 1. greedy algorithms 2. divideandconquer algorithms
More informationClass Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction
Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know
More informationROUTING? Sorting? Image Processing? Sparse Matrices? Reconfigurable Meshes! P A R C
ROUTING? Sorting? Image Processing? Sparse Matrices? Reconfigurable Meshes! P A R C Heiko Schröder, 1998 Reconfigurable architectures FPGAs reconfigurable multibus reconfigurable networks (Transputers,
More informationCS473  Algorithms I
CS473  Algorithms I Lecture 9 Sorting in Linear Time View in slideshow mode 1 How Fast Can We Sort? The algorithms we have seen so far: Based on comparison of elements We only care about the relative
More informationData Structures. Algorithm Performance and Big O Analysis
Data Structures Algorithm Performance and Big O Analysis What s an Algorithm? a clearly specified set of instructions to be followed to solve a problem. In essence: A computer program. In detail: Defined
More informationrecursion, O(n), linked lists 6/14
recursion, O(n), linked lists 6/14 recursion reducing the amount of data to process and processing a smaller amount of data example: process one item in a list, recursively process the rest of the list
More informationMerge Sort. 2004 Goodrich, Tamassia. Merge Sort 1
Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort 1 DivideandConquer Divideand conquer is a general algorithm design paradigm: Divide: divide the input data S in two disjoint subsets
More informationU.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, 2009. Notes on Algebra
U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, 2009 Notes on Algebra These notes contain as little theory as possible, and most results are stated without proof. Any introductory
More informationFrom Last Time: Remove (Delete) Operation
CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From
More informationA Note on Maximum Independent Sets in Rectangle Intersection Graphs
A Note on Maximum Independent Sets in Rectangle Intersection Graphs Timothy M. Chan School of Computer Science University of Waterloo Waterloo, Ontario N2L 3G1, Canada tmchan@uwaterloo.ca September 12,
More informationSOLVING LINEAR SYSTEMS
SOLVING LINEAR SYSTEMS Linear systems Ax = b occur widely in applied mathematics They occur as direct formulations of real world problems; but more often, they occur as a part of the numerical analysis
More informationThe Goldberg Rao Algorithm for the Maximum Flow Problem
The Goldberg Rao Algorithm for the Maximum Flow Problem COS 528 class notes October 18, 2006 Scribe: Dávid Papp Main idea: use of the blocking flow paradigm to achieve essentially O(min{m 2/3, n 1/2 }
More informationAnalysis of Algorithms: The Nonrecursive Case
Analysis of Algorithms: The Nonrecursive Case Key topics: * Introduction * Generalizing Running Time * Doing a Timing Analysis * BigOh Notation * BigOh Operations * Analyzing Some Simple Programs 
More information1 Review of complex numbers
1 Review of complex numbers 1.1 Complex numbers: algebra The set C of complex numbers is formed by adding a square root i of 1 to the set of real numbers: i = 1. Every complex number can be written uniquely
More informationChapter 6. Cuboids. and. vol(conv(p ))
Chapter 6 Cuboids We have already seen that we can efficiently find the bounding box Q(P ) and an arbitrarily good approximation to the smallest enclosing ball B(P ) of a set P R d. Unfortunately, both
More informationQuiz 1 Solutions. (a) T F The height of any binary search tree with n nodes is O(log n). Explain:
Introduction to Algorithms March 9, 2011 Massachusetts Institute of Technology 6.006 Spring 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Quiz 1 Solutions Problem 1. Quiz 1 Solutions True
More information2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]
Code No: R05220502 Set No. 1 1. (a) Describe the performance analysis in detail. (b) Show that f 1 (n)+f 2 (n) = 0(max(g 1 (n), g 2 (n)) where f 1 (n) = 0(g 1 (n)) and f 2 (n) = 0(g 2 (n)). [8+8] 2. (a)
More informationLS.6 Solution Matrices
LS.6 Solution Matrices In the literature, solutions to linear systems often are expressed using square matrices rather than vectors. You need to get used to the terminology. As before, we state the definitions
More informationIntroduction to Algorithms. Part 1: Divide and Conquer Sorting and Searching
Introduction to Algorithms Part 1: Divide and Conquer Sorting and Searching 1) Convex Hulls: An Example 2) Divide and Conquer 3) Sorting Revisited 4) Parallel Sorting 5) Finding the Median 6) Books c Wayne
More informationKapitel 1 Multiplication of Long Integers (Faster than Long Multiplication)
Kapitel 1 Multiplication of Long Integers (Faster than Long Multiplication) Arno Eigenwillig und Kurt Mehlhorn An algorithm for multiplication of integers is taught already in primary school: To multiply
More informationAnalysis of Algorithms, I
Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadthfirst search (BFS) 4 Applications
More informationAlgorithm Design and Recursion
Chapter 13 Algorithm Design and Recursion Objectives To understand basic techniques for analyzing the efficiency of algorithms. To know what searching is and understand the algorithms for linear and binary
More information5.2 The Master Theorem
170 CHAPTER 5. RECURSION AND RECURRENCES 5.2 The Master Theorem Master Theorem In the last setion, we saw three different kinds of behavior for reurrenes of the form at (n/2) + n These behaviors depended
More informationSolution to Homework 2
Solution to Homework 2 Olena Bormashenko September 23, 2011 Section 1.4: 1(a)(b)(i)(k), 4, 5, 14; Section 1.5: 1(a)(b)(c)(d)(e)(n), 2(a)(c), 13, 16, 17, 18, 27 Section 1.4 1. Compute the following, if
More informationCS2 Algorithms and Data Structures Note 11. BreadthFirst Search and Shortest Paths
CS2 Algorithms and Data Structures Note 11 BreadthFirst Search and Shortest Paths In this last lecture of the CS2 Algorithms and Data Structures thread we will consider the problem of computing distances
More informationMATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m
MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS 1. SYSTEMS OF EQUATIONS AND MATRICES 1.1. Representation of a linear system. The general system of m equations in n unknowns can be written a 11 x 1 + a 12 x 2 +
More information1. LINEAR EQUATIONS. A linear equation in n unknowns x 1, x 2,, x n is an equation of the form
1. LINEAR EQUATIONS A linear equation in n unknowns x 1, x 2,, x n is an equation of the form a 1 x 1 + a 2 x 2 + + a n x n = b, where a 1, a 2,..., a n, b are given real numbers. For example, with x and
More informationMergesort and Quicksort
Mergesort Mergesort and Quicksort Basic plan: Divide array into two halves. Recursively sort each half. Merge two halves to make sorted whole. mergesort mergesort analysis quicksort quicksort analysis
More informationIs n a Prime Number? Manindra Agrawal. March 27, 2006, Delft. IIT Kanpur
Is n a Prime Number? Manindra Agrawal IIT Kanpur March 27, 2006, Delft Manindra Agrawal (IIT Kanpur) Is n a Prime Number? March 27, 2006, Delft 1 / 47 Overview 1 The Problem 2 Two Simple, and Slow, Methods
More informationDivide and Conquer: Counting Inversions
Divide and Conquer: Counting Inversions Rank Analysis Collaborative filtering matches your preference (books, music, movies, restaurants) with that of others finds people with similar tastes recommends
More informationCSE 421 Algorithms: Divide and Conquer
CSE 421 Algorithms: Divide and Conquer Summer 2011 Larry Ruzzo Thanks to Paul Beame, James Lee, Kevin Wayne for some slides hw2 empirical run times e n Plot Time vs n Fit curve to it (e.g., with Excel)
More informationLoop Invariants and Binary Search
Loop Invariants and Binary Search Chapter 4.3.3 and 9.3.11  Outline Ø Iterative Algorithms, Assertions and Proofs of Correctness Ø Binary Search: A Case Study  2  Outline Ø Iterative Algorithms, Assertions
More informationTo My Parents Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers
To My Parents Laxmi and Modaiah To My Family Members To My Friends To IIT Bombay To All Hard Workers Copyright 2010 by CareerMonk.com All rights reserved. Designed by Narasimha Karumanchi Printed in
More informationMATRIX ALGEBRA AND SYSTEMS OF EQUATIONS
MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS Systems of Equations and Matrices Representation of a linear system The general system of m equations in n unknowns can be written a x + a 2 x 2 + + a n x n b a
More information1.4 Fast Fourier Transform (FFT) Algorithm
74 CHAPTER AALYSIS OF DISCRETETIME LIEAR TIMEIVARIAT SYSTEMS 4 Fast Fourier Transform (FFT Algorithm Fast Fourier Transform, or FFT, is any algorithm for computing the point DFT with a computational
More informationWhat s next? Reductions other than kernelization
What s next? Reductions other than kernelization Dániel Marx HumboldtUniversität zu Berlin (with help from Fedor Fomin, Daniel Lokshtanov and Saket Saurabh) WorKer 2010: Workshop on Kernelization Nov
More information3. Mathematical Induction
3. MATHEMATICAL INDUCTION 83 3. Mathematical Induction 3.1. First Principle of Mathematical Induction. Let P (n) be a predicate with domain of discourse (over) the natural numbers N = {0, 1,,...}. If (1)
More informationAlgorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw. === Homework submission instructions ===
Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw === Homework submission instructions === For Problem 1, commit your source code and a brief documentation
More informationCS/COE 1501 http://cs.pitt.edu/~bill/1501/
CS/COE 1501 http://cs.pitt.edu/~bill/1501/ Lecture 01 Course Introduction Metanotes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge
More informationRecursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.
Recursion Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive. Why recursion? o For many problems, the recursion solution is more natural than the alternative
More information9.2 Summation Notation
9. Summation Notation 66 9. Summation Notation In the previous section, we introduced sequences and now we shall present notation and theorems concerning the sum of terms of a sequence. We begin with a
More informationDiagonal, Symmetric and Triangular Matrices
Contents 1 Diagonal, Symmetric Triangular Matrices 2 Diagonal Matrices 2.1 Products, Powers Inverses of Diagonal Matrices 2.1.1 Theorem (Powers of Matrices) 2.2 Multiplying Matrices on the Left Right by
More informationData Structures and Algorithms
Data Structures and Algorithms Luciano Bononi Computer Science Engineering University of Bologna bononi@cs.unibo.it http://www.cs.unibo.it/~bononi/ Slide credits: these slides have been translated from
More information1.2 Solving a System of Linear Equations
1.. SOLVING A SYSTEM OF LINEAR EQUATIONS 1. Solving a System of Linear Equations 1..1 Simple Systems  Basic De nitions As noticed above, the general form of a linear system of m equations in n variables
More informationFACTORING LARGE NUMBERS, A GREAT WAY TO SPEND A BIRTHDAY
FACTORING LARGE NUMBERS, A GREAT WAY TO SPEND A BIRTHDAY LINDSEY R. BOSKO I would like to acknowledge the assistance of Dr. Michael Singer. His guidance and feedback were instrumental in completing this
More informationLecture 4 Online and streaming algorithms for clustering
CSE 291: Geometric algorithms Spring 2013 Lecture 4 Online and streaming algorithms for clustering 4.1 Online kclustering To the extent that clustering takes place in the brain, it happens in an online
More informationComputer Science 210: Data Structures. Searching
Computer Science 210: Data Structures Searching Searching Given a sequence of elements, and a target element, find whether the target occurs in the sequence Variations: find first occurence; find all occurences
More informationWarshall s Algorithm: Transitive Closure
CS 0 Theory of Algorithms / CS 68 Algorithms in Bioinformaticsi Dynamic Programming Part II. Warshall s Algorithm: Transitive Closure Computes the transitive closure of a relation (Alternatively: all paths
More informationThe PRAM Model and Algorithms. Advanced Topics Spring 2008 Prof. Robert van Engelen
The PRAM Model and Algorithms Advanced Topics Spring 2008 Prof. Robert van Engelen Overview The PRAM model of parallel computation Simulations between PRAM models Worktime presentation framework of parallel
More informationLecture 2: Universality
CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal
More informationLecture 6 Online and streaming algorithms for clustering
CSE 291: Unsupervised learning Spring 2008 Lecture 6 Online and streaming algorithms for clustering 6.1 Online kclustering To the extent that clustering takes place in the brain, it happens in an online
More informationTaylor Polynomials and Taylor Series Math 126
Taylor Polynomials and Taylor Series Math 26 In many problems in science and engineering we have a function f(x) which is too complicated to answer the questions we d like to ask. In this chapter, we will
More informationIntroduction. Appendix D Mathematical Induction D1
Appendix D Mathematical Induction D D Mathematical Induction Use mathematical induction to prove a formula. Find a sum of powers of integers. Find a formula for a finite sum. Use finite differences to
More information6.080 / 6.089 Great Ideas in Theoretical Computer Science Spring 2008
MIT OpenCourseWare http://ocw.mit.edu 6.080 / 6.089 Great Ideas in Theoretical Computer Science Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
More informationSolutions to Homework 6
Solutions to Homework 6 Debasish Das EECS Department, Northwestern University ddas@northwestern.edu 1 Problem 5.24 We want to find light spanning trees with certain special properties. Given is one example
More informationCMPS 102 Solutions to Homework 1
CMPS 0 Solutions to Homework Lindsay Brown, lbrown@soe.ucsc.edu September 9, 005 Problem.. p. 3 For inputs of size n insertion sort runs in 8n steps, while merge sort runs in 64n lg n steps. For which
More informationComputer Algorithms. NPComplete Problems. CISC 4080 Yanjun Li
Computer Algorithms NPComplete Problems NPcompleteness The quest for efficient algorithms is about finding clever ways to bypass the process of exhaustive search, using clues from the input in order
More informationSorting algorithm. Sorting algorithms used in computer science are often classified by:
Sorting algorithm In computer science and mathematics, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most used orders are numerical order and lexicographical
More information7 Gaussian Elimination and LU Factorization
7 Gaussian Elimination and LU Factorization In this final section on matrix factorization methods for solving Ax = b we want to take a closer look at Gaussian elimination (probably the best known method
More informationOutline BST Operations Worst case Average case Balancing AVL Redblack Btrees. Binary Search Trees. Lecturer: Georgy Gimel farb
Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worstcase time complexity of BST operations
More informationAlgorithms, Integers
CHAPTER 3 Algorithms, Integers 3.1. Algorithms Consider the following list of instructions to find the maximum of three numbers a, b, c: 1. Assign variable x the value of a. 2. If b > x then assign x the
More informationA Turán Type Problem Concerning the Powers of the Degrees of a Graph
A Turán Type Problem Concerning the Powers of the Degrees of a Graph Yair Caro and Raphael Yuster Department of Mathematics University of HaifaORANIM, Tivon 36006, Israel. AMS Subject Classification:
More informationMatrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.
Matrix Algebra A. Doerr Before reading the text or the following notes glance at the following list of basic matrix algebra laws. Some Basic Matrix Laws Assume the orders of the matrices are such that
More information