Question
Suppose that you are given an m*n grid of integers where each row and each column are in sorted order (we'll call this a sorted
Suppose that you are given an m*n grid of integers where each row and each column are in sorted order (we'll call this a sorted grid). For example:
10 12 13 21 32 34 43 51 67 69 90 101 133
16 21 23 26 40 54 65 67 68 71 99 110 150
21 23 31 33 54 58 74 77 97 98 110 111 150
32 46 59 65 74 88 99 103 113 125 137 149 159
53 75 96 115 124 131 132 136 140 156156 157 161
84 86 98 145 146 151 173 187 192 205 206 208 219
135 141 153 165 174181 194 208 210 223 236 249 258
216 220 222 225 234 301 355 409 418 446 454 460 541
Design an O(m + n)-time algorithm that, given as input a sorted m n grid and an integer, returns whether or not that integer is contained in the grid. Your algorithm should use only O(1) additional space. Then: Describe your algorithm. Prove that your algorithm is correct. Prove that your algorithm runs in time O(m + n) and uses O(1) additional space.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started