ch5 - Chapter 5 Section 5.1.1 Selection problem - find the...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 5 Section 5.1.1 Selection problem - find the kth largest number. Given unsorted list. Can we find the largest in linear time? Will prove can't do better than that. The middle number seems to be the hardest, can it be found in linear time? Could sort, then find any. Sort in nlgn, can we do better? Section 5.1.2 Establish a lower bounds -- decision tree again. internal leaves are comparisons leaves are output of kth element # comparisons in worst case is depth of tree depth = l lg , where l is number of leaves How well does the decision tree work for the selection problem? Need n leaves depth must be lg n, is this a good bound? We already know in the easy case the largest requires n-1 comparisons! What is wrong with the decision tree? Consider the tree when I = 4 -- yields more than n leaves! Some of the leaves are duplicated. Decision tree fails since we don't know how many leaves will be duplicated.
Background image of page 1

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

View Full DocumentRight Arrow Icon
USE THE ADVESARY ARGUMENT: adversary makes you guess the most adversary's answers must be consistent pick a month and day. Is it in the winter –- no Does it start with a-m – yes, more months in the first half of the alphabet. if f(n) steps can be forced then f(n) is a lower bound in worst case Some of the remaining use a “tournament.” Section 5.2 Finding Max and Min max the largest, min the smallest Can find max in n-1 comparisons eliminate max allows min to be found in n-2 comparisons so max and min can be found in 2n-3 comparisons - not optimal. Share some work. Both can be found in 3n/2 comparisons. Consider a tournament method. Can be found in 3n/2 -2 comparisons. Prove 3n/2-2 is optimal in worst case. keys are distinct to know x is max – every other key has lost once to know y is min – every other key has won once count each win as a unit of info, there has to be n-1 wins and n-1 losses so the algorithm has to have 2n-2 pieces of info to give the correct answer.
Background image of page 2
The adversary wants to minimize the amount of info given each time in order to force worst case. observe table 5.1
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

ch5 - Chapter 5 Section 5.1.1 Selection problem - find the...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online