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

Design a distributed system that is composed of one client and 5 servers: 1- The

ID: 3813521 • Letter: D

Question

Design a distributed system that is composed of one client and 5 servers:

1- The client application generates an array of size 10000 random double values and has 5 threads each of which sends the whole array to one of the five servers to sort the elements of the array (the sending of the array is done at the same time), the client then waits till all of the servers finish their work.

2- The 5 servers: one sorts the array using bubble sort, the second using merge sort, the third using insertion sort, the forth using Quick sort, and the fifth using selection sort.

3- After all servers finish their jobs, they return back the sorted array and the time needed to sort it. The client displays the names of the sorting algorithms according to the fastest one and the time needed to sort the array.

Explanation / Answer

try this

if you want individually try this code if you want combinedly then combine the pram of all sorts as functions

bubble sort

#include<stdio.h>
void main()
{
   int A[20], N, Temp, i, j;
   clrscr();
   printf(“ ENTER THE NUMBER OF TERMS…: “);
   scanf(“%d”,&N);
   printf(“ ENTER THE ELEMENTS OF THE ARRAY…:”);
   for(i=0; i<N; i++)
   {
       gotoxy(25, 11+i);
       scanf(“ %d”, &A[i]);
   }
   for(i=0; i<N-1; i++)
       for(j=0; j<N-i;j++)
           if(A[j]>A[j+1])
           {
               Temp = A[j];
               A[j] = A[j+1];
               A[j+1] = Temp;
           }
   printf(“ THE ASCENDING ORDER LIST IS…: ”);
   for(i=0; i<N; i++)
       printf(“ %d”,A[i]);
   getch();
}

merge sort

#include<stdio.h>

void getdata(int arr[],int n)
{
int i;
printf("enter the data:");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}

void display(int arr[],int n)
{
int i;
printf(" ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
getchar();
}

void sort(int arr[],int low,int mid,int high)
{
int i,j,k,l,b[20];
l=low;
i=low;
j=mid+1;
while((l<=mid)&&(j<=high))
{
if(arr[l]<=arr[j])
{
b[i]=arr[l];
l++;
}
else
{
b[i]=arr[j];
j++;
}
i++;
}
if(l>mid)
{
for(k=j;k<=high;k++)
{
b[i]=arr[k];
i++;
}
}
else
{
for(k=l;k<=mid;k++)
{
b[i]=arr[k];
i++;
}
}
for(k=low;k<=high;k++)
{
arr[k]=b[k];
}
}

void partition(int arr[],int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
sort(arr,low,mid,high);
}
}


void main()
{
int arr[20];
int n;
printf("Enter number of data:");
scanf("%d",&n);
getdata(arr,n);
partition(arr,0,n-1);
display(arr,n);
getchar();
}

insertion

#include<stdio.h>
void main()
{
   int A[20], N, Temp, i, j;
   clrscr();
   printf(" ENTER THE NUMBER OF TERMS...: ");
   scanf("%d", &N);
   printf(" ENTER THE ELEMENTS OF THE ARRAY...:");
   for(i=0; i<N; i++)
   {
       scanf(" %d", &A[i]);
   }
   for(i=1; i<N; i++)
   {
       Temp = A[i];
       j = i-1;
       while(Temp<A[j] && j>=0)
       {
           A[j+1] = A[j];
           j = j-1;
       }
       A[j+1] = Temp;
   }
   printf(" THE ASCENDING ORDER LIST IS...: ");
   for(i=0; i<N; i++)
       printf(" %d", A[i]);
   getch();
}

/* Quick sort. */

#include <stdio.h>
#include <conio.h>

int split ( int*, int, int ) ;

void main( )
{
   int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1, 90, 3 } ;
   int i ;

   void quicksort ( int *, int, int ) ;

   clrscr( ) ;

   printf ( "Quick sort. " ) ;
   printf ( " Array before sorting: ") ;

   for ( i = 0 ; i <= 9 ; i++ )
       printf ( "%d ", arr[i] ) ;

   quicksort ( arr, 0, 9 ) ;

   printf ( " Array after sorting: ") ;

   for ( i = 0 ; i <= 9 ; i++ )
       printf ( "%d ", arr[i] ) ;

   getch( ) ;
}

void quicksort ( int a[ ], int lower, int upper )
{
   int i ;
   if ( upper > lower )
   {
       i = split ( a, lower, upper ) ;
       quicksort ( a, lower, i - 1 ) ;
       quicksort ( a, i + 1, upper ) ;
   }
}

int split ( int a[ ], int lower, int upper )
{
   int i, p, q, t ;

   p = lower + 1 ;
   q = upper ;
   i = a[lower] ;

   while ( q >= p )
   {
       while ( a[p] < i )
           p++ ;

       while ( a[q] > i )
           q-- ;

       if ( q > p )
       {
           t = a[p] ;
           a[p] = a[q] ;
           a[q] = t ;
       }
   }

   t = a[lower] ;


   a[lower] = a[q] ;

   a[q] = t ;

   return q ;
}

selection

#include <stdio.h>
main()
{
int A[20], N, Temp, i, j;
printf(" ENTER THE NUMBER OF TERMS...: ");
scanf("%d",&N);
printf(" ENTER THE ELEMENTS OF THE ARRAY...:");
for(i=1; i<=N; i++)
{
scanf(" %d", &A[i]);
}
for(i=0; i<N-1; i++)
for(j=i+1; j<N;j++)
if(A[i]>A[j])
{
Temp = A[i];
A[i] = A[j];
A[j] = Temp;
}
printf(" THE ASCENDING ORDER LIST IS...: ");
for(i=0; i<N; i++)
printf(" %d",A[i]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote