Question

. Shell sort is a sorting algorithm similar to insertion sort. Research shell sort and apply...

. Shell sort is a sorting algorithm similar to insertion sort. Research shell sort and apply that to the following array. Show your work in Detail. [15 points]

45 20 50 10 80 30 60 70 40 90

2. Is Shell sort a stable sorting algorithm? Answer this with an example. [10 points]
3. Apply Merge Sort to sort the following list. Show your work in Detail. [15 Points]

45 20 50 10 80 30 60 70 40 90

4. Is merge sort a stable sorting algorithm? Answer this with an example. [10 points]
5. Apply Quick sort to sort the following list. Show your work in Detail [15 Points]

45 20 50 10 80 30 60 70 40 90

6. Is Quick sort a stable sorting algorithm? Answer this with an example. [10 points]
7. This question involves comparing the sorting algorithms that we studied so far such as selection sort, bubble sort, insertion sort, merge sort & quicksort. First briefly explain the idea behind each of them. And then compare them according to the criterion such as time(best, worst and average case) and space efficiency, stability, applicability (when performs best) etc. You may use following links as hints, however you will be able to find a significant number of links that compare sorting algorithms. Make sure that you check the validity of any information found in any website before using them and if used acknowledge the references properly. [25 points]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

(1)Shellsort

#include<stdio.h>

Void shellsort(int a[], int num)

{

int i ,j , k, temp;

for(i=num/2; i>0; i=i/2)

{

for(j=i; j<num; j++)

{

for(k=j-i; k>=0; k=k-i)

{

if(a[k+i] >=a[k])

break;

else

{

temp=a[k];

a[k] =a[k+i];

a[k+i] = temp;

}

}

}

}

}

int main()

{

int a[30];

int k, num;

printf(“Enter total no. of elements :”);

scanf(“%d”, &num);

printf(“\n Enter %d elements:”, num);

for(k=0; k<num; k++)

{

scanf(“%d”, &a[k]);

}

shellsort(a, num);

printf(“\n Sorted array is:”);

for(k=0; k<num; k++)

printf(“%d”, a[k]);

return 0;

}

OUTPUT:

(3)Merge sort

#include<stdio.h>

void mergesort(int a[], int i, int j);

void merge(int a[], int i1, int j1, int i2, int j2);

int main()

{

int a[30], n, i;

printf(“enter no. of elements:”);

scanf(“%d, &n);

printf(“enter array elements:”);

for(i=0; i<n; i++)

scanf(“%d”, &a[i]);

mergesort(a,0,n-1);

printf(“\n Sorted array is:”);

for(i=0; i<n; i++)

printf(“%d”, a[i]);

return 0;

}

void mergesort(int a[], int i, int j)

{

int mid;

if(i<j)

{

mid=(i+j)/2;

mergesort(a, i, mid);

mergesort(a, mid+1, j);

mergesort(a, i, mid, mid+1, j);

}

}

void merge(int a[], int i1, int j1, int i2, int j2)

{

int temp[50];

int i, j, k;

i=i1;

j=i2;

k=0;

while(i<=j1 && j<=j2)

{

if(a[i]<a[j])

temp[k++]=a[i++];

else

temp[k++]=a[j++];

}

while(i<=j1)

temp[k++]=a[i++];

while(j<=j2)

temp[k++]=a[j++];

for(i=i1, j=0; i<=j2; i++,j++)

a[i]=temp[j];

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
. Shell sort is a sorting algorithm similar to insertion sort. Research shell sort and apply...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT