

























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























































- (^) QuickSort is a simple and efficient approach
to sorting:
and divide the array into two subarrays:
c small
c large
them together in sorted array c sorted
Given an array: c = { 5, 2, 8, 4, 3, 1, 7, 6, 9 }
Step 1: Choose the first element as m
c = { 6 , 3, 2, 8, 4, 5, 1, 7, 0, 9 }
Our Selection
Step 3: Recursively do the same thing to
c small
and c large
until each subarray has
only one element or is empty.
C small
= { 3 , 2, 4, 5, 1, 0
}
C large
= { 8 , 7,
9 }
m =
3
m =
{ 2 , 1, 0 } < { 4 , 5 }^8 { 7 } < { 9 }
m =
2
{ 1 , 0 } < { empty} { empty } < { 5 }
m =
4
m =
1
{ 0 } < { empty }
Step 4: Combine the two arrays with m working
back out of the recursion and as we build
together the sorted array.
C small
= { 0, 1, 2, 3, 4, 5
}
C large
= { 7, 8, 9 }
{ 0, 1, 2 } 3 { 4, 5 }
{ 7 } 8 { 9 }
{ 0, 1 } 2 { empty }
{ empty } 4 { 5 }
{ 0 } 1 { empty }
QuickSort(c)
if c consists of a single element
return c
4. m ß c 1
Determine the set of elements c small
smaller than m
Determine the set of elements c large
larger than m
QuickSort(c small
)
QuickSort(c large
)
Combine c small
, m , and c large
into a single array, c sorted
return c sorted
-A good selection will split c evenly such that
| c small
| = | c large
|, then the runtime is O( n log
n ).
-For a good selection, the recurrence relation is:
T ( n ) = 2T ( n /2) + const · n
Time it takes to split the
array into 2 parts where
const is a positive constant
The time it takes to
sort two smaller
arrays of size n /
good ‘splitter.’
time, we don’t need a perfect split, just reasonably
good one. In fact, if both subarrays are at least of
size n/4 , then running time will be O( n log n ).
splitters.
splitters, if we choose m at random we will
get a 50% chance that m will be a good
choice.
what input is received, the expected running
time is small.
- (^) Expected runtime : O( m log m ).
performance of randomized algorithms, often
more informative than worst case runtimes.
correct answer, which offers a way to classify
Randomized Algorithms.
- (^) Las Vegas Algorithms – always produce the
correct solution (ie. RandomizedQuickSort)
- (^) Monte Carlo Algorithms – do not always
return the correct solution.
but they are often hard to come by.
- Motif Finding Problem : Given a list of t
sequences each of length n , find the “best”
pattern of length l that appears in each of the
t sequences.
- Previously: we solved the Motif Finding
Problem using a Branch and Bound or a
Greedy technique.
- Now : randomly select possible locations and
find a way to greedily change those locations
until we have converged to the hidden motif.
,..., s t
) be the set of starting
positions for l- mers in our t sequences.
starting positions will form:
*We make a special note that the profile matrix will be defined in terms of the
frequency of letters, and not as the count of letters.