Design an efficient sorting algorithm for an array of n integers where for each element is in the range of 0
Answers
Answered by
0
Answer:
Sort n numbers in range from 0 to n^2 – 1 in linear time
Given an array of numbers of size n. It is also given that the array elements are in range from 0 to n2 – 1. Sort the given array in linear time.
Examples:
Since there are 5 elements, the elements can be from 0 to 24.
Input: arr[] = {0, 23, 14, 12, 9}
Output: arr[] = {0, 9, 12, 14, 23}
Since there are 3 elements, the elements can be from 0 to 8.
Input: arr[] = {7, 0, 2}
Output: arr[] = {0, 2, 7}
Similar questions
Biology,
6 months ago
Chemistry,
6 months ago
Computer Science,
6 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago