Apply mergesort algorithm to sort S, O, R, T, I, N, G in alphabetical order.
Note: For any doubts please put a comment before giving a thumbs down.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h> //To use the string functions like strcmp and strcpy
#define MAX 10
// This is the default size of every string
void Merge(char* arr[],int low,int mid,int high) //Merging the Array Function
{
int nL= mid-low+1;
int nR= high-mid;
char** L=malloc(sizeof(char *)*nL);
char** R=malloc(sizeof(char *)*nR);
int i;
for(i=0;i<nL;i++)
{
L[i]=malloc(sizeof(arr[low+i]));
strcpy(L[i],arr[low+i]);
}
for(i=0;i<nR;i++)
{
R[i]=malloc(sizeof(arr[mid+i+1]));
strcpy(R[i],arr[mid+i+1]);
}
int j=0,k;
i=0;
k=low;
while(i<nL&&j<nR)
{
if(strcmp(L[i],R[j])<0)strcpy(arr[k++],L[i++]);
else strcpy(arr[k++],R[j++]);
}
while(i<nL)strcpy(arr[k++],L[i++]);
while(j<nR)strcpy(arr[k++],R[j++]);
}
void MergeSort(char* arr[],int low,int high) //Main MergeSort function
{
if(low<high)
{
int mid=(low+high)/2;
MergeSort(arr,low,mid);
MergeSort(arr,mid+1,high);
Merge(arr,low,mid,high);
}
}
int main()
{
printf("\nEnter the size of the array desired: ");
int size; //This is the String array size
scanf("%d",&size);
char** arr= malloc(sizeof(char *)* size); //Creating required string array
printf("\nEnter the strings of the array: ");
*arr = "SORTING";
int i;
MergeSort(arr,0,size-1);
printf("\nThe Sorted Array is: ");
for(i=0;i<size;i++)printf("%s ->",arr[i]);
return 0;
}
Apply mergesort algorithm to sort S, O, R, T, I, N, G in alphabetical order.
Show that the time complexity for the number of assignments of records for the Mergesort algorithm (Algorithms 2.2 and 2.4) is approximated by T (n) = 2nlgn. by Mingfu LI, CGUEE Algorithms Algorithms 2.2 : Mergesort O Problem Sort n keys in nondecreasing sequence. Inputs positive integer n, array of keys S index from 1 to n Output the array 5 containing the keys in nondecreasing sequence. void mergesort (int n, keytype S[]) (1 <u)и } keytype UI..h), ИI.m); copy...
1. Show the steps in order to sort {11,5,6,3,8,1,9,2} using Mergesort algorithm. 2. Show the element sequences of running Shellsort on the input {15,2,8,1,10,7,4,3,9,11,12,6} at the increments {7, 3, 1}, respectively. 3. Show the steps in details of sorting {15, 2, 8, 1, 10, 7, 4, 3, 9, 11, 12, 6} using quicksort with median-of-three partitioning and a cutoff 3 (if the elements are less than 3, using insertion sort).
Show that the time complexity for the number of assignments of records for the Mergesort algorithm (Algorithms 2.2 and 2.4) is approximated by T (n) = 2nlgn. by Mingfu LI, CGUEE Algorithms Algorithms 2.2 : Mergesort O Problem Sort n keys in nondecreasing sequence. Inputs positive integer n, array of keys S index from 1 to n Output the array 5 containing the keys in nondecreasing sequence. void mergesort (int n, keytype S[]) (1 <u)и } keytype UI..h), ИI.m); copy...
In C++: 1. What is the difference between a deterministic algorithm and a randomized algorithm? 2. What is the difference between a Las Vegas algorithm (pattern) and a Monte Carlo algorithm? 3. Solve the following recurrences, giving the answer in terms of Big-Oh O() F (n) = 4F ( 1 ) +no F (n) = 2 F (*) +2 4. Given the string "DECEMBER", execute the mergesort algorithm by hand to sort it. Show your work to make it clear...
No program needed. Sort the sequence M, I, D, T, E, R, M, E, X, A, M using the following sort methods. Show the trace after each iteration of the outer loop. a. Insertion sort b. Top-Down Mergesort
In Java, Bucket sort is a sorting algorithm that has O(n) performance on average. I want you to write a function to perform bucket sort on a list of strings. I also want you to test your function to see if it really work in linear time on average. This code will need to be tested. Finally, I want you to compare the performance of your function with Javasort method for lists.
Q3) Apply Quick sort algorithm to sort the following Array (Show complete steps, and show the values of p,r and q) 7 13 5 2 4 10 15 6 3 6
> Question 54 2.67 pts Merge sort is aln)_ algorithm. Tim Atter 38 N Ollogn) O(n log(n)) 24/7 O(n) O(n)
Apply the topological sort algorithm to the graph. Follow the algorithm in you textbook and clearly show the content of the three lists: resultList, noIncoming and remainingEdges after each iteration. 2. Apply the topological sort algorithm to the graph below. Follow the algorithm in you textbook and clearly show the content of the three lists: resultList, nolncoming and remainingEdges after each iteration GraphTopologicalSort (graph) { resultList = empty list of vertices no Incoming = list of all vertices with no...
2. Consider your ID as an array of 9 elements, apply an insertion sort algorithm to sort the numbers in descending order. Show your steps. Example ID: 201710340 Array: 2 0 7 0 1 1 0 3 4