Question: write the code using C++ Question 2. Given two sorted arrays each of size n. Find the median of an array resulting from merging the

write the code using C++

write the code using C++ Question 2. Given two sorted arrays each

Question 2. Given two sorted arrays each of size n. Find the median of an array resulting from merging the two arrays. (Hint: You could use the same approach of binary search algorithm. The time complexity of your solution should be O(logn).) Example 1: a1 = [0, 2, 10, 26, 68), >> median = 10 a2 = (1, 11, 18, 20, 41), >> median = 18 Output: Median = (11+18)/2 = 14.5 Example 2: a1 = [5, 6, 14, 26), >> median = (6+14)/2 = 10 a2 = [3, 41, 88, 100] >> median = (41+88)/2 = 64.5 Output: Median = (14+26)/2 = 20 Example 3: al = [5, 10), a2 = [2, 41] Output: Median = {max(a1[0], a2[0]) + min(a1[1], a2[1])}/2 = {max(5,2)+min(10,41)}/2 = {5+10}/2 = 7.5

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!