45 20 50 10 80 30 60 70 40 90
45 20 50 10 80 30 60 70 40 90
45 20 50 10 80 30 60 70 40 90
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:
. Shell sort is a sorting algorithm similar to insertion sort. Research shell sort and apply...
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 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...
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 • 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 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 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. Verify the correctness of each implemented algorithm by sorting the following array: 10, 5, 60, 53, 45, 3, 25,37,39,48
Is quick sort a stable or unstable sorting algorithm. Explain with an example.
pls answer explaining all steps shull gay a) Which sorting algorithm behaves as insertion sort in one of its iteration. Explain it with an example (4) ) Lot fin) - 3n+8 and g(n) = n. Claim: f(n) = O(g(n)). Check whether selection sort is stable or not loso egin
8 Sorting Algorithms: Bubble, selection, insertion, quick, merge, bucket, radix, counting. 1. A..Which of the above sorting algorithms does TimSort use? 2. Which of the above algorithms sort a REVERSE ORDER list in O(n2 ) (worst case)? 3. Which of the above algorithms sort a REVERSE ORDER list in O(nlogn) (worst case)? 4. Which of the above algorithms sort an ordered list , a reverse ordered list, and a random list (all three) in 0(nlogn) (worst case)? 5. Which of...