Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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++

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago