Question: In lecture we discussed the binary search algorithm which searches a sorted array for a key and returns either the index of where it was
In lecture we discussed the binary search algorithm which searches a sorted array for a key and returns either the index of where it was found, or if not found, returns the index of where it belongs. In such a case this belongs index is encoded as a negative number to distinguish it from being confused with a found index. The encoding is as follows: add to index then negate. In lecture we also discussed the insertInOrder algorithm which reads a sequence of values from a source text file and inserts them into an array keeping them sorted as each value is added to the array.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
