Computer Science Question 1 What is the index of the first element accessed in t
ID: 3559684 • Letter: C
Question
Computer Science
Question 1
What is the index of the first element accessed in the array when searching for the number 20?
Only put in the integer for the index, not the value of the array.
Question 2
What is the index of the second element accessed in the array when searching for the number 20?
Only put in the integer for the index, not the value of the array.
Question 3
What is the index of the third element accessed in the array when searching for the number 20?
Only put in the integer for the index, not the value of the array.
Question 4
What is the index of the fourth element accessed in the array when searching for the number 20?
Only put in the integer for the index, not the value of the array.
Explanation / Answer
Both Previous Answers are Incorrect.
I just had this exact question on a quiz, and it relates to Binary Search.
The way it is to be computed is as follows:
First element accessed: Hi=17; Lo=0; Mid=(17+0)/2 = 8 (Integer division)
Second element accessed: Hi=7 (8-1); Lo=0; Mid=(7+0)/2 = 3 (Integer division)
Third element accessed: Hi=7; Lo=4 (3+1); Mid=(7+4)/2 = 5 (Integer division)
Fourth Element accessed: Hi=7; Lo=6 (5+1); Mid=(7+6)/2 = 6 (Integer division)
Note that when you search a specific index, you must, on the next test, start one index higher (if the indexed value was less than the search number) or one lower (if the indexed value was more than the search number).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.