ENGLISH
tut12sol

# tut12sol - COMP 271H Design and Analysis of Algorithms 2006...

• Notes
• 1

This preview shows page 1. Sign up to view the full content.

COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 12 1. (From Computational Geometry by de Berg, van Kreveld, Overmars, and Schwarzkopf) Let A be a set of numbers. Analyze the expected running time of the following procedure RandMax ( A ). The set A in the first call to RandMax contains n distinct numbers. RandMax ( A ) (a) If | A | = 1, return the number in A . (b) Otherwise, choose a random number x A . i. y := RandMax ( A - { x } ). ii. If y x , return y . iii. Otherwise, compare x with all other elements in A to confirm that x is larger than them. Return x . Possible solution: Worst case analysis: T (1) = 1 T ( n ) = T ( n - 1) + O ( n ) Result: T ( n ) = O ( n 2 ) Average case analysis: T (1) = 1 T ( n ) = T ( n - 1) + 1 n x [ Pr ( y x )(1) + Pr ( y < x )( n )] x [ Pr ( y x )(1) + Pr ( y < x )( n )] A small example: We have a set of 4 numbers, { 1 , 2 , 3 , 4 } Case 1: x = 1, A - { x } = { 2 , 3 , 4 } , y = 4, Pr ( y x ) = 1 Case 2:
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A- { x } = { 1 , 3 , 4 } , y = 4, Pr ( y ≥ x ) = 1 Case 3: x = 3, A- { x } = { 1 , 2 , 4 } , y = 4, Pr ( y ≥ x ) = 1 Case 4: x = 4, A- { x } = { 1 , 2 , 3 } , y = 3, Pr ( y ≥ x ) = 0 So, we know that Pr ( y ≥ x ) = 0 if x is maximal among all n numbers, otherwise Pr ( y ≥ x ) = 1. Also, Pr ( y < x ) = 1-Pr ( y ≥ x ), Thus, we have ∑ ∀ x [ Pr ( y ≥ x )(1) + Pr ( y < x )( n )] = 1 + 1 + 1 .... + 1 + n = ( n-1)(1) + n = 2 n-1 T ( n ) = T ( n-1) + 1 n ∑ ∀ x [ Pr ( y ≥ x )(1) + Pr ( y < x )( n )] T ( n ) = T ( n-1) + 1 n (2 n-1) T ( n ) < T ( n-1) + 2 T ( n ) = O ( n ) c ± 2006 Chung Kai Lun Peter. Comments are welcomed. Email: [email protected] 1...
View Full Document

• Spring '10
• may
• English, Analysis of algorithms, Computational complexity theory, Best, worst and average case, Chung Kai Lun Peter, RandM ax

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern