Question

A4: Merge Sort - Reverse - Due Jul 30, 2020 11:59 PM Summer II 2020 - Data Structures and Algorithms (COSC-2336-01W) void mer
0 0
Add a comment Improve this question Transcribed image text
Answer #1

We have to change "less(aux[j], aux[i])" to "less(aux[i], aux[j])".

less(aux[j], aux[i]) will return true if aux[j] is less than aux[i], in which case aux[j] will be inserted into the array before aux[i] since it will be in ascending order. Now, if we change it to less(aux[i], aux[j]), it will return true if aux[i] is less than aux[j], or in other words when aux[j] is more than aux[i]. When aux[j] is more aux[i], aux[j] will be inserted into the array. Since the higher values are going into the array before lesser values, it will be in descending order.

Add a comment
Know the answer?
Add Answer to:
A4: Merge Sort - Reverse - Due Jul 30, 2020 11:59 PM Summer II 2020 -...
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] =...

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

  • Practical 5: Write a program that implements several sorting algorithms, and use it to demonstrate the comparative perfo...

    Practical 5: Write a program that implements several sorting algorithms, and use it to demonstrate the comparative performance of the algorithms for a variety of data sets. Need Help With this Sorting Algorithm task for C++ Base Code for sorting.cpp is given. The header file is not included in this. Help would be much appreciated as I have not started on this due to personal reasons #include <cstdlib> #include <iostream> #include <getopt.h> using namespace std; long compares; // for counting...

  • Any help in the compiler error //Driver Program //***************** /** * * CSCI 241 Assignment 8...

    Any help in the compiler error //Driver Program //***************** /** * * CSCI 241 Assignment 8, Part 3 * * Author: your name * z-ID: your z-ID * Date: due date of assignment * * This program builds, sorts and prints lists using the quicksort and * merge sort algorithms. */ #include <iostream> #include <iomanip> #include <vector> #include <string> #include "sorts.h" #include "quicksort.h" #include "mergesort.h" using std::cout; using std::fixed; using std::left; using std::setprecision; using std::string; using std::vector; // Data files...

  • In Python! Search Exercise 11.A: Mergesort with a Comparator CS 1410 Background The sort algorithms we...

    In Python! Search Exercise 11.A: Mergesort with a Comparator CS 1410 Background The sort algorithms we have looked at in Module 8 have all sorted list elements in ascending because it compares elements with the less-than operator. For example, in our mergesort program, the comparison appears as follows: 18 L[1] R01 The effect of this comparison is that if L(i) is less than RC), then L[is considered to come before R[i] in the sorted result. Hence the ascending order of...

  • In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the...

    In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the following sort member function on a singly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); Implement the following sort member function on a doubly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); The sort(…) methods take as a parameter a comparator function, having a default assignment of defaultCompare, a static function defined as follows: template <typename T> static bool defaultCompare(const...

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