TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: References for Lower Triangular Matrix column major?

1 pointsby shivajikobardan9 months ago
I am studying data structures&#x2F;compiler design. And I am surprised that I can&#x27;t find much reputed resources for learning LTM Column Major. There are books like sartaj sahni and debasis samnatha which lightly present this.<p>I google<p>filetype:pdf &quot;row-major order&quot; compiler design OR data structures &quot;column-major order&quot;<p>Still I didn&#x27;t get accurate results.<p>Theere are some trash videos on youtube, and almost everyone is deriving hacky way. I want a mathematical way of deriving the address calculation. I would love if they&#x27;re using different techniques to calculate the address.

2 comments

Someone9 months ago
&gt; I want a mathematical way of deriving the address calculation<p>So, filling in some blanks, you<p>- want to store the lower triangular matrix as a single contiguous array of <i>n × (n+1) ÷ 2</i> items<p>- don’t want to store an additional array of column offsets<p>and hence need a way to compute an offset into that contiguous array from <i>(row,column)</i> coordinates with <i>row ≥ column</i> (elsewhere, the matrix contains zeroes)<p>I first would consider storing the columns in reverse order, as that would mean storing<p>- 1 item for the last column<p>- 2 items for the next-to-last<p>- …<p>- <i>n</i> items for the first column<p>Offsets then are 1, 3, 6, 10, etc. Those are the triangular numbers (<a href="https:&#x2F;&#x2F;oeis.org&#x2F;A000217" rel="nofollow">https:&#x2F;&#x2F;oeis.org&#x2F;A000217</a>)<p>Calculation of the column offset then would be (counting rows and columns from <i>1</i> to <i>n</i>; untested, so chances are there is an off-by-one error there somewhere)<p><pre><code> (n - column) × (n - column + 1) ÷ 2 </code></pre> If you don’t want to reverse column order, I think it’s easiest to think of the problem as computing an offset from the end of the array:<p>- to find the column offset, you have to move back from there by <i>(n - column)</i> columns<p>- so, you have to move back <i>1 + 2 + 3 + … + (n - column)</i> items<p>- that’s <i>(n - column) × (n - column + 1) ÷ 2</i> items.<p>The offset from the start would be <i>n × (n - 1) ÷ 2)</i> minus that.
yorwba9 months ago
Start with small matrices (1×1, 2×2, 3×3, ...), do the calculations by hand to gain some intuition, come up with a generalization to n×n matrices, prove it by induction.