#196 Write a program to compare the execution
Write a program to compare the execution - Computer Science
ChemistryExplain daily providing Q&A content “#196 Write a program to compare the 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
Write a program to compare the execution time of method max in best case, and in worst case
What array will make the above method always run in the best case?
What array will make the above method always run in the worst case?
Repeat the experiment with different sizes of the input array as follows:
For More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain
Free Chegg Answer
EXAMPLE 3 SOLTION
CONSIDER 2 INPUTS
INPUT 1: 5 4 3 2 1
INPUT 2: 1 2 3 4 5
in exmple 3 both worst case and best will take same time to run because in for loop if condition is true theen the value of variable m will be update else loop will continue for next itration so overall complexity best case = worst case ==O(n) where n is the number of elements in array.
input best case comparisons worst case comparisons
10,000 10,000 10,000
100,000 100,000 100,000
500,000 500,000 500,000
1000,000 1000,000 1000,000
2000,000 2000,000 2000,000
example 4 solution for code 1.
the output of above mentioned input 5 1 3 2 4
output will be 5 6 9 11 15 sum of all previous iterated element for perticular index
complexity of above method will be
best case = worst case = O(n^2)
example 4 solution for code 2.
input = 5 1 3 2 4
output = 5 6 9 11 15
complexity of the second code will be
best case = worst case = O(n) only one time loop will be iterate
class Time {
public static void main(String[] args) {
long start = System.currentTimeMillis();
long total = 0;
for (int i = 0; i < 10000000; i++) {
total += i;
}
long stop = System.currentTimeMillis();
long elapsedTime = stop - start;
System.out.println(
}
}
Labels: Chegg, Free Chegg Answer, Q&A Computer Science
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home