Question: (d) Consider a Binary Search algorithm (Algorithm 2): Algorithm 2 To find which (if any) component of the sorted (sub)array alleft...right) equals target. Set /
(d) Consider a Binary Search algorithm (Algorithm 2): Algorithm 2 To find which (if any) component of the sorted (sub)array alleft...right) equals target. Set / = left, and set r = right while I sr do Let m be (a) if target equals a[m] then terminate with answer m. end if if target is less than a[m] then set (b) end if if target is greater than a[m] then set (0) end if end while Terminate with answer none. i. Complete the missing parts of the algorithm at (a), (b) and (c). ii. Using Big-O notation, state the time complexity of the algorithm; justify your answer. iii. At each iteration of the algorithm, it compares the target with the current sub-array element a[m]. For the target value = '5' and the following sorted array: 1,2,4,5,6,7, '8', '10', '15', write values of a[m] in sequence, which will be compared with the target value by the algorithm (e) i. Write the insertion sort algorithm that sorts an array alleft...right) into ascending order. ii. Given the following array, 15 3 12 5 9 run the insertion sort algorithm and show the intermediate status of the array until the sorting is completed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
