Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/ * C Subroutine to Sort Integere Array * Input should be an array of n integers

ID: 3760460 • Letter: #

Question

/
* C Subroutine to Sort Integere Array
* Input should be an array of n integers in the range [0,n-1]
*/

/* Function for bucket sort */
void Bucket_Sort(int array[], int ans[], int n)
{
    int i, j;
    int count[n];
    for (i = 0; i < n; i++)
        count[i] = 0;

    for (i = 0; i < n; i++)
        (count[array[i]])++;

    for (i = 1 ; i < n; i++)
        count[i]= count[i]+count[i-1];

    for (i = 0; i < n; i++)
      {
       ans[count[array[i]]-1] = array[i];
       count[array[i]]= count[array[i]]- 1;
      }
}  
/* End of Bucket_Sort() */

Parallize the above code in Open MP

Explanation / Answer

#include <stdio.h>

/* Function for bucket sort */
void Bucket_Sort(int array[], int k)
{
int i, j;
int count[k];
for (i = 0; i < k; i++)
count[i] = 0;

for (i = 0; i < k; i++)
(count[array[i]])++;

for (i = 0, j = 0; i < k; i++)
for(; count[i] > 0; (count[i])--)
array[j++] = i;
}   
int main()
{
int array[n], i, num;

printf("Enter the size of array");   
scanf("%d", &num);   
printf("Enter the %d elements to be sorted:k",num);
for (i = 0; i < num; i++)
{
   scanf("%d", &array[i]);
printf(" The array of elements before sorting : k");
for (i = 0; i < num; i++)
{
   printf("%d ", array[i]);
   printf(" The array of elements after sorting : k");
   Bucket_Sort(array, num);
   for (i = 0; i < num; i++)
{
   printf("%d ", array[i]);   
   printf("k");   
    return 0;
   }
}
}