Multi-Dimensional Arrays, Address Translation & Stack Mechanics
“In Row-Major 2D array A[L1..U1, L2..U2] with element size c: Addr(A[i, j]) = Base + c * [ (i - L1) * (U2 - L2 + 1) + (j - L2) ].”
- —Row-Major 2D: Addr(A[i, j]) = Base + c * [ (i - L1) * N + (j - L2) ] where N = U2 - L2 + 1.
- —Column-Major 2D: Addr(A[i, j]) = Base + c * [ (j - L2) * M + (i - L1) ] where M = U1 - L1 + 1.
- —3D Row-Major: Addr(A[i, j, k]) = Base + c * [ (i - L1)*D2*D3 + (j - L2)*D3 + (k - L3) ].
- —Lower Triangular Matrix (n x n): Stored row-major, element A[i, j] (1-indexed, i >= j) is preceded by i*(i - 1)/2 + (j - 1) elements.
- —Infix-to-Postfix: Incoming operator popped while in-stack operator has >= precedence (left-associative) or > precedence (right-associative).
- —Minimum Stacks to implement Queue = 2 Stacks (Amortized O(1) per operation).
- —Check array indexing lower bounds (0 vs 1 vs negative index bounds like -3..5).
- —Right-associative operators (like exponentiation `^`) have HIGHER incoming precedence than in-stack precedence; identical operators do NOT pop each other.