2. The mergesort is a recursive sort. What is the base case for the merge sort?
A.There is none.
B. When right = left -1
C. When start = end
D. When end - start = 1
3. Given the array [ 23, 83, 82, 92, 28, 21, 91, 17, 54, 32, 41, 14], what is the value of mid for the call mergesort (elements, 0, 5, temp) ?
A. The value of mid is 3
B. The value of mid is 28
C. The value of mid is 2.
D. The value of mid is 82.
4. Given the call: mergesort (elements, 5, 9, temp) where the array elements contains the following values [38, 43, 34, 52, 88, 79, 87, 70, 95, 82}]. What are the values for start and end for the first recursive call in this mergesort?
A. start = 5 and end = 8
B. start = 5 and end = 7
C. start = 6 and end = 9
D. start = 8 and end = 9
5. What is the time needed for a merge sort in terms of Big-O in the best case? In the worst case?
A. Best case: O(n log n)
Worst case: O(n log n)
B. Best case: O( n2)
Worst case: O( n2)
C. Best case: O( log n)
Worst case: O(n log n)
D. Best case: O(n log n)
Worst case: O( n2)
2) start=end
3) The value of mid is 2
4)start=5 ,end=7
5) Best case : O(n logn) , Worst case: O(n logn)
2. The mergesort is a recursive sort. What is the base case for the merge sort?...
In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 processes. First half of the array will be sorted by thread 1 and the second half by thread 2. When the threads complete their tasks, the main program will merge the half arrays. You should not waste your time on merge-sort algorithm. Use the merge sort algorithm given below void mergesort(int a[],int i,int j) { int mid; if(i<j) { mid=(i+j)/2; mergesort(a,i,mid); //left recursion mergesort(a,mid+1,j); //right...
6
6. Merge Bubble Sort: a) How does the merge bubble sort break the array into sublists? b) What does it need to use for each sublist and then what does it do with all of the sublists? c) What is the Big-O notation for this sort? 7. Merge Sort: a) How does the merge sort use recursion to break the array into sublists? b) What happens to each of these sublists to get the final sorted list? c) What...
Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case time and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of...
In this assignment, you sort a list of strings using mergesort and the compareToIgnoreCase method of the String class. The strings are provided as arguments to your main method. In case you haven't yet learned to configure command-line arguments to main in your IDE, now is a good time to learn. Your program should sort the array of strings using mergesort, then print the strings one per line, in order from smallest ("a") to largest ("z"). The name of your...
HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge sort (on arrays). Create a public non-final class named Mergesort that extends Merge. Implement a public static method int[] mergesort(int[] values) that returns the input array of ints sorted in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. If the passed array is null you should return null. If the...
use the same code. but the code needs some modifications. so
use this same code and modify it and provide a output
Java Program to Implement Merge Sort import java.util.Scanner Class MergeSort public class MergeSort Merge Sort function / public static yoid sortfintfl a, int low, int high) int N-high-low; if (N1) return; int mid- low +N/2; Il recursively sort sort(a, low, mid); sort(a, mid, high); I/ merge two sorted subarrays int] temp new int[N]; int i- low, j-mid; for...
Given an array with n elements, after doing merge sort on the array, what is the time taken to conduct the merge sort (Choose one answer)? O(n) O ( n *n ) O(n log n)
Implement merge sort and merge
#include <iostream>
using namespace std;
void * merge(int arr[], int start1, int end1, int start2, int
end2){
int * combined = new int[end2-start1 + 1];
}
void mergeSort(int arr[], int start, int end){
//base case: down to 1 item, do nothing
//recursive case:
//MergeSort(left)
//MergeSort(right)
//Merge(left, right)
int m = (end - start) / 2;
if(start==end){ }
else {
mergeSort(arr, start, m);
mergeSort(arr, m+1, end);
merge(arr, start, m, m+1, end);
}
}
void fill(int arr[],...
2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Gi pseudocode for an algorithm that will solve the following...
When sorting n records, Merge sort has worst-case running time a. O(n log n) b. O(n) c. O(log n) d. O(n^2)