Sample Questions for Computer Science A 10. Consider the following instance vari
ID: 3829036 • Letter: S
Question
Sample Questions for Computer Science A 10. Consider the following instance variable and method private int arr; Precondition: arr contains no duplicates; the elements in arr are in ascending order. aram low an int value such that o s low s arr. length @param high an int value such that low 1 s high arr.length aparam num an int value public int mystery (int low, high, int num) int int mid (low high) 2 if (low high return low; else if arr [mid num return mystery (mid 1 high num else if arr [mid num return mystery (low mid 1, num else arr [mid] num return mid What is returned by the call mystery (0, arr. length 1, num) CA) The number of elements in arr that are less than num The number of elements in arr that are less than or equal to num (c) The number of elements in arr that are equal to num (D) The number of elements in arr that are greater than num (E) The index of the middle element in arr 26 e 2014 The College Board. Visit the College Board on the Webe vrww.collegeboard.org.Explanation / Answer
this is the algorithm of binary seach which folllow divide and conqueor technique
it seaches the no which is given by num parameter and return the index of a number
1) it first compare with the middle element if found then it return the index of middle elenemt
2) if middle element is not equal to num,and middle element is greater than num then it search on array conatining element of left of middle
3) if middle element is not equal to num,and middle element is smaller than num then it search on array conatining element of right of middle
so this algorith return the index of the number provided by the num parameter
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.