Notes  >  Lecture 12: Recurrences - PowerPoint Presentation, Algorithms

Lecture 12: Recurrences - PowerPoint Presentation, Algorithms PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


1
CSE 421
Algorithms g
Richard Anderson
Lecture 12
Recurrences
Announcements
•Midterm
– Feb 9, In class, closed book
– Through section 5.2
Divide and Conquer
• Recurrences, Sections 5.1 and 5.2
• Algorithms
– Counting Inversions (5.3)
Cl t P i (5 4) – Closest Pair (5.4)
– Multiplication (5.5)
– FFT (5.6)
Divide and Conquer
Array Mergesort(Array a){
n = a.Length;
if (n <= 1)
t return a;
b = Mergesort(a[0 .. n/2]);
c = Mergesort(a[n/2+1 .. n-1]);
return Merge(b, c);
}
Algorithm Analysis
• Cost of Merge
• Cost of Mergesort
T(n) <= 2T(n/2) + cn; T(1) <= c;
Page 2


1
CSE 421
Algorithms g
Richard Anderson
Lecture 12
Recurrences
Announcements
•Midterm
– Feb 9, In class, closed book
– Through section 5.2
Divide and Conquer
• Recurrences, Sections 5.1 and 5.2
• Algorithms
– Counting Inversions (5.3)
Cl t P i (5 4) – Closest Pair (5.4)
– Multiplication (5.5)
– FFT (5.6)
Divide and Conquer
Array Mergesort(Array a){
n = a.Length;
if (n <= 1)
t return a;
b = Mergesort(a[0 .. n/2]);
c = Mergesort(a[n/2+1 .. n-1]);
return Merge(b, c);
}
Algorithm Analysis
• Cost of Merge
• Cost of Mergesort
T(n) <= 2T(n/2) + cn; T(1) <= c;
2
Recurrence Analysis
• Solution methods
– Unrolling recurrence
– Guess and verify
Plugging in to a “Master Theorem” – Plugging in to a Master Theorem
Unrolling the recurrence
Substitution
Prove T(n) <= cn (log
2
n + 1) for n >= 1
Induction:
Base Case:
Induction Hypothesis:
A better mergesort (?)
• Divide into 3 subarrays and recursively 
sort
• Apply 3-way merge
What is the recurrence?
Unroll recurrence for                
T(n) = 3T(n/3) + dn
T(n) = aT(n/b) + f(n)
Page 3


1
CSE 421
Algorithms g
Richard Anderson
Lecture 12
Recurrences
Announcements
•Midterm
– Feb 9, In class, closed book
– Through section 5.2
Divide and Conquer
• Recurrences, Sections 5.1 and 5.2
• Algorithms
– Counting Inversions (5.3)
Cl t P i (5 4) – Closest Pair (5.4)
– Multiplication (5.5)
– FFT (5.6)
Divide and Conquer
Array Mergesort(Array a){
n = a.Length;
if (n <= 1)
t return a;
b = Mergesort(a[0 .. n/2]);
c = Mergesort(a[n/2+1 .. n-1]);
return Merge(b, c);
}
Algorithm Analysis
• Cost of Merge
• Cost of Mergesort
T(n) <= 2T(n/2) + cn; T(1) <= c;
2
Recurrence Analysis
• Solution methods
– Unrolling recurrence
– Guess and verify
Plugging in to a “Master Theorem” – Plugging in to a Master Theorem
Unrolling the recurrence
Substitution
Prove T(n) <= cn (log
2
n + 1) for n >= 1
Induction:
Base Case:
Induction Hypothesis:
A better mergesort (?)
• Divide into 3 subarrays and recursively 
sort
• Apply 3-way merge
What is the recurrence?
Unroll recurrence for                
T(n) = 3T(n/3) + dn
T(n) = aT(n/b) + f(n)
3
T(n) = T(n/2) + cn
Where does this recurrence arise?
Solving the recurrence exactly
T(n) = 4T(n/2) + cn T(n) = 2T(n/2) + n
2
T(n) = 2T(n/2) + n
1/2
Recurrences
• Three basic behaviors
– Dominated by initial case
– Dominated by base case
All cases equal we care about the depth – All cases equal – we care about the depth
Read More

FAQs on Lecture 12: Recurrences - PowerPoint Presentation, Algorithms

1. What is a recurrence relation in computer science?
Ans. A recurrence relation in computer science is a way to define a sequence or a function in terms of its previous values. It is a mathematical equation that expresses the relationship between the current value and one or more previous values in the sequence or function.
2. How are recurrences used in algorithm analysis?
Ans. Recurrences are used in algorithm analysis to analyze the time complexity or space complexity of algorithms. By expressing the time or space required for solving a problem in terms of smaller subproblems, recurrences help in understanding the overall efficiency of an algorithm and making comparisons between different algorithms.
3. What are the common methods to solve recurrences?
Ans. There are several common methods to solve recurrences, such as the substitution method, the recursion tree method, and the master theorem. The substitution method involves making an educated guess for the solution and then proving it correct using mathematical induction. The recursion tree method involves drawing a tree to represent the recursive calls and analyzing the height and number of nodes in the tree. The master theorem is a precise mathematical formula that can be used to solve certain types of recurrences.
4. Can all recurrences be solved analytically?
Ans. No, not all recurrences can be solved analytically. Some recurrences may not have a closed-form solution, meaning that it is not possible to express the solution in terms of elementary functions or known mathematical functions. In such cases, approximation methods or numerical techniques may be used to estimate the solution.
5. How are recurrences related to dynamic programming?
Ans. Recurrences are closely related to dynamic programming as dynamic programming often involves solving subproblems and combining their solutions to solve the larger problem. Recurrences are used to express the relationship between the subproblems and their solutions, allowing dynamic programming algorithms to efficiently solve complex problems by avoiding redundant calculations. Dynamic programming algorithms often have a time complexity that is improved compared to a brute-force approach.
Download as PDF
Explore Courses for exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev