Question

In: Computer Science

You are working as the software developer and need to identify the best sorting algorithm. You...

You are working as the software developer and need to identify the best sorting algorithm.

You can pick any two-sorting algorithm. You need to determine which sorting algorithm is the best to sort the array of 10k elements.

Use the following steps to help with your solution:

  1. Create C++ functions for any two-sorting algorithm.
  2. Write down the random array generation function to generate at least 10k elements.
  3. Pass the same array into both the sorting algorithm.
  4. Calculate the end transactiontime-start transactiontime for each sorting algorithm.
  5. Determine the best algorithm for sorting 10k elements based on the transaction time.

Solutions

Expert Solution

PLEASE GIVE THUMBS UP, THANKS
OUTPUT SAMPLE :

code:

#include <iostream>
#include<ctime>
#include<stdlib.h>
using namespace std;
  
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
  
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)   
  
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
  
/* Function to sort an array using insertion sort*/
void insertionSort(int arr[], int n)
{
int i, key, j;
for (i = 1; i < n; i++)
{
key = arr[i];
j = i - 1;
  
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}   
// Driver code
int main()
{
int arr1[10000],arr2[10000];
int n =10000;
   int num;
   int start_s;
   int stop_s;
   //generating 10k Randoms numbers
for(int i=0; i<n; i++)
{
   num=rand();
   arr1[i]=num;
   arr2[i]=num;
   }
   //starting clock for bubble sort
start_s=clock();
   bubbleSort(arr1, n);
   //stopping cock for bubble sort
   stop_s=clock();
   cout << "Bubble sort taking time: " << (stop_s-start_s)<<"ms" << endl;
   //starting clock for insertion sort
   start_s=clock();
   insertionSort(arr2,n);
   //stopping cock for insertion sort
   stop_s=clock();
   cout << "insertion sort taking time: " << (stop_s-start_s)<<"ms" << endl;
return 0;
}


Related Solutions

You are working as a software developer for a large insurancecompany. Your company is planning...
You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score.Your Java program should perform the following things:Take the input from the user about the patient name, weight, birthdate, and height.Calculate Body Mass Index.Display person name and BMI Category.If the BMI Score...
You are working as a software developer for a large insurance company. Your company is planning...
You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score. Your Java program should perform the following things: Take the input from the user about the patient name, weight, birthdate, and height. Calculate Body Mass Index. Display person name and BMI...
1.) (a) There exists a very popular sorting algorithm called Timsort, the default sorting algorithm in...
1.) (a) There exists a very popular sorting algorithm called Timsort, the default sorting algorithm in both Python and Java. This sort is a combination of two different sorting algorithms: Merge sort, and Insertion sort. Recall that the Big-O of Merge sort is O(nlogn) and the Big-O of Insertion sort is O(n 2 ). What advantage would Timsort have to combine the two algorithms if merge-sort has a better Big-O metric? (b) Consider two algorithms: f(n) and g(n). You run...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design in place sorting algorithm? How this in place term is related to the time complexity and space complexity of the program?
Recall the definition of stable sorting: a sorting algorithm is said to be stable when elements...
Recall the definition of stable sorting: a sorting algorithm is said to be stable when elements with equal keys (after the sorting is complete) remain in the same order as they were in the input (before the sorting). Answer the following: Is Radix Sort stable, and why? Show an example: start from 10 random integer numbers (of at least 2 digits per integer number) to be sorted, where at least 2 of those 10 elements need to have equal keys;...
Choice 1. You are the new software developer at work. You are brought into a meeting...
Choice 1. You are the new software developer at work. You are brought into a meeting with clients that do not understand the idea of sorting data. Now you know, that you cannot use complex math to explain, but you can illustrate in diagrams. Basically, this group has been working with unsorted data and you must explain why their searches and reports will be so much faster with sorted data. You do not know anything specific about their data, but...
Could the sorting algorithm start out as if then else situation?
Could the sorting algorithm start out as if then else situation?
You are a renowned software developer and you have been hired by an old British boyband...
You are a renowned software developer and you have been hired by an old British boyband that wants to make a comeback in the industry. They ask you to make an app to showcase their new music and events. In your implementation, you have a class for each of the 5 group members, but you find that compiling each band member’s class takes more time than you currently have. Luckily, you remember that you learned about Makefiles in your favorite...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting .Arrival time, burst time and priority values.The code should also display: (i) Gantt chart and determine the following: (ii) Determine the Turnaround time(TAT), waiting time(WT) of each process (iii) Determine the Average Waiting Time (AWT) and Average Turnaround Time (ATAT) of all processes. please write the comments
RUN THIS PROGRAM ON NETBEANS As a Software Developer, you have received a requirement from a...
RUN THIS PROGRAM ON NETBEANS As a Software Developer, you have received a requirement from a Company to implement a prototype for its payroll system. You receive the following specifications: If an employee works more than its regular hours, it is considered overtime and it will be paid based on the employee’s experience. All employees are paid biweekly (80 hours) Employee taxes: 1% This company manages three categories of workers based on employee’s experience. Group 1 (Silver) o Pay rate:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT