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 an analytics developer, and you need to write the searching algorithm to find the...
You are an analytics developer, and you need to write the searching algorithm to find the element. Your program should perform the following: Implement the Binary Search function. Write a random number generator that creates 1,000 elements, and store them in the array. Write a random number generator that generates a single element called searched value. Pass the searched value and array into the Binary Search function. If the searched value is available in the array, then the output is...
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?
For this assignment, you will take on the role of software developer as part of a...
For this assignment, you will take on the role of software developer as part of a team of developers for a retail company. The payroll manager of the company has tasked you with developing a Java program (if you can put it in NetBeans that would be awesome) to quickly calculate an employee’s weekly gross and net pay. The program must prompt the user to enter the employee’s name, rate of pay, and hours worked. The output will display the...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT