Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

CSCI3320/8325: Data Structures 1

CSCI3320/8325: Data Structures 2


Fill up the target array B
reversely: put i into the C(i)th
position, decrease C(i) by 1

CSCI3320/8325: Data Structures 3


Note that Counting sort beats the
lower bound of Ω(n lg n), because
it is not a comparison sort and
requires special assumptions.

There is no comparison between


elements. Counting sort uses the
actual values of the elements
to index into an array.

CSCI3320/8325: Data Structures 4


CSCI3320/8325: Data Structures 5
CSCI3320/8325: Data Structures 6
CSCI3320/8325: Data Structures 7
CSCI3320/8325: Data Structures 8
CSCI3320/8325: Data Structures 9
Method Time_ave Time_worst Time_best Space Stable?
Insertion O(N^2) O(N^2) O(N) O(1) Y
Shell O(N^1.3) O(N^2) O(N) O(1) N
Selection O(N^2) O(N^2) O(N^2) O(1) N
Bubble O(N^2) O(N^2) O(N) O(1) Y
Merge O(NlogN) O(NlogN) O(NlogN) O(N) Y
Quick O(NlogN) O(N^2) O(NlogN) O(logN) ~ O(N) N
Heap O(NlogN) O(NlogN) O(NlogN) O(1) N
Counting O(N+k) O(N+k) O(N+k) O(N+k) Y
Radix O(N+k) O(N+k) O(N+k) O(N+k) Y
Bucket O(N+k) O(N^2) O(N) O(N+k) Y

CSCI3320/8325: Data Structures 10


Bubble
Counting Swap
Radix Quick
Non-Compare
Bucket Insertion
Insert
Shell
Sorting
Compare
Algorithms
Selection
Select
Heap

External
Merge
Outside Computer Memory Merge
Such as merging sorted list from multiple tapes or disk divisions
K-way
Merge

Happy Sorting!
CSCI3320/8325: Data Structures 11

You might also like