Question: Let's consider an n n matrix A whose each row and each column is sorted. That is , A [ i , j ] A
Let's consider an matrix A whose each row and each column is sorted. That is
and Given a number we want to find whether exists
in this matrix or not. We try to generalize the Binary Search algorithm to dimensions. We
use divideandconquer or reduceandconquer approach. Probe the element at the center
of the matrix. Based on the result, eliminate some part of the matrix from your search space
and focus on the parts where your answer could lie.
a Give a pseudocode and English explanation for this algorithm.
b Set up a recurrence for the analysis of running time of this algorithm and obtain the
best possible bigO complexity.
c Is there a better algorithm possible which is based on binary search?
d Is there a better algorithm possible, if we do not use binary search? What is the
minimum number of probes any algorithm must do in the worst case in order to solve
this problem?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
