Question: Suppose A is a matrix with n rows and n columns. Further suppose that A is sorted both by rows and by columns i.e. within
Suppose A is a matrix with n rows and n columns. Further suppose that A is sorted both by rows and by columns i.e. within any row, the elements are increasing from left to right, and within any column, the elements are increasing from top to bottom. We want to determine if a number k is one of the entries in A.The obvious way of doing this would look at all n 2 entries of A, but you have to do better i.e. come up with a more efficient algorithm.
1. Give a clear description of your algorithm for the above problem.
2. Show how your algorithm works on two examples, one where the answer is YES, another where the answer is NO.
3. Do a worst case time analysis (use big O notation) of your algorithm.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
