Illustrate the growth of the algorithm by: i. providing a table that reports the growth of the sorting algorithm in the implementation above; and ii. plot a graph to illustrate the growth of the sorting algorithm. To illustrate the growth of your sorting algorithm, run the program with at least the following n values (n represents the number of order ids that was generated): 1,000; 5,000; 32,000; 512,000; 1,000,000. The growth of the algorithm is typically measured in millisecond (ms) or microsecond (us) or nanosecond (ns). The growth rate of your sorting algorithm may vary due to your processor speed, memory capacity and etc. Therefore, to illustrate the consistency of the growth rate of your program, you will need to perform and report a minimum of 5 trial runs on each of then values. You may then take the average of the running time for plotting the graph and for the discussion in the section below.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;

void merge(int arr[], int l, int m, int r)
{
    int n1 = m - l + 1;
    int n2 = r - m;
    int L[n1], R[n2];
    for (int i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (int j = 0; j < n2; j++)
        R[j] = arr[m + 1 + j];
    int i = 0;
    int j = 0;
    int k = l;

    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        }
        else {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int arr[],int l,int r){
    if(l>=r){
        return;
    }
    int m =l+ (r-l)/2;
    mergeSort(arr,l,m);
    mergeSort(arr,m+1,r);
    merge(arr,l,m,r);
}


int main()
{
    srand(time(0));
    long int n;
    cout<<"Enter the number of orders ";
    cin>>n;
    int ids[n],cost[n],sorted_ids[n],sorted_cost[n];
    for(int i=0;i<n;i++)
    {
        ids[i]=rand();
    }
    for(int i=0;i<n;i++)
    {
        cost[i]=rand();
    }
    while(1)
    {
        cout<<"1. Unsorted Order ids and their cost"<<endl;
        cout<<"2. Sorted Order ids and their cost"<<endl;
        cout<<"3. exit"<<endl;
        int choice;
        cin>>choice;
        if(choice == 1)
        {
            cout<<"Order ID\t Cost"<<endl;
            for(int i=0;i<n;i++)
            {
                cout<<"FD"<<ids[i]<<"\t\t RM"<<cost[i]<<endl;
            }
        }
        else if(choice==2)
        {
            for(int i=0;i<n;i++)
            {
                sorted_ids[i]=ids[i];
            }
            time_t start,end;
            time(&start);
            mergeSort(sorted_ids,0,n);
            for(int i=0;i<n;i++)
            {
                int j;
                for(j=0;j<n;j++)
                {
                    if(ids[j]==sorted_ids[i])
                    {
                        sorted_cost[i]=cost[j];
                        break;
                    }
                }
            }
            time(&end);
            double time_taken = double(end-start);
            cout<<"Time taken to mergesort is "<<time_taken<<" sec"<<endl;
            cout<<"Order ID\t Cost"<<endl;
            for(int i=0;i<n;i++)
            {
                cout<<"FD"<<sorted_ids[i]<<"\t\t RM"<<sorted_cost[i]<<endl;
            }
        }
        else if(choice==3)
        {
            break;
        }
        else
        {
            cout<<"Invalid choice"<<endl;
        }
    }
}

Illustrate the growth of the algorithm by:
i.
providing a table that reports the growth of the sorting algorithm in the
implementation above; and
ii.
plot a graph to illustrate the growth of the sorting algorithm.
To illustrate the growth of your sorting algorithm, run the program with at least the
following n values (n represents the number of order ids that was generated): 1,000; 5,000;
32,000; 512,000; 1,000,000. The growth of the algorithm is typically measured in
millisecond (ms) or microsecond (us) or nanosecond (ns).
The growth rate of your sorting algorithm may vary due to your processor speed, memory
capacity and etc. Therefore, to illustrate the consistency of the growth rate of your program,
you will need to perform and report a minimum of 5 trial runs on each of the n values. You
may then take the average of the running time for plotting the graph and for the discussion
in the section below.
Transcribed Image Text:Illustrate the growth of the algorithm by: i. providing a table that reports the growth of the sorting algorithm in the implementation above; and ii. plot a graph to illustrate the growth of the sorting algorithm. To illustrate the growth of your sorting algorithm, run the program with at least the following n values (n represents the number of order ids that was generated): 1,000; 5,000; 32,000; 512,000; 1,000,000. The growth of the algorithm is typically measured in millisecond (ms) or microsecond (us) or nanosecond (ns). The growth rate of your sorting algorithm may vary due to your processor speed, memory capacity and etc. Therefore, to illustrate the consistency of the growth rate of your program, you will need to perform and report a minimum of 5 trial runs on each of the n values. You may then take the average of the running time for plotting the graph and for the discussion in the section below.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY