#264 Write a program to compare execution
Write a program to compare execution - Computer Science
ChemistryExplain daily providing Q&A content “#264 Write a program to compare execution" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs.
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.
ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.
For More Chegg Questions
Free Chegg Question
For More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain
Free Chegg Answer
Hello, here are the answers to the above question. Hope it helps. If you are satisfied with the answers, do consider upvoting! Stay safe and keep learning
Q1. The time complextity of running the max function is O(n) where n is the length of the array supplied in the parameter. If the maximum number is the first number in the array itself(index-0), then the if condition is run 0 times and the assignment of m = a[i] is done 0 times(Ex: [10,4,3,7]). This is the best case scenario. On the otherhand if the array is sorted in increasing order, then the if condition is run n times, where n is the length of the array. Hence this is the worst case(Ex: [4,6,9,11,13]).
Q2. For the function prefixTotal1(), the return array's ith term is the the sum of all elements in the index range [0,i] in the supplied array. Thus for the given array[5,1,3,2,4], the output tmp array is [5,6,9,11,15]. The time complexity of the given function is O(n2), where n is the length of the input array(Since there are 2 for loops and the inner loops run from 0 to ith index each time for the outer for loop).
Q3. For the function prefixTotal2(), the output for the input array is same as that of Q2. These both functions return the same value, but the efficiency of prefixTotal2() is better than that of prefixTotal1().(Since there are no nested loop in prefixTotal2() as opposed to prefixTotal1()). The time complexity of this function is O(n), where n is the length of the input array.
Thus if a computer can do 1000 basic operations in 1 second, it will take the computer the following times to run the given 2 functions:
Labels: Chegg, Free Chegg Answer, Q&A Computer Science
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home