One search for a whole grid.
transcript
A grid of 250,000 cells. The rows chain in order. Scanning is slow. One search is enough. Let me show you the map.
Treat the grid as one line. The row is p divided by cols. The column is p modulo cols. The divisor is the row width. Test it on a small grid first. A wrong divisor shows at once.
Search for eighteen. The middle holds fourteen. Go right. Position eight holds eighteen. Row two, column zero. Four steps found it in twelve cells. Eight divided by four is two.
Divide by the row width. Dividing by the row count is wrong. Use the number of columns. A three by four grid shows the mistake at once.
Five hundred by five hundred. Eighteen steps in all. Scanning would read two hundred fifty thousand cells.
Name the order first. Divide by the row width. Test a three by four grid. Full breakdown in the lecture.