C program to find the median of two sorted arrays with same using simple merge-based O(n) solution
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Here, we will create two sorted arrays of the same size. And, we used a simple merge-based O(n) solution and print the median on the console screen.
Program:
The source code to find the median of two sorted arrays with the same using a simple merge-based O(n) solution is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
Here, we created two arrays arr1, arr2 with 5 integer elements. And, we find the median of both arrays using the simple merge O(n) method. And, we also checked with the size of both arrays is different, then print the error message, and calculateMedian() function to calculate the median and return the result to the main() function. After that, we printed the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer