13.1 Rectilinear Grids

Traversal and indexing:

Row-Wise

|---|---|---|--|
|-1-|2--|3--|4-|
| 5 |6  |7  |8 |
|---|---|---|--|
| 9 |10 |11 |12|
|---|---|---|--|
|13-|14-|15-|16|

n = (r - 1) * C + c

(r,c) = (n/C,n%C)

Snake

|---|---|---|--|
|-1-|2--|3--|4-|
| 8 |7  |6  |5 |
|---|---|---|--|
| 9 |10 |11 |12|
|---|---|---|--|
|16-|15-|14-|13|

Diagonal

|---|---|---|--|
|-1-|3--|6--|10|
| 2 |5  |9  |13|
|---|---|---|--|
| 4 |8  |12 |15|
|---|---|---|--|
|-7-|11-|14-|16|