If the array is [2, 3, 4, 10, 40] and we are searching for 10, what is the first
Practice Questions
Q1
If the array is [2, 3, 4, 10, 40] and we are searching for 10, what is the first mid index calculated in binary search?
0
2
3
1
Questions & Step-by-Step Solutions
If the array is [2, 3, 4, 10, 40] and we are searching for 10, what is the first mid index calculated in binary search?
Step 1: Identify the array we are working with, which is [2, 3, 4, 10, 40].
Step 2: Determine the starting index (left) and the ending index (right) of the array. The left index is 0 (the first element) and the right index is 4 (the last element).
Step 3: Calculate the mid index using the formula (left + right) / 2. Here, it will be (0 + 4) / 2.