Part 1: Extend your sorting framework with two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (Merge Sort OR Quick Sort). If you choose Shell Sort, experiment with different incremental sequences to see how they affect the algorithm's run time efficiency (count the number of comparisons and exchanges). If you choose to implement Radix Sort, answer the following question as well: Can you write a version of Radix Sort to work with real numbers? If yes, show me how. If not, explain why. Compare the advanced sorting methods that you have implemented to elementary sorts from homework 1. Explain the results generated by your program (do not forget to experiment with best / worst / avarage cases, if applicable). Part 2: Design a recursive method for finding the largest element in an array A of N elements. Characterize its run-time efficiency.You don't have to implement it.
Question No 1:
Part 1: Extend your sorting framework with two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (Merge Sort OR Quick Sort).
If you choose Shell Sort, experiment with different incremental sequences to see how they affect the algorithm's run time efficiency (count the number of comparisons and exchanges).
If you choose to implement Radix Sort, answer the following question as well: Can you write a version of Radix Sort to work with real numbers? If yes, show me how. If not, explain why.
Compare the advanced sorting methods that you have implemented to elementary sorts from homework 1.
Explain the results generated by your program (do not forget to experiment with best / worst / avarage cases, if applicable).
Part 2: Design a recursive method for finding the largest element in an array A of N elements. Characterize its run-time efficiency. You don't have to implement it.
Part1.
Shell sort is like insertion sort. In shell sort we check distant members of our array not adjacent. We sort to elements in such a way that we think that other elements doesn’t exists. We make partition and gaps and in different phases we reduces these gaps.
If we have an array of 10 integers
e.g 25, 24,21,210,19,15,12,10,9,7
We will sort in such a way that first the turn will be of 25 and its adjacent 19 and its adjacent 9
Now 9 will be compared with the selected ones and it will be sorted. Then it will check the rest if they have to be sorted they will be sorted.
Now we will decrease the gap and will work on the rest.
The worst case will be O(n) and the best case will be O(1).
Quick Sort:
#include<iostream>
usingnamespace std;
int partition(int *arr, intstart, intend)
{
intcurr;
int next;
inti;
int temp;
curr = start;
next = end + 1;
i = arr[start];
while (next >= curr)
{
while (arr[++curr]<i);
while (arr[--next]>i);
if (next>curr) // sorting ascending order
{
temp = arr[curr]; // storing current index in a temp variable
arr[curr] = arr[next]; //replacing current with the next
arr[next] = temp; // replace value of next with current
}
}
temp = arr[start]; // storing prev value into temp
arr[start] = arr[next]; // storing next value into prev
arr[next] = temp; // replacing next with prev
return next;
}
intquickSort(int *arr, intstart, intend)
{
inti; // i is partitioning index
if (end>start)
{
i = partition(arr, start, end);
quickSort(arr, start, i - 1);
quickSort(arr, i + 1, end);
}
// now arr[i] is sorted
return 0;
}
int main()
{
int size;
int *arr;
cout<<"Enter size: ";
cin>> size;
arr = newint[size];
cout<<"Enter elements to insert"<<endl;
for (inti = 0; i<size; i++)
{
cin>>arr[i];
}
quickSort(arr, 0, size -1);
cout<<"SORTED"<<endl;
for (inti = 0; i<size; i++)
{
cout<<arr[i] <<" ";
}
return 0;
}
PART 2:
LARGEST NUM
#include<iostream>
usingnamespace std;
#include<cmath>
staticint max = INT_MIN; // intializing max with the possible minimum number
int Largest(int *arr,intn, intcap)
{
staticinti = 0; // static will help us to not lose the value when recursion is called.
if (i<cap)
{
if (max <arr[i]) // if any value in the array is greater than current value of max
{
max = arr[i];
}
i++;
Largest(arr,n,cap); // recursive call for the next iteration
}
return max;
}
void menu() {
cout<<endl<<endl;
cout<<"1. Press 1 to INSERT"<<endl;
cout<<"2. Press 2 to DISPLAY"<<endl;
cout<<"3. Press 3 to find MAX"<<endl;
cout<<"4. Exit"<<endl<<endl;
}
int main()
{
int *arr; // delcaring an interger type array
int size;
int capacity=0; // capacity of an array
int choice;
cout<<"Enter size of array: ";
cin>> size;
arr = newint[size]; // dynamic array created
while (1) {
menu(); //menu
cout<<"Enter choice: ";
cin>> choice;
if (choice == 1) {
cout<<"Cuurent space left: "<< size - capacity <<endl;
if (capacity < size) { // if capacity is lesser than size
cout<<"Enter elements: ";
cin>>arr[capacity]; // inputing in array
capacity++;
}
}
elseif (choice == 2) {
for (inti = 0; i< capacity; i++) {
cout<<arr[i] <<endl;
}
}
elseif (choice == 3) {
cout<<"MAX: "<< Largest(arr, size,capacity)<<endl;
system("pause");
}
elseif (choice == 4) {
return 0;
}
else {
cout<<"INVALID CHOICE"<<endl;
}
// system("cls");
}
return 0;
}
The run efficiency is poor because we use recursion to make our program become short not to improve efficiency. The time complexity will remain same for the worst case O(1). But this recursive function isn’t efficient as compare to a loop.
COMMENT DOWN FOR ANY QUERIES AND,
LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.
Part 1: Extend your sorting framework with two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (...
Your mean employer has five sorting programs. But they are labeled by their descriptions - no names. Read each label then say which of the following it is: Heap Sort Insertion Sort Merge Sort Quick Sort Radix Sort Selection Sort 1) “I always use theta(n^2) comparisons no matter what kind of list I am sorting. I am ashamed.” *Answer: This is 2) "I am a good choice if you want to quickly sort a large number of K digit numeric...
please answer all parts and code thanks
. - PART 1-Introduction to Sorting, 21 points Use this array of integer for the problems 1A, 1B, and 1c: 9 57 8324761 Each of these problems is worth 3 points A. Show the contents of the array each time a selection sort changes it while sorting the array into B. Show the contents of the array each time an insertion sort changes it while sorting C. Show the contents of the array...
A test harness program for testing sorting methods is provided with the rest of the textbook program files. It is the file Sorts.java in the ch11 package. The program includes a swap method that is used by all the sorting methods to swap array elements. Describe an approach to modifying the program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method. Implement your approach. Test your new program by...
SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what choices does one make when creating a class that is an example of Abstraction? Encapsulation: What is encapsulation? What is information hiding? What does a public interface to a class consist of (not in the sense of actual java interfaces but what the client uses to manipulate objects of the class) What is an object of a class? What is the constructor? How do...
Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...