<?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[Akshay Tiwari's team blog]]></title><description><![CDATA[Akshay Tiwari's team blog]]></description><link>https://akshaytiwari.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 19 Oct 2026 19:05:53 GMT</lastBuildDate><atom:link href="https://akshaytiwari.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Time & Space Complexity 101 : Beginners POV]]></title><description><![CDATA[Understanding “Complexity”
It starts with “Why complexity exists? and is it important?”. It exists because of mathematics. Let me cook, in general terms when we here the term “complexity”? We here it for the first time in our Data Structures and Algo...]]></description><link>https://akshaytiwari.hashnode.dev/time-and-space-complexity-101-beginners-pov</link><guid isPermaLink="true">https://akshaytiwari.hashnode.dev/time-and-space-complexity-101-beginners-pov</guid><category><![CDATA[data structures]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[Concepts]]></category><dc:creator><![CDATA[Akshay]]></dc:creator><pubDate>Sun, 04 Jan 2026 10:40:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767522947173/bf74ff05-bd00-4394-9971-6f249e2d1ba1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-understanding-complexity">Understanding “Complexity”</h2>
<p>It starts with “<em>Why complexity exists? and is it important?</em>”. It exists because of mathematics. Let me cook, in general terms when we here the term “<em>complexity</em>”? We here it for the first time in our Data Structures and Algorithms course. So one thing is clear that it it related to Algorithms because Data Structures are used to store data there is no rocket science in that. Now to generalize Algorithms I can call all the algorithms “programs” because that’s what it is. The work of a program is to take input and produce some output, so if i try to reason on how can <strong>work</strong> of a program grow, the only option is to increase the size of my input. How does one track “<em>how much has the work program grown?</em>” because there is nothing to measure it. This led to the birth of complexity which measures the <strong>growth pattern</strong> of a program under huge load of work. So where does the mathematics part ? Here : when we try to compute complexity of any program, it will be dependent on that machine, which will be inaccurate. Why, because my decade old samsung laptop can’t compete with someone’s latest macbook pro with latest chip and highest specs. So what computer scientist did is they made this concept <strong>machine-independent</strong> (<em>laptop, desktop or servers</em>). There are some <strong>basic operations</strong> in every program like <em>variables, comparisions, loops etc</em>. We can just count these on pen and paper and calculate complexity of any program. It is just really a theoretical lens.</p>
<h2 id="heading-evolving-to-time-complexity">Evolving to Time Complexity</h2>
<p>Remember I talked about <strong>growth of work</strong> of program, and as the work grows it is certain that the <strong>time taken</strong> by program will also grow. So the first question comes to my mind is <em>why do we calculate time?</em> Simple answer is computers have limited time(<em>CPUs can do only so many steps per second</em>) then next question arises <em>how do we calculate this time? In seconds</em>? Like “this particular program took 2 seconds to complete this task”. But it isn’t going to work because same principle: every machine is different, every programming is different, CPUs is going to evolve so this time is definitely going to reduce. So seconds are unreliable. We need something <strong>machine-independent</strong>. This thinking leads to <strong>Time Complexity.</strong></p>
<h2 id="heading-flipping-to-space-complexity">Flipping to Space Complexity</h2>
<p>Time matters but what about <strong>memory</strong>(in computer science whenever we talk about memory, we are referring to RAM), just like time computers have <em>limited memory</em>. In a similar fashion to time complexity, when we think of memory for a program, this leads to <strong>Space complexity</strong>, which is definately not calculated in <strong>megabytes</strong>(MBs).</p>
<h2 id="heading-why-big-o-was-chosen">Why Big-O was chosen ?</h2>
<p>Since i was studying this topic, I came to know that there isn’t any formula for time and space complexity, and it seems counter intuitive to me because through out life if something comes under the umbrella of maths it should have formula to calculate it. But that is not the case for complexity. When I dig deeper, I found some problems:</p>
<ul>
<li>Exact formula depends on machine: Which is definitely not acceptable since we discussed it already that we need something machine-independent. For instance, let’s say that you wrote a program(Algorithm) and it takes 3n + 5 operations on your laptop. Ask yourself a question “what is one operation?” is it one cpu cycle, one line of code or one assembly instruction. Different machine answer differently. So its not going to take 3n + 5 operations on my laptop, it could be more or less.</li>
</ul>
<p>Constant stop mattering as input grows: Suppose I have written 2 algorithms “Algo A” and “Algo B”. Algo A takes 3n+10 operations and Algo B takes n2 operations. For very large n, which one explodes? when n = 10:<br />A ⇒ 40<br />B ⇒ 100</p>
<p>but when n = 1,000,000</p>
<p>A ⇒ 3,000,010</p>
<p>B ⇒ 1,000,000,000,000</p>
<p>So in this case +10 and x3 doesn’t matter anymore. The actual thing we care about is “<em>How does this algorithm behaves when input becomes huge?</em>” not exact time, exact steps, exact constants. So to avoid all these pain computer scientist introduced Big-O which can be calculated on pen and paper. It stays <strong>stable</strong>, is <strong>machine-independent</strong> and answers <strong>growth rate</strong>. And when we compare 2 different algorithms that’s where it helps. Big-O gives a rough idea on performance of algorithms.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>We are:</p>
<ul>
<li><p>abstracting away details</p>
</li>
<li><p>focusing on growth</p>
</li>
<li><p>modeling behavior mathematically</p>
</li>
</ul>
<p>Hope I was able to add value to your today’s learning goal !! Happy Learning ..</p>
]]></content:encoded></item></channel></rss>