1. What is the index of the first element accessed in the array when searching f
ID: 3566766 • Letter: 1
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.
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.
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.
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.
5. Will the algorithm access another (the fifth) element 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
1.
Using Linear Search
The correct answer is 0. The array index starts at 0. So, the first element in the array is accessed at index value 0, while searching the number 20.
Using Binary Search
If the binary search technique is used, then the index of the first element accessed in the array when searching for the number 20 is 8. According to the binary search technique, Hi: = 17, Lo:= 0, Mid:= (17+0)/2 = 8
2.
Using Linear Search
The correct answer is 1. The array index starts at 0. So, the second element in the array is accessed by incrementing the index value by 1. So, the index value becomes 1, while searching the number 20.
Uisng Binary search
If binary search technique is used, then Hi:= 7(8-1), Lo:= 0, Mid: = (7+0)/2 = 3. The index at which second element is accessed is 3.
3.
Using linear Search
The correct answer is 2. The array index starts at 0. So, the third element in the array is accessed by incrementing the index value by 2. So, the index value becomes 3, while searching the number 20.
Using Binary Search
The index at which third element is accessed is 5 because Hi:= 7, Lo: = 4(3+1) Mid : = (7+4)/2 =5
4.
Using Linear Search
The correct answer is 3. The array index starts at 0. So, the fourth element in the array is accessed by incrementing the index value by 3. So, the index value becomes 3, while searching the number 20.
Using Binary Search
The index at which the 4th element is accessed is given by: Hi:= 7, Lo:=6(5+1), Mid : =(7+6)/2 = 6
5.
Using linear Search
The correct answer is 4. The array index starts at 0. So, the fifth element in the array is accessed by incrementing the index value by 4. So, the index value becomes 4, while searching the number 20.
Using Binary Search
The index at which the 5th element is accessed is given by Hi:=7, Lo:=7(6+1), Mid: =(7+7)/2 = 7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.