Time & Space Complexity - Counting Sort

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Algorithm

Counting Sort, known also as Histogram Sort


n = length of input Array
k = number of unique symbols that appear in the input
Array

Initialization takes k time


down vote

Counting takes n time


Enumeration takes Sum { Count(i) } = n time
Complexity
Time = k + n + n = 2n+k
Time ~ O(2n+k) = O(n+k)
Space = n + k ~ O(n+k)

You might also like