1. Given an array B = {4, 20, 36, 45, 101, 175, 209, 332), show the steps to search for the value 200 in array B using sequential search, binary search and key-indexed search. Indicate the number of comparisons performed by each algorithm. Sequential Search Binary Search Key-indexed Search Steps # of Comparisons 2. Given an array storing integers ordered by value in increasing order, modify the binary search algorithm to return the position of the first integer with value K assuming K can appear multiple times in the array. Be sure that your algorithm is 0(log n), that is, do not use sequential search once an occurrence of K is found. 3. Given an array storing integers ordered by value in increasing order, modify the binary search algorithm to return the position of the integer with the greatest value less than K assuming K does not appear in the array. Return -1 if all values in the array are greater or equal K.
1. Given an array B = {4, 20, 36, 45, 101, 175, 209, 332}, show the steps to search for the value
200 in array B using sequential search, binary search and key-indexed search. Indicate the
number of comparisons performed by each
2. Given an array storing integers ordered by value in increasing order, modify the binary search
algorithm to return the position of the first integer with value K assuming K can appear
multiple times in the array. Be sure that your algorithm is (log n), that is, do not use
sequential search once an occurrence of K is found.
3. Given an array storing integers ordered by value in increasing order, modify the binary search
algorithm to return the position of the integer with the greatest value less than K assuming K
does not appear in the array. Return -1 if all values in the array are greater or equal K.
Step by step
Solved in 4 steps