Question

In: Computer Science

Consider the following sorted int array: 1 3 4 5 7 9 10 12 If we...

Consider the following sorted int array:

1 3 4 5 7 9 10 12

If we search for the key value 10 in the array using the binary search algorithm, what is the sequence of indices that will be accessed in the array?

(Hint: For a sublist between index values low and high, the middle index is calculated using: (low + high) / 2. So you need to show the sequence of indices of the middle index in each pass.)

Question 40 options:

Solutions

Expert Solution

Searching for 10 in list [1, 3, 4, 5, 7, 9, 10, 12]
   low = 0, high = 7, mid = 3
   > Middle element in this list is 5
   > Compare Target (10) with middle element (5) of this list
   > Target value (10) is larger than this middle element 5
   > so, we have to search in right part of the list([7, 9, 10, 12])
Searching for 10 in list [7, 9, 10, 12]
   low = 4, high = 7, mid = 5
   > Middle element in this list is 9
   > Compare Target (10) with middle element (9) of this list
   > Target value (10) is larger than this middle element 9
   > so, we have to search in right part of the list([10, 12])
Searching for 10 in list [10, 12]
   low = 6, high = 7, mid = 6
   > Middle element in this list is 10
   > Compare Target (10) with middle element (10) of this list
   > They are the same. Target element (10) is found. so, binary search ends here.
It took a total of 3 comparisons using binary search



Related Solutions

Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int...
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int n, int k)             if (n <= 0) return 0;             else if (A[n] < k) return (1+ 2*BBOX(n-1,k+1));             else return BBOX(n-1,k-2);             Find BBOX(8, 5)
Consider the following data set: 3 -5 5 7 9 10 -3 35 2 1 1...
Consider the following data set: 3 -5 5 7 9 10 -3 35 2 1 1 a) Determine by hand (you can use the calculator) the mean, median and mode of this data set. show enough details in your work for it to be clear that you did this work. b) Use MINITAB to obtain the above results for this data set (and only these results). c) By hand clearly determine the 5 number summary for this data set and...
Given the matrix 7 7 -4 12 -5 A = 9 10 2 6 13 8 11 15 4 1 3. a. Sort each column and store the result in an array B.
Given the matrix a. Sort each column and store the result in an array B.b. Sort each row and store the result in an array C.c. Add each column and store the result in an array D.d. Add each row and store the result in an array E.  
5.) For the data set 2 4 4 5 7 8 9 10 12 12 13...
5.) For the data set 2 4 4 5 7 8 9 10 12 12 13 13 16 16 16 16 17 19 19 20 23 24 24 24 25 26 26 27 28 28 29 31 32 34 34 36 37 38 42 44 45 46 47 47 48 50 52 53 53 54 55 56 56 57 58 (a) Find the 80th percentile. The 80t percentile is =    (a) Find the 42nd percentile. The 42nd percentile is...
3 6 4 8 1 10 2 9 11 12 15 22 3 6 7 5...
3 6 4 8 1 10 2 9 11 12 15 22 3 6 7 5 8 1 12 14 Each column represents a different treatment given to sick rats. Each cell is a different rat. Use statistical analysis and use post hoc testing using contrasts to find the best treatment. Treatment 1: vitamins Treatment 2: prescription pills Treatment 3: brain surgery Treatment 4: shock therapy Treatment 5: dietary changes
Match No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14...
Match No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Player A 8 42 56 68 91 123 12 46 57 137 5 80 14 10 19 Player B 38 44 46 59 57 61 48 42 51 39 58 41 55 45 68 1. For the given data set representing the runs scored by two players in last 15 matches, conduct the following analysis: i. Which average you will use to summarize...
(9) Diagonalizing 4 0 1 -7 -5 5. -12 -6 7
(9) Diagonalizing 4 0 1 -7 -5 5. -12 -6 7
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6};...
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6}; and we also have a linked list L of 5 entries 1 -> 2 -> 3 -> 5 -> 6, where 1 is the first in the linked list L, followed by 2 etc. We want to put a new item 4 between 3 and 5 in the array a and in the linked list L (a) Explain in plain English how you do...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .text la $s0, myArray li $s1, 0 loop: sll $t0, $s1, 2 add $t0, $t0, $s0 lw $s2, 0($t0) lw $s3, 4($t0) add $s2, $s2, $s3 sw $s2, 0($t0) addi $s1, $s1, 1 slti $t1, $s1, 9 bne $t1, $zero, loop .end Explain what does this program do? How is the data bound from the .data segment to the base address register $s0? What...
Periods ​1% ​2% ​3% ​4% ​5% ​6% ​7% ​8% ​9% ​10% ​12% ​14% ​15% ​16% ​18%...
Periods ​1% ​2% ​3% ​4% ​5% ​6% ​7% ​8% ​9% ​10% ​12% ​14% ​15% ​16% ​18% ​20% 1 0.990 0.980 0.971 0.962 0.952 0.943 0.935 0.926 0.917 0.909 0.893 0.877 0.870 0.862 0.847 0.833 2 0.980 0.961 0.943 0.925 0.907 0.890 0.873 0.857 0.842 0.826 0.797 0.769 0.756 0.743 0.718 0.694 3 0.971 0.942 0.915 0.889 0.864 0.840 0.816 0.794 0.772 0.751 0.712 0.675 0.658 0.641 0.609 0.579 4 0.961 0.924 0.888 0.855 0.823 0.792 0.763 0.735 0.708 0.683 0.636...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT