I could really use some help with for-loop complexity analysis. Thank you! CSC34
ID: 3813979 • Letter: I
Question
I could really use some help with for-loop complexity analysis. Thank you!
CSC340: HW5 Problem: Please analyze the time complexity of the following functions or for- loops. For each question, use the following template to figure out the total time needed to finish the corresponding function or for-loop. Line No. Time taken to run this line of code Total number of times needed to run this line. Once Total time needed to finish this function or loop: Submission: Please submit your solution as one PDF file. This PDF will contain three tables in the above format, corresponding to your complexity analysis to the three questions. Q1. double sum skip7 (double arra. l, int n) n: size of the array. Assume n is divisible by 7, 1.e., nF k, where k is a positive integer double sum-0 for (int i 0: iExplanation / Answer
Since the amount of time exactly varies from compilers to system execution time, we need a universal denotion to have an idea for time complexity. That denotion is O(). We calculate the number of times a line will execute and take the maximum O() as our final ans. Son in the tables we choosed the one with the maximum time complexity as our problem time complexity. Since the number of times a line will execute depends on the input, so we write using consonants.
For q.1)
Total time needed to finish this function or loop: O(n).
For q.2)
Total time needed to finish this function or loop: O(n).
For q.3)
Total time needed to finish this function or loop: O(n2).
Line No. Time taken to run this line of code once Total no. of times needed to run this line 1 O(1) 1 2 O(n) (n/i)+1 3 O(n) (n/i) 4 O(1) 1Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.