Professional Documents
Culture Documents
Homework 1 Array (Tahani)
Homework 1 Array (Tahani)
Question 1: The following function is the code for binary search, but some of the code is wrong. Correct the
code so the function starts working as it is intended.
Line Code Corrected code
1 public static int binSearch(int[] a, int value) {
2 int low = 0;
Question 2 For a given array, you wish to find the value 118 using Linear and Binary search algorithms.
1. Write the number of steps it would take using linear search and the number of steps it would take using
binary search algorithms when finding the value 118 in the array.
index 0 1 2 3 4 5 6 7 8
value 2 6 19 27 33 37 38 41 118