7300_04

7300_04 - CSC7300 AlgorithmsDesignandAnalysis

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

View Full Document Right Arrow Icon
1 CSC 7300 Algorithms Design and Analysis  Lecture 4: Order Statistics, Select/Median,Divide  and Conquer, Amortization
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Finding  max min  in an unsorted array ( upper bound  and  lower bound ) Finding both  max  and  min  ( upper bound ) Selecting the  k th  smallest element Order Statistics k th  smallest element     k th  order statistics
Background image of page 2
3 Finding Maximum in unsorted array
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Finding Maximum  Let  S  denote the input set of  n  items    To find the maximum of  S , we can:    Step 1:  Set  max  = item 1   Step 2:  for  k  = 2, 3, …,  n                    if (item  k  is larger than  max   Update  max  = item  k ;   Step 3:  return  max ; # comparisons  = n – 1
Background image of page 4
5 Lower Bound Question:   Can we find the maximum using fewer than  n   – 1 comparisons? Answer:   No !  To ensure that an item  x  is not the  maximum, there must be  at least  one comparison in  which  x  is the smaller of the compared items     So, we need to ensure  n-1  items not max         at least   n  – 1 comparisons are needed
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Selecting Second Highest First max and second max n + log n – 2 Tournament Tree Comparision Tree (make it as balanced as possible) How many possible candidates are for position #2 ?
Background image of page 6
7 Binary Search Consider a Decision Tree How many possible outcomes?
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Selecting k th  smallest item in unsorted array
Background image of page 8
9 Selection in Linear Time In next slides, we describe a recursive call  Select ( S ,k)   which supports finding the  k th  smallest element in  S Recursion is used for  two  purposes:     (1) selecting a  good  pivot (as in Quicksort)     (2) solving a smaller sub-problem
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Select ( S k )       /* First,find a good pivot */ 1. Partition  S  into | S | /5   groups, each group has five  items (one group may  have fewer items); 2. Sort each group separately; 3. Collect median of each group into  S’ ; 4. Find median  m  of  S’ :   m  =  Select ( S’ , | S |/10);
Background image of page 10
11 4.  Let  q  = # items of  S  smaller than  m ;     5.  If ( ==  q + 1 return  m ; /* Partition with pivot */ 6.  Else partition  S  into  and  Y            X  = {items smaller than  m }         Y  = {items larger than  m /* Next,form a sub-problem */ 7.  If ( <  q + 1 )   return  Select ( X k ) 8.  Else   return  Select ( Y k–(q+1) );
Background image of page 11

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

View Full DocumentRight Arrow Icon
Selection in Linear Time Questions:     1.  Why is the previous algorithm correct?   
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/02/2011 for the course CS 7300 taught by Professor R during the Spring '11 term at LSU.

Page1 / 98

7300_04 - CSC7300 AlgorithmsDesignandAnalysis

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

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