|
132 | 132 | **Mathematical formula (3×3)** |
133 | 133 |
|
134 | 134 | $$ |
135 | | -(A^{\mathsf T})_{r,c}=A_{c,r},\quad 0\le r,c<3. |
| 135 | +(A^T)_{r,c}=A_{c,r},\quad 0\le r,c<3 |
136 | 136 | $$ |
137 | 137 |
|
138 | 138 | **Pseudocode (square, in-place)** |
|
168 | 168 | **Mathematical formula (2×3 → 3×2)** |
169 | 169 |
|
170 | 170 | $$ |
171 | | -(A^{\mathsf T})_{r,c}=A_{c,r},\quad 0\le r<3,\ 0\le c<2. |
| 171 | +(A^{\mathsf T})_{r,c}=A_{c,r},\quad 0\le r<3,\ 0\le c<2 |
172 | 172 | $$ |
173 | 173 |
|
174 | 174 | **Pseudocode (rectangular, new matrix)** |
|
213 | 213 | **Mathematical formula (2×3)** |
214 | 214 |
|
215 | 215 | $$ |
216 | | -B_{r,c}=A_{r,\ C-1-c},\quad 0\le r<2,\ 0\le c<3. |
| 216 | +B_{r,c}=A_{r,\ C-1-c},\quad 0\le r<2,\ 0\le c<3 |
217 | 217 | $$ |
218 | 218 |
|
219 | 219 | **Pseudocode (in-place)** |
|
255 | 255 | **Mathematical formula (3×3)** |
256 | 256 |
|
257 | 257 | $$ |
258 | | -B_{r,c}=A_{R-1-r,\ c},\quad 0\le r,c<3. |
| 258 | +B_{r,c}=A_{R-1-r,\ c},\quad 0\le r,c<3 |
259 | 259 | $$ |
260 | 260 |
|
261 | 261 | **Pseudocode (in-place)** |
|
301 | 301 | **Mathematical formula (n×n)** |
302 | 302 |
|
303 | 303 | $$ |
304 | | -B_{r,c}=A_{n-1-c,\ r},\quad 0\le r,c<n. |
| 304 | +B_{r,c}=A_{n-1-c,\ r},\quad 0\le r,c<n |
305 | 305 | $$ |
306 | 306 |
|
307 | 307 | **Pseudocode (square, in-place via basics)** |
|
338 | 338 | **Mathematical formula (R×C → C×R)** |
339 | 339 |
|
340 | 340 | $$ |
341 | | -B_{r,c}=A_{R-1-c,\ r},\quad 0\le r<C,\ 0\le c<R\ \ (R{=}2,\ C{=}3). |
| 341 | +B_{r,c}=A_{R-1-c,\ r},\quad 0\le r<C,\ 0\le c<R\ \ (R{=}2,\ C{=}3) |
342 | 342 | $$ |
343 | 343 |
|
344 | 344 | **Pseudocode (rectangular, direct mapping)** |
|
385 | 385 | **Mathematical formula (n×n)** |
386 | 386 |
|
387 | 387 | $$ |
388 | | -B_{r,c}=A_{c,\ n-1-r},\quad 0\le r,c<n. |
| 388 | +B_{r,c}=A_{c,\ n-1-r},\quad 0\le r,c<n |
389 | 389 | $$ |
390 | 390 |
|
391 | 391 | **Pseudocode (square, via basics)** |
|
446 | 446 | **Mathematical formula (R×C → R×C)** |
447 | 447 |
|
448 | 448 | $$ |
449 | | -B_{r,c}=A_{R-1-r,\ C-1-c},\quad 0\le r<R,\ 0\le c<C. |
| 449 | +B_{r,c}=A_{R-1-r,\ C-1-c},\quad 0\le r<R,\ 0\le c<C |
450 | 450 | $$ |
451 | 451 |
|
452 | 452 | **Pseudocode (in-place via two flips)** |
@@ -526,7 +526,7 @@ top ← left, left ← bottom, bottom ← right, right ← top |
526 | 526 | For an $n\times n$ matrix and a position $(r,c)$ on layer $\ell$, a 90° CW rotation sends |
527 | 527 |
|
528 | 528 | $$ |
529 | | -(r,c)\ \mapsto\ (c,\ n-1-r)\ \mapsto\ (n-1-r,\ n-1-c)\ \mapsto\ (n-1-c,\ r). |
| 529 | +(r,c)\ \mapsto\ (c,\ n-1-r)\ \mapsto\ (n-1-r,\ n-1-c)\ \mapsto\ (n-1-c,\ r) |
530 | 530 | $$ |
531 | 531 |
|
532 | 532 | **Pseudocode (explicit loops, in-place)** |
|
586 | 586 | Let the matrix indices be $(r,c)$ with $0\le r<R,\ 0\le c<C$. For layer $\ell=0,1,\dots,L-1$ where $L=\left\lceil \tfrac{\min(R,C)}{2}\right\rceil$, set |
587 | 587 |
|
588 | 588 | $$ |
589 | | -t=\ell,\quad b=R-1-\ell,\quad left=\ell,\quad rgt=C-1-\ell . |
| 589 | +t=\ell,\quad b=R-1-\ell,\quad left=\ell,\quad rgt=C-1-\ell |
590 | 590 | $$ |
591 | 591 |
|
592 | 592 | Visit, in order: |
|
660 | 660 | Let $s=r+c$. For $s=0,1,\dots,R+C-2$, define |
661 | 661 |
|
662 | 662 | $$ |
663 | | -r_{\min}(s)=\max\!\big(0,\ s-(C-1)\big),\qquad |
664 | | -r_{\max}(s)=\min\!\big(R-1,\ s\big). |
| 663 | +r_{\min}(s)=\max\!\big(0,\ s-(C-1)\big) |
| 664 | +$$ |
| 665 | + |
| 666 | +$$ |
| 667 | +r_{\max}(s)=\min\!\big(R-1,\ s\big) |
665 | 668 | $$ |
666 | 669 |
|
667 | 670 | The diagonal set is $\{(r,s-r)\mid r_{\min}(s)\le r\le r_{\max}(s)\}$. |
| 671 | + |
668 | 672 | Traverse with alternating direction: |
669 | 673 |
|
670 | 674 | $$ |
@@ -708,6 +712,7 @@ Each cell is a node; edges connect neighboring walkable cells. |
708 | 712 | **Grid-as-graph view (4-dir edges).** Each cell is a node; edges connect neighbors that are “passable”. Great for BFS shortest paths on unweighted grids. |
709 | 713 |
|
710 | 714 | **Example map (walls `#`, free `.`, start `S`, target `T`).** |
| 715 | + |
711 | 716 | Left: the map. Right: BFS distances (4-dir) from `S` until `T` is reached. |
712 | 717 |
|
713 | 718 | ``` |
|
772 | 777 |
|
773 | 778 | Push S to a queue, expand in 4-dir layers, track distance/visited; stop when T is dequeued. |
774 | 779 |
|
775 | | -* Time: $O(R\cdot C)$; Space: $O(R\cdot C)$. |
| 780 | +* Time: $O(R\cdot C)$ |
| 781 | +* Space: $O(R\cdot C)$ |
776 | 782 |
|
777 | 783 | #### Connected Components (Islands) |
778 | 784 |
|
|
0 commit comments