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
  • Sorting: (40 points) a. We studied several sorting algorithms. Every sorting algorithm has their own special...

    Sorting: (40 points) a. We studied several sorting algorithms. Every sorting algorithm has their own special reason where it can only use. Can you explain carefully in which situation the following algorithms would be best sorting algorithm to use in an application. (10 points) i. Insertion sort ii. Selection sort iii. Merge sort iv. Quick sort b. You are given a string of elements as below, Canopus, Mimosa, Betelgeuse, Deneb, Stars, Pollux, Antares, Sirius, Hader i. Your task is to...

  • 1. Which is the best sorting algorithm for larger arrays if all the items can not...

    1. Which is the best sorting algorithm for larger arrays if all the items can not fit in main memory? selection sort insertion sort quicksort Merge sort 2. Which sorting algorithm sorts items without comparing them? quick sort radix sort merge sort Insertion sort 3 What is the average running time for quicksort? O(n2) O(logn) O(nlogn) O(n) O(n2logn) 4. Examine the steps of the following algorithm and write the name of the algorithm described in the blank provided: Recursively divide...

  • c++ Implement Radix Sort Most sorting algorithms, like bubble, insertion, selection and shell follow similar implementations....

    c++ Implement Radix Sort Most sorting algorithms, like bubble, insertion, selection and shell follow similar implementations. Radix sort is a unique sorting algorithm. In this assignment, implement the Radix Sort algorithm, as explained the text book in chapter 2. Use the Numbers.txt file in the DataFiles folder for the numbers to sort. Extra credit is available for processing alphabetic strings instead of just numbers. Specification: * Using your Doubly-Linked list to create an dynamic array of Doubly-Linked lists (like lab1)....

  • a. We studied several sorting algorithms. Every sorting algorithm has their own special reason where it...

    a. We studied several sorting algorithms. Every sorting algorithm has their own special reason where it can only use. Can you explain carefully in which situation the following algorithms would be best sorting algorithm to use in an application. (10 points) i. Insertion sort ii. Selection sort iii. Merge sort iv. Quick sort b. You are given a string of elements as below, Canopus, Mimosa, Betelgeuse, Deneb, Stars, Pollux, Antares, Sirius, Hader i. Your task is to insert the above...

  • C++ Programing Consider the following sorting techniques: • Bubble Sort • Insertion Sort • Selection Sort...

    C++ Programing Consider the following sorting techniques: • Bubble Sort • Insertion Sort • Selection Sort • Merge Sort • Quick Sort Select any two of the above sorting techniques: 1. Write an algorithm (pseudocode) for the two selected sorting techniques 2. Write two separate C++ programs using user defined functions for each of the selected sorting techniques.

  • Please come up with an array of 9 random integers then sort the array. Show the...

    Please come up with an array of 9 random integers then sort the array. Show the contents of the array each time a sorting algorithm changes it while sorting the array into ascending order. The 6 sorting algorithm we are using are: 1. Selection Sort 3 points 2. Insertion Sort 3 points 3. Shell Sort 6 points 4. Bubble Sort 3 points 5. Merge Sort 10 points 6. Quick Sort 10 points It is OK to do this assignment on...

  • Shell sort works by Group of answer choices using insertion sort on subarrays of equally spaced...

    Shell sort works by Group of answer choices using insertion sort on subarrays of equally spaced entries using insertion sort on subarrays of equal size consecutive entries iteratively searching for the smallest entry in subarrays of equally spaced entries iteratively searching for the smallest entry in subarrays of equal size consecutive entries Chapter 15:  Shell sort can be improved by Group of answer choices you cannot improve the algorithm’s time efficiency using selection sort instead of insertion sort as the final...

  • Implement the following sorting algorithms using Java: a. Heap Sort. b. Quick Sort. c. Radix Sort....

    Implement the following sorting algorithms using Java: a. Heap Sort. b. Quick Sort. c. Radix Sort. Verify the correctness of each implemented algorithm by sorting the following array: 10, 5, 60, 53, 45, 3, 25,37,39,48

  • This question involves comparing the sorting algorithms that we studied so far such as selection sort,...

    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...

  • Is quick sort a stable or unstable sorting algorithm. Explain with an example.

    Is quick sort a stable or unstable sorting algorithm. Explain with an example.

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