1 votes 1 votes Let $A$ be an $n\times n $ matrix of integers such that each row and each column is arranged in ascending order. We want to check whether a number $k$ appears in $A.$ If $k$ is present, we should report its position - that is, the row $i$ and column $j$ such that $A(i,j)=k.$ Otherwise, we should declare that $k$ is not present in $A.$ Describe an algorithm that solves this problem in time $O(n\log n).$ Justify the complexity of your algorithm. Describe an algorithm that solves this problem by examining at most $2n$ values in $A.$ Justify the complexity of your algorithm. For both algorithms, describe a worst-case input where $k$ is present in $A.$ Algorithms cmi2019 algorithms algorithm-design descriptive + – gatecse asked Sep 13, 2019 • edited Nov 16, 2019 by Lakshman Bhaiya gatecse 698 views answer comment Share Follow See 1 comment See all 1 1 comment reply s_dr_13 commented Apr 4, 2022 reply Follow Share This exact question was asked in JEST 2022 in TCS exam 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes (a) Since, each row is sorted in the ascending order therefore we can use Binary search on each row, which works in $O(logn)$ time. For $n$ rows, time complexity $=$ $O(nlogn)$ PS will write b and c by evening. `JEET answered Sep 17, 2019 `JEET comment Share Follow See 1 comment See all 1 1 comment reply Priyansh Singh commented Aug 8, 2020 reply Follow Share (1) is kind of Peak finding question just with a little variation , we can do it in O(logN * logM) time where N,M are rows and column of matrix. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Answer: soujanyareddy13 answered May 4, 2021 soujanyareddy13 comment Share Follow See all 0 reply Please log in or register to add a comment.