Problem

Consider an array data of n numerical values in sorted order and a list of numerical targe...

Consider an array data of n numerical values in sorted order and a list of numerical target values. Your goal is to compute the smallest range of array indices that contains all of the target values. If a target value is smaller than data[0], the range should start with -1. If a target value is larger than data[n - 1], the range should end with n.

For example, given the array in Figure 3 and the target values (8, 2, 9, 17), the range is -1 to 5.

a. Devise an efficient algorithm that solves this problem.


b. If you have n data values in the array and m target values in the list, what is the Big Oh performance of your algorithm?


c. Implement and test your algorithm.

FIGURE 3 An array for Project 4

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 18
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT