

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Lecture 2 Example Algorithm Analysis: Finding the maximum element in an array Lessons to learn
Recursive analysis for general n and specific values of A P(n,k) = the number of permutations of n objects for which A = k Previous example: P(3,0) = 2, P(3,1) = 3, P(3,2) = 1 Then desired E[A] = (1/n!) k k P(n,k) Analyze first element X[1] (divide and conquer analysis) Two possibilities: first element is max element (1 possible value) will increment A by 1 first element is NOT max element (n-1 possible values) will NOT increment A by 1 P(n,k) = P(n-1,k-1) + (n-1) P(n-1,k) Base Cases: P(n,0) = (n-1)! P(0,k) = 0 for k > 0 P(0,0) =? COMMENT: In most cases, we hopefully can develop recurrence relations with only 1 parameter! What happens if we start with element X[n] rather than X[1]? Example Algorithm Analysis: Testing primality Lesson to learn