<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Daksh Goel Blogs]]></title><description><![CDATA[Just learning and growing........]]></description><link>https://ug-beast.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6aa6c59155fd9b74c5bdb60e/5d386295-b474-4085-9c52-57e309a63f45.png</url><title>Daksh Goel Blogs</title><link>https://ug-beast.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 07:28:34 GMT</lastBuildDate><atom:link href="https://ug-beast.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Why contiguous Data Structures (DS) are faster than non-contiguous DS]]></title><description><![CDATA[Summary:
The massive performance gap between contiguous DS and node-base structures is due to CPU Cache lines and spatial locality.
Deep Dive:
RAM Bottleneck:
CPU is very fast, but RAM is slow. To pre]]></description><link>https://ug-beast.hashnode.dev/why-contiguous-data-structures-ds-are-faster-than-non-contiguous-ds</link><guid isPermaLink="true">https://ug-beast.hashnode.dev/why-contiguous-data-structures-ds-are-faster-than-non-contiguous-ds</guid><dc:creator><![CDATA[Daksh Goel]]></dc:creator><pubDate>Sun, 20 Sep 2026 08:46:22 GMT</pubDate><content:encoded><![CDATA[<h2>Summary:</h2>
<p>The massive performance gap between contiguous DS and node-base structures is due to CPU Cache lines and spatial locality.</p>
<h2>Deep Dive:</h2>
<h3>RAM Bottleneck:</h3>
<p>CPU is very fast, but RAM is slow. To prevent CPU from idling, CPU is fitted with CPU Caches (L1, L2, L3).</p>
<p>This includes 2 major things:</p>
<ul>
<li><p>Spatial Locality: States that, if a program accesses a specific memory address, it will almost certainly need the data at the immediately adjacent address very soon.</p>
</li>
<li><p>Cache Lines: Because of spatial locality, CPU grabs a fixed-size block of contiguous memory all at once. Generally it's 64 bytes long contiguous block in modern machines.</p>
</li>
</ul>
<h3>Contiguous Memory DS (eg. Arrays):</h3>
<p>Perfect spatial locality.</p>
<p>When you read the first item (say, 4-byte integer) in an array, the CPU fetches a 64-byte cache line from RAM. This brings first integer + the next 15 integer immediately. When the loop moves to the 2nd, 3rd, ..... items, the CPU doesn't have to wait for RAM; the data is already present in the L1-cache (a cache hit). You only suffer a slow RAM fetch once every 16 steps.</p>
<h3>Non-contiguous Memory DS (eg. Linked List):</h3>
<p>Linked List nodes are dynamically allocated, meaning they are scattered randomly across the heap wherever there happens to be free space.</p>
<p>When you ask for the first node, the CPU fetches a 64-byte cache line from RAM. However, because the next node is stored at a completely different, random memory address, the rest of that cache line is filled with unrelated data.</p>
<p>When we follow pointer to 2nd node, the CPU discovers it isn't in the cache (a cache miss). It has to make a slow trip to RAM again. We have to pay the massive latency penalty on almost every step, making linked list traversal slower regardless of theoretical speed.</p>
]]></content:encoded></item><item><title><![CDATA[Batch Norm vs Layer Norm]]></title><description><![CDATA[Summary:

Batch Norm -> normalizing each feature across batch.

Layer Norm -> normalizing the values of each individual example independently.


Deep Dive:
Suppose we have 4 students (examples / rows)]]></description><link>https://ug-beast.hashnode.dev/batch-norm-vs-layer-norm</link><guid isPermaLink="true">https://ug-beast.hashnode.dev/batch-norm-vs-layer-norm</guid><dc:creator><![CDATA[Daksh Goel]]></dc:creator><pubDate>Sun, 13 Sep 2026 17:03:50 GMT</pubDate><content:encoded><![CDATA[<h2>Summary:</h2>
<ul>
<li><p>Batch Norm -&gt; normalizing each feature across batch.</p>
</li>
<li><p>Layer Norm -&gt; normalizing the values of each individual example independently.</p>
</li>
</ul>
<h2>Deep Dive:</h2>
<p>Suppose we have 4 students (examples / rows) and 3 subjects (features), say:</p>
<table>
<thead>
<tr>
<th>Student</th>
<th>Math</th>
<th>DSA</th>
<th>ML</th>
</tr>
</thead>
<tbody><tr>
<td>A</td>
<td>2</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td>B</td>
<td>1</td>
<td>3</td>
<td>5</td>
</tr>
<tr>
<td>C</td>
<td>18</td>
<td>12</td>
<td>24</td>
</tr>
<tr>
<td>D</td>
<td>5</td>
<td>10</td>
<td>22</td>
</tr>
</tbody></table>
<p>Note: analogous to NN tensor: 4 examples * 3 features</p>
<h2>Batch Normalization (feature view):</h2>
<blockquote>
<p><em><strong>Analogy: "How did everyone do on the Math test?"</strong></em></p>
</blockquote>
<ul>
<li><p>Batch Norm looks at each feature separately:</p>
<ul>
<li><p>For math: <code>[2, 1, 18, 5]</code></p>
</li>
<li><p>For DSA: <code>[4, 3, 12, 10]</code></p>
</li>
<li><p>For ML: <code>[3, 5, 24, 22]</code></p>
</li>
</ul>
</li>
</ul>
<h3>How it works:</h3>
<ul>
<li><p>It calculates the mean for a specific subject across all students:</p>
<ul>
<li><p>mean_math</p>
<p>$$[ \mu_{\text{math}}=\frac{2+1+18+5}{4} ]$$</p>
</li>
</ul>
</li>
<li><p><code>var_math</code>:</p>
</li>
</ul>
<p>$$[ \sigma_{\text{math}}^2= \frac{1}{4}\sum_{i=1}^{4}(x_i-\mu_{\text{math}})^2 ]$$</p>
<ul>
<li>It repeats this for DSA and ML to get <code>mean_dsa</code>, <code>var_dsa</code>, etc.</li>
</ul>
<h2>Layer Normalization (Row view):</h2>
<blockquote>
<p>Analogy: "How did Student A perform overall across all their subjects?"</p>
</blockquote>
<ul>
<li><p>Layer Norm looks at each example separately:</p>
<ul>
<li><p>For A -&gt; <code>[2, 4, 3]</code></p>
</li>
<li><p>For B -&gt; <code>[1, 3, 5]</code></p>
</li>
<li><p>For C -&gt; <code>[18, 12, 24]</code></p>
</li>
<li><p>For D -&gt; <code>[5, 10, 22]</code></p>
</li>
</ul>
</li>
</ul>
<h3>How it works</h3>
<ul>
<li>mean_A:</li>
</ul>
<p>$$[ \mu_A=\frac{2+4+3}{3} ]$$</p>
<ul>
<li>var_A:</li>
</ul>
<p>$$[ \sigma_A^2= \frac{(2-\mu_A)^2+(4-\mu_A)^2+(3-\mu_A)^2}{3} ]$$</p>
<ul>
<li>It repeats this independently for students B, C, and D.</li>
</ul>
<h3>The Engine: Z-Score Normalization</h3>
<p>Both norm's used Z-Score normalization only.</p>
<p>$$[ \hat{x} = \frac{x-\mu}{\sqrt{\sigma^2+\epsilon}} ]$$</p>
<p>Note: <code>epsilon</code> is added to avoid divide by zero error. <code>Its a very small value</code>.</p>
<h2>When to use what?</h2>
<h3>Layer Norm:</h3>
<p>Use LayerNorm when we want to normalize each example independently, without depending on other examples in the batch.</p>
<p>This is especially useful in sequence models, where each token has its own hidden representation.</p>
<p><code>Generally used in: Transformers, LLMs, RNNs, LSTMs, GRUs, Vision Models.</code></p>
<h3>Batch Norm:</h3>
<p>Use BatchNorm when batch-level statistics are meaningful and useful for training.</p>
<p><code>Generally used in: CNNs, ResNet-style architectures, Image classification, Object detection, Image segmentation.</code></p>
]]></content:encoded></item></channel></rss>