Question: We are given a table A of size n by n such that each row and each column is sorted. In other words, for

We are given a table A of size n by n such that each row and each column is sorted. In other words, for each i, j = {1,... n}, and any i' > i,j' > j, we have that A[i, j] < A[i, j] and A[i, j] < A[i, j']. Furthermore, assume for simplicity that all the entries of A are distinct and are from the range [1, n]. Design an algorithm for finding the median (element of rank n/2) of A in O(nlogn) time (partial credit will be given for solutions achieving O(n log n) time). In particular, you can consider the following two steps: a) Design an algorithm that, given x = [1,4], outputs the number of entries in A that are smaller than or equal to x. Your algorithm should run in O(n) time (O(nlogn) time will get partial credit). b) Now design an algorithm for the overall problem running in O(nlogn) time.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
