1. Engineering
  2. Computer Science
  3. 10 30 marks write a program that obtains the execution...

Question: 10 30 marks write a program that obtains the execution...

Question details

10. [30 marks] Write a program that obtains the execution times for the following three code segments with the different n code 1 for (int i 0; i <= n; i++) x=i; code 2: for (int í = 0; i <= n; i++) for (int j = 0; j <= n; j++) x=i+j; code 3: for (int i # 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k= 0; k <= n; k++) Please record the execution time of the following tasks, Code 1 when n-I00, n. 1,000, n-5,000, n# 10,000, n 100,000, n. 1,000,000. n=2,000,000, and n= 10,000,000 Code 2 when m=100, n=1,000, n-5,000, n= 10,000, n-l 00,000, and n-200,000. Code 3 when n= 10, n-50, n= 100, n-500, and n = 1.000. You can fill a table like this: n=10 l n=50 l n=100 l n=200 l n=10001. Code 1 Code 2 Code 3 Plotting the execution time of Code 1, Code 2 and Code 3. You may want to execute Codel, Code2 and Code 3 with more n values to plot.Plotting the execution time of Code 1, Code 2 and Code 3. You may want to execute Codel, Code2 and Code 3 with more n values to plot. You can use the following code template to obtain the execution time. #include <iostream> #include <ctime> // for time function #include <chrono> void get_time_codel (int n) using clockchrono::steady clock; clock: time-point start clock: :now(); //Get start time // perform the task Code 1 which you want to analyze the // execution time int x # 0; for (int i = 0; i <-n; i++) x = i; clock::time_ point end - clock:no 1/Get end time clock::duration time span-end start: double ns double (time span.count)clock::period: :num clock: :period: :den; cout << Code 1 execution time for n<Kn <<is << ns << seconds << endl; You can put functions in the file alql0.cpp. Please submit the program alqlo.cpp, a script file alq10result containing result, and the plot of execution time

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution