0% found this document useful (0 votes)
54 views

373 Lecture 5

The document discusses different sorting algorithms and their time complexities. It introduces bucket sort, which can sort in linear time for uniformly distributed inputs by placing elements in buckets rather than comparing elements. It also discusses selection algorithms like RandomizedSelect that can find the median or other ordered statistics in expected linear time.

Uploaded by

api-3696125
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

373 Lecture 5

The document discusses different sorting algorithms and their time complexities. It introduces bucket sort, which can sort in linear time for uniformly distributed inputs by placing elements in buckets rather than comparing elements. It also discusses selection algorithms like RandomizedSelect that can find the median or other ordered statistics in expected linear time.

Uploaded by

api-3696125
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like