Sunteți pe pagina 1din 12

CSC 373

Lecture 5
By
Javed Siddique
Sorting
• Can sorting be done in linear time?
• So far the algorithms we have seen sorts by
comparing items.
• It is called sorting by comparison.
• We will show that sorting by comparison
can be done in
• So the lower bound of sorting is
Decision Tree
Sorting in Linear Time
• Sorting in linear time is possible.
• But these algorithm does not work by
comparison.
Bucket Sort
• Runs in linear time when input is drawn
from a uniform distribution.
• Bucket sort assumes that we have an array
of n elements and 0<= A[i] < 1.
• The code requires B[0..n-1] linked lists.
Bucket Sort Algorithm
Example
Runtime Analysis
Median and Ordered Statistics
• The ith order statistic of a set of n elements
is the ith smallest element.
• Median is a halfway point.
Selection in Expected Linear Time

• The algorithm is known as


RandomizedSelect.
• It runs in expected Theta(n).
Randomized Select

S-ar putea să vă placă și