Finding the Minimum Element - Lecture Slides | CS 231, Study notes of Algorithms and Programming

Material Type: Notes; Professor: Shull; Class: Fundamental Algorithms; Subject: Computer Science; University: Wellesley College; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-jih
koofers-user-jih 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Finding the Minimum Element
Minimum(A)
min A[1]
for i 2 to length[A]
do if min > A[i]
then min A[i]
return min
Is That the Best We Can Do?
Remark
A decision tree for the MIN problem must have at least
n leaves since any one of the n keys may be the output.
pf3
pf4
pf5

Partial preview of the text

Download Finding the Minimum Element - Lecture Slides | CS 231 and more Study notes Algorithms and Programming in PDF only on Docsity!

Finding the Minimum Element

Minimum(A)

min ← A[1]

for i ← 2 to length[A]

do if min > A[i]

then min ← A[i]

return min

Is That the Best We Can Do?

Remark

A decision tree for the MIN problem must have at least

n leaves since any one of the n keys may be the output.

That Don't Impress Me Much

• The decision tree model yields a Ω(lg n ) lower bound for

finding the minimum value.

• Surely any algorithm that returns a minimum value

requires at least Ω( n ) steps.

Lower Bound On Minimum

Lemma

Any algorithm to find the min of n keys by comparisons

of keys must do at least n -1 comparisons.

Proof

In any list with n distinct entries, n-1 entries are not

minimum. An entry is not minimum if it is larger than at

least one other entry on the list.

Hence, n -1 entries must be "winner" in comparisons done

by algorithm A.

Each comparison has one only winner.

To find i

th smallest element:

p ← Randomized-Partition(A,lo,hi)

if i = p-lo+

then return A[p]

elseif i < p-lo+

then search bottom half of array for i

else search top half of array for i-(p-lo+1)

Selection in Expected Linear Time

lo p hi

p - lo smallest elements

hi - p largest elements

Randomized-Select

Randomized-Select(A,lo,hi,i)

if lo = hi

then return A[lo]

p ← Randomized-Partition(A,lo,hi)

if i = p-lo+

then return A[p]

elseif i < p-lo+

then return Randomized-Select(A,lo,p-1,i)

else return Randomized-Select(A,p+1,hi,i-(p-lo+1))

An Unhappy Choice in the Worst Case ...

lo p=hi

n-1 elements

A Happy Choice on Average ...

lo p hi

n/2

n/2