4. What is the growth rate of the following method? public static int count(int
ID: 3700986 • Letter: 4
Question
4. What is the growth rate of the following method? public static int count(int (1 a, int c int count-0; for(int i-0; ika.length; i++X if(ali]c) count++ return count; 5. What is the m sorted 45-element array? Explain. aximum number of elements that will be visited by the binary search algorithm when searching a a. 1 b.6 c. 7 d. 22 e. 45 Suppose algorithm A takes 5 seconds to handle a data set of 1000 records. If the algorithm A is an O(n) algorithm, how long will it take to handle a data set of 2000 records? Of 10000 records? 6. 7. Approximately how many seconds would it take to sort a data set of 80000 values?Explanation / Answer
4. There is one for loop in function count(). it will execute for the whole length of the array. Let array length is n.
This loop will run n times. So the complexity of count function is O(n).
-------------------------------------------------------------------------------------------------------------------------------------------------------
5. Binary Search Algorithm has Complexity of O(log2n) in all cases where n is the number of elements in the sorted array.
Here n =45. So log245 =5.4 approx =6
so maximum 6 comparisons will be done in binary search .
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.