Question: ### Please solve as per method 1B ### 1A-1. Create one array arr1 of size 1000. Populate it with random numbers in the range from

### Please solve as per method 1B ###

1A-1. Create one array arr1 of size 1000. Populate it with random numbers in the range from 0 to 2000.

1A-2. Randomly generate 5 numbers and try to search each number in the array.

1A-3. Display the number of key comparison for each search.

1A-4. Display a table like the following:

Target Number

# of Key Comparison

1

356

(Not Found) 1000

2

54

256

3

1568

546

4

349

(No Found) 1000

5

545

678

Average

696

Method 1B

1B-1. Use the same array which was generated above. Sort the array.

1B-2. Use binary search to do the search for the same 5 random numbers in Part 1.

1B-3. Display the report like the one above. Compare the differences between the two tables. With this method, the numbers of key comparison should be fewer than 10, which is roughly 70 times faster than that of the Method 1.

Part 2

Create a function like:

void findMedianNo(int arr1[], int size1, int arr2[], int size2)

which takes two arrays and their sizes as parameters and displays (1) the int median number of the two arrays as if they are combined together as one array, (2) the number of key comparisons during the entire process. Please be informed that NO ANY AUXILIARY DATA STRUCTURES, such as array, IS ALLOWED to use in the function for solving this problem and no data in the arrays can be modified.

In main() create another array named arr2 of the same size, i.e. 1000. Populate it with any random numbers and sort it. (Please be aware that the integers in this array are very different from those in arr1.) Find the median number of the two arrays. (In the case that the sum of the two array sizes is even, the function should first locates the two median numbers and return the average of the two integers without the decimal.)

There are at least three possible methods, i.e. linear and binary, to solve this problem and Big-Os of these methods are very different. Could you figure out what these three methods are? (Hint: Use the examples in Part 1 to figure out one of the three solutions.) Display reports to show the differences in terms of numbers of key comparisons among these three methods. In this homework, you should at least use the linear method for implementation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!