If there are n integers to sort, each integer had d digits and each digit is…

2015

If there are n integers to sort, each integer had d digits and each digit is in the set {1,2,…,𝑘}, radix sort can sort the numbers in :

  1. A.

    \(O(d \: n \: k)\)

  2. B.

    \(O(d \ n^k)\)

  3. C.

    \(O(d+n)k)\)

  4. D.

    \(O(d(n+k))\)

Attempted by 129 students.

Show answer & explanation

Correct answer: D

Key idea: Radix sort processes the numbers digit by digit and uses a stable sorting algorithm (commonly counting sort) on each digit.

  1. Number of passes: d (one stable sort per digit).

  2. Cost per pass: counting sort runs in O(n + k) because it counts frequencies over the k possible digit values and then places the n items accordingly.

  3. Total time: Multiply the number of passes by the cost per pass: d × O(n + k) = O(d (n + k)).

  4. Notes: If k = O(n), the complexity becomes O(d n). If d is a constant, the complexity is O(n + k).

Explore the full course: Coding For Placement