Question

In: Computer Science

Write a program to implement problem statement below: provide the menu for input N and number...

Write a program to implement problem statement below:

provide the menu for input N and number of experiment M to calculate average time on M runs. randomly generated list. State your estimate on the BigO number of your algorithm/program logic. (we discussed in the class) Measure the performance of your program by given different N with randomly generated list with multiple experiment of Ns against time to draw the BigO graph (using excel) we discussed during the lecture. Lab-08-BigBiggerBiggtest.png *** high level of algorithm for measurement,

Step1. Given N>0, M >0, Input N, M, set C=M

Step2. While C is greater than 0, repeat Step 3 to 8

Step3. Fill the Array[N] with random number

Step4. record start time

Step5. call biggest(Array[N] return the biggest number and position

Step6. record end time

Step7. decrement C

Step8, running time[C] = end time - start time

Step9, Calculate average running time based on running time[M]

Step10. Record N and average running time into 2D Array *** use of clock function for benchmarking measure in milliseconds, http://en.cppreference.com/w/cpp/chrono/c/clock (Links to an external site.) *** you should use 2D array to store your experiment time with different N. biggest-example.rtf

Programming language: C++

Solutions

Expert Solution

#include<iostream>

#include<ctime>

#include<bits/stdc++.h>

using namespace std;

double calculate(double arr[], int l)

{

double avg=0.0;

int x;

for(x=0;x<l;x++)

{

avg+=arr[x];

}

avg/=l;

return avg;

}

int biggest(int arr[], int n)

{

int x,idx,big=-1;

for(x=0;x<n;x++)
{

if(arr[x]>big)
{

big=arr[x];

idx=x;

}

}

return idx;

}

int main()

{

vector<pair<int,double> >result;


cout<<"Enter 1 for iteration\nEnter 2 for exit\n";

int choice;

cin>>choice;

while(choice!=2)

{

int n,m;

cout<<"Enter N"<<endl;

cin>>n;

cout<<"Enter M"<<endl;

cin>>m;

int c=m;

double running_time[c];

while(c>0)

{

int arr[n];

int x;

for(x=0;x<n;x++)

{
arr[x] = rand();

}

clock_t start = clock();

int pos = biggest(arr,n);

clock_t t_end = clock();

c--;

running_time[c] = 1000.0*(t_end-start)/CLOCKS_PER_SEC;

}

double avg_running_time = calculate(running_time,m);

result.push_back(make_pair(n,avg_running_time));

cout<<"Enter 1 for iteration\nEnter 2 for exit\n";

cin>>choice;

}

for(int x=0;x<result.size();x++)

{

cout<<result[x].first<<" "<<result[x].second<<endl;

}

}



Related Solutions

Write a program to implement the Romberg Algorithm. Input: f(x), an interval [a,b], N (the number...
Write a program to implement the Romberg Algorithm. Input: f(x), an interval [a,b], N (the number of subintervals on the finest grid on level 0 is 2^N, therefore, N is usualy a small integer) Output: the triangle generated by Romberg Algorithm.
Write a program (O(n), where n is the number of words) that takes as input a...
Write a program (O(n), where n is the number of words) that takes as input a set of words and returns groups of anagrams for those words. Complete your code here Do not change anything in the test file. CPP File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); vector> findAnagrams(const vector& dict) { // Your code here... } Test File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); int main() { vector word_list...
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system....
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system. The menu includes the following options: Add new room. The program will prompt the user to enter the roomID, courseID and time of the new reserved room, then will call the add() method from the RoomsBoard class. Remove all occurrences of a room. The program will prompt the user to input the room ID to be removed, then call the remove() method from the...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file has unknown number of records of inventory items, but no more than 100; one record per line in the following order: item ID, item name (one word), quantity on hand , and a price All fields in the input file are separated by a tab (‘\t’) or a blank ( up to you) No error checking of the data required Create a menu which...
Write a Little Man program that outputs the sum of n number of input values.
Write a Little Man program that outputs the sum of n number of input values.
Problem: Write a C++ program that will implement and test the five functions described below that...
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter...
in python Using this baseline template, write a program to input a choice from a menu...
in python Using this baseline template, write a program to input a choice from a menu def calcArea(length, width):    pass    def CalcVolumeSa(length, width, height):    pass def menu():    pass        def getValuesArea(): pass    def getValuesVolSa(): pass       def main():    menu() if __name__ == "__main__":    main() [1] - Calculate Area of rectangle [2] - calculate Volume and Surface area of Rectangle [x} - Exit Please select Option: input the appropriate values and calculate...
Now say you wish to write a program that, given a natural number input n, finds...
Now say you wish to write a program that, given a natural number input n, finds another program (e.g. in Java or C) which prints out n. The discovered program should have the minimum execution-time-plus-length of all the programs that print n. Execution time is measured by the number of CPU instructions executed, while “length” is the number of characters in the source code. Can this be done? (Hint: Is it possible to tell whether a program halts on a...
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT