Lecture 7

# Introduction to Algorithms, Second Edition

• Notes
• davidvictor
• 2

This preview shows pages 1–2. Sign up to view the full content.

The University of Texas at Austin Lecture 7 Department of Computer Sciences Professor Vijaya Ramachandran Randomized Select CS357: ALGORITHMS, Spring 2006 Randomized Selection The selection problem (Chapter 9) is the following. Input. An array A [1 ..n ] of n distinct elements from a totally ordered set, and an index i , where 1 i n . Output. The i th smallest element in array A . If i = 1 the output is the minimum element in the array, and if i = n the output is the maximum element in the array. The median element is the output if n is odd and i = ( n + 1) / 2. If n is even there are two ‘middle elements’ corresponding to i = n/ 2 and i = ( n/ 2) + 1; for convenience we will assume that the median is i = d ( n + 1) / 2 e , i.e., the upper middle element, when n is even. The selection problem can be solved in O ( n log n ) time using a good sorting algorithm. But it can be solved in O ( n ) expected time using the follow- ing randomized algorithm. (It can also be solved deterministically in O ( n ) worst-case time, but we will not go into that here.)

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Spring '06
• Ramachandran
• Algorithms, xk, ith smallest element, Professor Vijaya Ramachandran

{[ 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