Question

Project 2 Sorting, CPU Time, and Big O Analysis Note: you will be using Microsoft Visual...

Project 2

Sorting, CPU Time, and Big O Analysis

Note: you will be using Microsoft Visual Studios 2019 as the compiler.

This is an individual assignment. You will have lab time to work on this assignment as well as homework time.

Each person will analyze two sorts. The first sort will be either bubble sort or insertion sort. The second sort will be either quick sort or merge sort. Create two projects, one for each sort in the given choices.

In this assignment, we will be learning about, describing, coding, and empirically looking at the work involved in each sorting algorithm. Use 4 data set sizes. Results will be based on execution time for each sort. The size should have a regular increment. For example, using a regular increment of 10,000, you might have sizes of 10,000, 20,000, 30,000, and 40,000. Choose your data size based upon the ability to obtain meaning results.

Submit:

  1. A Word document named SortDescriptionsLastName.docx. The Word document should be modeled after the selection sort description under Course Content. The Word document should have:
    1. A few useful web resources for the sort.
    2. A detailed explanation (in your own words) of the sort.
    3. A clear visual representation of the sort (cite source if found on web, book …).
    4. Two screen shots of your program displaying the sorted array for each sort. The display of each value should include the index and value of each element in the array. These screen shots of course will not show your entire array but only a part.
  2. An Excel document that shows the empirical results of running each sort. The name of the file should be SortEmpiricalAnalysesLastName.xlsx.
  3. Code for the algorithm in a working program (similar to SelectionSort.cpp).
    1. Code should be well-documented.
    2. Code should use meaningful identifiers (do not use abbreviated variable names such as r for right).
    3. Code should be well-structured and easy to read.
    4. You should be able to understand every aspect of the code that you are using.
    5. The code for each sort should be organized in its own project folder – a compressed zipped folder for each project. Use only .zip folders (not .rar folder).

Grading

For the two sorts:

      Code is well documented

      Code uses meaningful identifiers

      Code is well-structured and easy to read.

      In Word document:

      Useful web resources for each sort

      Detailed explanation (in your own words) of each sort

      A clear visual representation of each sort (cite source if found on web, book …)

      One screen shot of your program displaying the sorted arrays

An Excel spreadsheet that shows the empirical results of running each sort.

Code for each sort should be organized in its own project folder – a compressed zipped folder (for each project). Use only .zip folders (not .rar folder).

10 points

10 points

10 points

10 points

20 points

10 points

10 points

10 points

10 points

Total 100

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

The main function takes as input the size of the array and calls the corresponding sort function and measure the time taken by the algorithm to sort.

In this I am giving you the code for all the sorting techniques mentioned above as well as the main function. Change the sorting function as you like in the main() function to get the result.

You can then compare time taken by different algorithms to sort large sized arrays.

#include <bits/stdc++.h>

using namespace std;

//-----------------------bubble sort-----------------------

// swap function for bubble sort and quick sort algorithms

void swapElements(int &a, int &b) {

int temp = a;

a = b;

b = temp;

}

void bubbleSort(int a[], int n) {

for(int i = 0;i < n - 1; ++i) {

for(int j = 0; j < n - i - 1; ++j) {

if(a[j] > a[j + 1]) {

swapElements(a[j], a[j + 1]);

}

}

}

}

//----------------------Insertion sort-------------------------

int insertionSort(int a[], int n) {

int key;

for(int i = 1; i < n; ++i) {

key = a[i];

int j = i - 1;

while(j >= 0 && a[j] > key) {

a[j + 1] = a[j];

j--;

}

a[j + 1] = key;

}

}

//-------------------------Merge sort------------------------------

void mergeArrays(int a[], int left, int mid, int right) {

int n1 = mid - left + 1;

int n2 = right - mid;

int l[n1], r[n2];

for(int i = 0; i < n1; ++i) {

l[i] = a[left + i];

}

for(int i = 0; i < n2; ++i) {

r[i] = a[mid + 1 + i];

}

int i = 0, j = 0, k = left;

while(i < n1 && j < n2) {

if(l[i] <= r[j]) {

a[k++] = l[i++];

}

else {

a[k++] = r[j++];

}

}

while(i < n1) {

a[k++] = l[i++];

}

while(j < n2) {

a[k++] = r[j++];

}

}

void mergeSort(int a[], int left, int right) {

if(left < right) {

int mid = (left + right) / 2;

mergeSort(a, left, mid);

mergeSort(a, mid + 1, right);

mergeArrays(a, left, mid, right);

}

}

//--------------Quick Sort-----------------

int partitionArray(int a[], int low, int high) {

int pivot = a[high];

int i = low - 1;

for(int j = low; j < high; j++) {

if(a[j] <= pivot) {

i++;

swapElements(a[i], a[j]);

}

}

swapElements(a[i + 1], a[high]);

return i + 1;

}

void quickSort(int a[], int low, int high) {

if(low < high) {

int pi = partitionArray(a, low, high);

quickSort(a, low, pi - 1);

quickSort(a, pi + 1, high);

}

}

void sortFunctionForQuickSort(int a[], int n) {

quickSort(a, 0, n - 1);

}

int main() {

// seed for rand() functon

srand(time(0));

// Taking the size as input

int n;

cout << "Enter The Size of Array:\t";

cin >> n;

// Generating and printing size n array

int A[n];

// cout << "Unsorted Array:" << endl;

for(int i = 0; i < n; ++i) {

A[i] = (rand() % 10000) + 1;

// cout << A[i] << " ";

}

// Running Sort Algorithm and calculating Time

auto start = chrono::high_resolution_clock::now();

bubbleSort(A, n); // change the sorting algorithm as you wish

// Use auto keyword to avoid typing long

// type definitions to get the timepoint

// at this instant use function now()

auto stop = chrono::high_resolution_clock::now();

// Subtract stop and start timepoints and

// cast it to required unit. Predefined units

// are nanoseconds, microseconds, milliseconds,

// seconds, minutes, hours. Use duration_cast()

// function.

// You can change the values of time here to display in seconds or even minutes.

auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);

// To get the value of duration use the count()

// member function on the duration object

cout << endl << "Duration:\t";

cout << duration.count() << " microseconds" << endl;

return 0;

}

Hope this answer is helpful to you.

Add a comment
Know the answer?
Add Answer to:
Project 2 Sorting, CPU Time, and Big O Analysis Note: you will be using Microsoft Visual...
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
  • C program: Write a program that assigns and counts the number of each alphabetic character in...

    C program: Write a program that assigns and counts the number of each alphabetic character in the Declaration of Independence and sorts the counts from the most used to the least used character. Consider upper and lower case letters the same. The frequency of each character should be accumulated in an array. USE POINTERS to increment counts for each letter, sort your array, and display the results. Output should consist of two columns: (1) each letter 'a'-'z' and (2) the...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • disregard Final Project 2 Due Sunday by 11 59pm Points 100 Submitting the upload Instructions For...

    disregard Final Project 2 Due Sunday by 11 59pm Points 100 Submitting the upload Instructions For this assignment, you will create flowchart using Flowgorithm and Pseudocode for the following program example You are to design a program for Alexander's Coffee Shop providing customer research data When a customer places an order, the clerk asks the customer for their zip code and age. The clerk enters this data as well as the number of ems purchased. The program should operate continuously...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • Please write C++ code Description: As a senior software engineer, I would like to determine and...

    Please write C++ code Description: As a senior software engineer, I would like to determine and prove which sorting algorithm is the most efficient between quick sort, merge sort, and heap sort so that I can recommend it to the development team for inclusion in the code base of an upcoming code optimization project. Acceptance Criteria: Well documented, executable C++ source files including classes for each of the aforementioned sorting algorithms. In addition, each sorting algorithm class implementation should be...

  • Need this assignment in complete steps with the code and written in C++ Description: As a...

    Need this assignment in complete steps with the code and written in C++ Description: As a senior software engineer, I would like to determine and prove which sorting algorithm is the most efficient between quicksort, merge sort, and heap sort so that I can recommend it to the development team for inclusion in the code base of an upcoming code optimization project. Acceptance Criteria: Well documented executable C++ source files including classes for each of the aforementioned sorting algorithms. In...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • c++. please show screenshots of output This project will continue to familiarize the student with using...

    c++. please show screenshots of output This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_funch and store all the functions in project11_func.cpp. Make sure you have proper header comments in each.h,.cpp file. When you run your program, your sample output should show your name. Your report should include the following: 1) project11_func.h 2) project11_func.cpp 3) project11.cpp 4) sample output Write the following functions: a) void fill_array_with_random_nums(int array(), int N): Fill array...

  • Please help ASAP! C ++, linked list, etc. everything for the project is in the link...

    Please help ASAP! C ++, linked list, etc. everything for the project is in the link below. https://www.zipshare.com/download/eyJhcmNoaXZlSWQiOiIzZDIyN2UzYi1kNGFhLTRlMzEtYjMzZi00MDhmYzNiMjk3ZGMiLCJlbWFpbCI6Im1pMTQzNEBnbWFpbC5jb20ifQ== You should turn it in by blackboard. Each task should be in a separate unzipped folder named YourLastName_YourFirstInitial_taskN, where N is the task number inside a zipped file named: YourLastName_YourFirstInitial.zip. You may use code you have written previously and you may ask other members of the class questions about the assignment. However, you must do your own assignment; you may not use...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

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