Question: Write a Python function, median(X, Y), which returns the median of all elements of arrays X and Y, where the sizes of X and Y
Write a Python function, median(X, Y), which returns the median of all elements of arrays X and Y, where the sizes of X and Y are the same and each are sorted. (CLRS Exercise 9.3-8)
Your algorithm should run in O(log n) time, where n is the size of each array. So, you should NOT do linear search. Assume that each list contains at least one number.
def median(X, Y): ### Write Your Code Here ###
median([1], [2]) # return 1.5 median([1, 2], [3, 4]) # returns 2.5 median([1,2,5,7], [2,3,6,9]) # returns 4.0 median([1,2,3,7], [2,5,6,9]) # returns 4.0 median([1,2,5,7,8], [2,3,6,9,10]) # returns 5.5 median([1,2,6,7,8], [2,3,5,8,10]) # returns 5.5 median([1,2,10,100], [1,3,6,9]) # returns 4.5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
