Question

2. What is the issue with the following section of merge sort code? 1: void merges(int st, int en, int * x) { 2: int mid = (s
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given section of mergeSort code,will fall in infinite Loop.
Because it keeps on calling mergeS() function before checking condition
if(st==en) return;

Therefore this code keeps on calling mergeS() function until stack overflows.

Add a comment
Know the answer?
Add Answer to:
2. What is the issue with the following section of merge sort code? 1: void merges(int...
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
  • A4: Merge Sort - Reverse Hide Assignment Information Instructions void merge (int a[], int aux[], int...

    A4: Merge Sort - Reverse Hide Assignment Information Instructions void merge (int a[], int aux[], int lo, int mid, int hi) for (int k = lo; k <= hi; k++) aux[k] = a[k]; int i = lo, j = mid+1; for (int k = lo; k <= hi; k++) { if (i > mid) a[k] = aux [j++); else if (j > hi) a[k] = aux[i++]; else if (less (aux()], aux[i])) a[k] = aux [j++]; else a[k] = aux[i++]; The...

  • A4: Merge Sort - Reverse Hide Assignment Information Instructions void merge (int al], int aux[], int...

    A4: Merge Sort - Reverse Hide Assignment Information Instructions void merge (int al], int aux[], int lo, int mid, int hi) { for (int k = lo; k <= hi; k++) aux [k] = a[k]; int i = lo, j = mid+1; for (int k = lo; k <= hi; k++) if (i > mid) a[k] = aux [j++]; else if (i > hi) a[k] = aux[i++) ; else if (less (aux(j), aux[i])) a[k] = aux [j++); else a[k] =...

  • In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 pro...

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

  • 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];         ...

    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[],...

  • How would I be able to get a Merge Sort to run in this code? MY...

    How would I be able to get a Merge Sort to run in this code? MY CODE: #include <iostream> #include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h> using namespace std; class mergersorter { private:    float array[1000] ;    int n = 1000;    int i=0; public:    void fillArray()    {        for(i=1;i<=n;i++)        {            array[i-1]= ( rand() % ( 1000) )+1;        }    }    void arrayout ()    {   ...

  • 4. (5 Points) The following is another merge sort top down implementation, what is the running...

    4. (5 Points) The following is another merge sort top down implementation, what is the running time and space complexity for this implementation in big-0? Briefly explain your answer. public static 〈T extends Comparable〈 T> > void sort2(T[] a) { sort2(a, , a.length - 1); @Suppresswarnings ("unchecked") private static <T extends Comparable<T>> void sort2(ΤΠ a, intlo, int hi) { if (hi (z lo) return; T[] aux- (TLD new comparable[a,length]; int mid- (10 + hi) / 2; sort2 (a, lo, mid);...

  • must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int...

    must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...

  • use the same code. but the code needs some modifications. so use this same code and...

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

  • USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list...

    USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list and use a Merge Sort to sort the object by age. Create a class called Person : name and age Create methods that add, and delete Person from the link list Create a method that sorts the persons' objects by age. package mergesort; public class MergeSortExample { private static Comparable[] aux; // auxiliary array for merges public static void sort(Comparable[] a) { aux =...

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

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