<?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[TechVani Notes]]></title><description><![CDATA[TechVani Notes]]></description><link>https://techvani.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>TechVani Notes</title><link>https://techvani.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 18:35:53 GMT</lastBuildDate><atom:link href="https://techvani.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Python generators and yield: a short guide with tested examples]]></title><description><![CDATA[Generators show up in Python exams, interviews and real projects, and most students only half remember them. Here is the short version, with output I ran on Python 3.10.
A function that remembers wher]]></description><link>https://techvani.hashnode.dev/python-generators-and-yield-a-short-guide-with-tested-examples</link><guid isPermaLink="true">https://techvani.hashnode.dev/python-generators-and-yield-a-short-guide-with-tested-examples</guid><category><![CDATA[Python]]></category><category><![CDATA[python beginner]]></category><dc:creator><![CDATA[Aditya]]></dc:creator><pubDate>Wed, 14 Oct 2026 05:57:34 GMT</pubDate><content:encoded><![CDATA[<p>Generators show up in Python exams, interviews and real projects, and most students only half remember them. Here is the short version, with output I ran on Python 3.10.</p>
<h2>A function that remembers where it stopped</h2>
<pre><code class="language-python">def squares(n):
    for i in range(n):
        yield i * i

g = squares(4)
print(next(g), next(g))   # 0 1
print(list(g))            # [4, 9]
print(list(g))            # []
</code></pre>
<p><code>yield</code> pauses the function and hands back one value. The next <code>next()</code> call resumes from the same line. After the last value the generator is used up, so the second <code>list(g)</code> is empty. This is the classic exam trap: a generator can be consumed only once.</p>
<h2>Why use one: memory</h2>
<pre><code class="language-python">import sys
sys.getsizeof([i for i in range(100000)]) &gt; sys.getsizeof((i for i in range(100000)))
# True
</code></pre>
<p>A list comprehension builds all 100000 values at once. A generator expression keeps only its current state and makes each value when asked.</p>
<h2>Infinite sequences</h2>
<pre><code class="language-python">from itertools import islice

def evens():
    n = 0
    while True:
        yield n
        n += 2

print(list(islice(evens(), 5)))   # [0, 2, 4, 6, 8]
</code></pre>
<p>This would never finish as a list. As a generator it is fine, because you take only what you need.</p>
<h2>What a for loop really does</h2>
<pre><code class="language-python">it = iter([10, 20])
print(next(it), next(it))   # 10 20
try:
    next(it)
except StopIteration:
    print("StopIteration")
</code></pre>
<p>A <code>for</code> loop calls <code>iter()</code> once, then <code>next()</code> again and again, and stops quietly when <code>StopIteration</code> is raised.</p>
<h2>Quick rules</h2>
<ul>
<li>Use a generator when you read data once, in order, and it may be large.</li>
<li>Use a list when you need indexing, <code>len()</code> or several passes.</li>
<li>A generator that you loop over twice gives nothing the second time.</li>
</ul>
<p>A longer version with 8 tested examples and exam questions is on the TechVani notes site: <a href="https://techvaniai.blogspot.com/2026/10/python-iterators-generators-yield-lazy-8-tested.html">Python Iterators and Generators: yield, Lazy Evaluation and 8 Tested Examples</a></p>
]]></content:encoded></item><item><title><![CDATA[Time complexity: loops and the master theorem, quick guide]]></title><description><![CDATA[Most time complexity questions in exams reduce to two skills: counting how many times a loop body runs, and solving a recurrence.
Loops

A loop for (i = 1; i <= n; i++) runs n times, so O(n).
A loop w]]></description><link>https://techvani.hashnode.dev/time-complexity-loops-and-the-master-theorem-quick-guide</link><guid isPermaLink="true">https://techvani.hashnode.dev/time-complexity-loops-and-the-master-theorem-quick-guide</guid><category><![CDATA[algorithms]]></category><dc:creator><![CDATA[Aditya]]></dc:creator><pubDate>Mon, 05 Oct 2026 05:10:55 GMT</pubDate><content:encoded><![CDATA[<p>Most time complexity questions in exams reduce to two skills: counting how many times a loop body runs, and solving a recurrence.</p>
<p><strong>Loops</strong></p>
<ul>
<li>A loop <code>for (i = 1; i &lt;= n; i++)</code> runs n times, so O(n).</li>
<li>A loop where i doubles each step (<code>i = i * 2</code>) runs about log2(n) times, so O(log n).</li>
<li>Nested loops multiply, but only if the inner count does not depend on the outer variable in a way that changes the sum. For <code>for i in 1..n</code> with inner <code>for j in 1..i</code>, the total is n(n+1)/2, which is O(n^2).</li>
</ul>
<p><strong>Recurrences (master theorem)</strong>
For T(n) = a T(n/b) + f(n), compare f(n) with n^(log_b a):</p>
<ul>
<li>If f(n) is smaller by a polynomial factor, T(n) = Theta(n^(log_b a)).</li>
<li>If they are the same order, T(n) = Theta(n^(log_b a) log n).</li>
<li>If f(n) is larger (and the regularity condition holds), T(n) = Theta(f(n)).</li>
</ul>
<p>Example: T(n) = 2T(n/2) + n. Here n^(log_2 2) = n, same order as f(n), so T(n) = Theta(n log n), which is merge sort.</p>
<p>I solved 6 more loop and recurrence problems step by step on my blog TechVani (originally published there): <a href="https://techvaniai.blogspot.com/2026/10/time-complexity-questions-6-solved-loop.html">https://techvaniai.blogspot.com/2026/10/time-complexity-questions-6-solved-loop.html</a></p>
]]></content:encoded></item><item><title><![CDATA[Deadlock in 4 checks: a quick way to solve exam problems]]></title><description><![CDATA[Deadlock questions are easier when you check four conditions in order. A deadlock needs all four at once: mutual exclusion, hold and wait, no preemption, and circular wait. Break any one and the deadl]]></description><link>https://techvani.hashnode.dev/deadlock-in-4-checks-a-quick-way-to-solve-exam-problems</link><guid isPermaLink="true">https://techvani.hashnode.dev/deadlock-in-4-checks-a-quick-way-to-solve-exam-problems</guid><dc:creator><![CDATA[Aditya]]></dc:creator><pubDate>Thu, 01 Oct 2026 18:39:21 GMT</pubDate><content:encoded><![CDATA[<p>Deadlock questions are easier when you check four conditions in order. A deadlock needs all four at once: mutual exclusion, hold and wait, no preemption, and circular wait. Break any one and the deadlock cannot happen.</p>
<p>A quick worked example. Two processes, two resources. P1 holds R1 and waits for R2. P2 holds R2 and waits for R1. Draw the wait-for graph: P1 -&gt; P2 -&gt; P1. That cycle is the circular wait, and since each resource has one instance, a cycle means deadlock.</p>
<p>How to prevent it in practice: make every process request resources in one fixed order (this kills circular wait), or make a process request everything up front (this kills hold and wait).</p>
<p>For the Banker's algorithm, keep a table of Allocation, Max and Available. Compute Need = Max - Allocation, then look for any process whose Need fits in Available. Run it, add its Allocation back to Available, and repeat. If you can finish all processes this way, the state is safe.</p>
<p>I covered this and other OS topics (processes, scheduling, memory, file systems) in a 96 minute Hinglish revision video: <a href="https://www.youtube.com/watch?v=RSR2sqyR5pE">https://www.youtube.com/watch?v=RSR2sqyR5pE</a></p>
<p>More notes on Telegram: <a href="https://t.me/techvaniai">https://t.me/techvaniai</a></p>
]]></content:encoded></item></channel></rss>