📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Counting Sort is an efficient sorting algorithm when the

    range of input elements (k) is not significantly larger than the number of elements (n). What is its time complexity?
    A O(N log N) Correct Answer Incorrect Answer
    B O(N^2) Correct Answer Incorrect Answer
    C O(N + K) Correct Answer Incorrect Answer
    D O(K log N) Correct Answer Incorrect Answer
    E O(N K) Correct Answer Incorrect Answer

    Solution

    Counting Sort works by counting the frequency of each distinct element in the input array. It then uses this count information to place elements in their correct sorted positions. The time complexity involves iterating through the input array (O(N)) and iterating through the count array (which depends on the range K), making its overall time complexity O(N + K).

    Practice Next
    More Algorithms Questions
    ask-question