<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vaibhavi Maradiya on Medium]]></title>
        <description><![CDATA[Stories by Vaibhavi Maradiya on Medium]]></description>
        <link>https://medium.com/@vaibhavimaradiya17?source=rss-abcfe10d0649------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IHRSnHVR64-Bm5Vc</url>
            <title>Stories by Vaibhavi Maradiya on Medium</title>
            <link>https://medium.com/@vaibhavimaradiya17?source=rss-abcfe10d0649------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:44:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vaibhavimaradiya17/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Time Complexity of Algorithms]]></title>
            <link>https://medium.com/@vaibhavimaradiya17/time-complexity-of-algorithms-e3ace79299b2?source=rss-abcfe10d0649------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3ace79299b2</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Vaibhavi Maradiya]]></dc:creator>
            <pubDate>Sun, 08 Sep 2019 10:08:54 GMT</pubDate>
            <atom:updated>2019-09-08T10:08:54.465Z</atom:updated>
            <content:encoded><![CDATA[<p>For any defined problem, there can be N number of solution. And we have to decide which solution is the best based on the circumstances. Similarly for any problem which must be solved using a program, there can be infinite number of solutions.</p><p>the <strong>time complexity</strong> is the computational complexity that describes the amount of time it takes to run an algorithm.</p><p>Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm to finish execution, supposing that each elementary operation takes a fixed amount of time to perform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*wflSxpIgWRJ7jCtyKx2oKw.jpeg" /></figure><p>Since the algorithm’s performance may vary with different types of input data, hence for an algorithm we usually use the <strong>worst-case Time complexity</strong> of an algorithm because that is the maximum time taken for any input size.</p><p>The time complexity of algorithms is most commonly expressed using the <strong>big O notation</strong>. It’s an asymptotic notation to represent the time complexity.</p><p>For example, an algorithm with time complexity O(n) is a <em>linear time algorithm</em> and an algorithm with time complexity O(n^k) for some constant k&gt;1 is a <em>polynomial time algorithm</em>.</p><h3>Types of Notations for Time Complexity :</h3><ol><li><strong>Big Oh</strong> denotes “<em>fewer than or the same as</em>” &lt;expression&gt; iterations.</li><li><strong>Big Omega</strong> denotes “<em>more than or the same as</em>” &lt;expression&gt; iterations.</li><li><strong>Big Theta</strong> denotes “<em>the same as</em>” &lt;expression&gt; iterations.</li><li><strong>Little Oh</strong> denotes “<em>fewer than</em>” &lt;expression&gt; iterations.</li><li><strong>Little Omega</strong> denotes “<em>more than</em>” &lt;expression&gt; iterations.</li></ol><h3>Understanding Notations of Time Complexity :</h3><p><strong>O(expression)</strong> : It indicates the maximum required by an algorithm for all input values. It represents the worst case of an algorithm’s time complexity.</p><p><strong>Omega(expression) : </strong>It indicates the minimum time required by an algorithm for all input values. It represents the best case of an algorithm’s time complexity.</p><p><strong>Theta(expression): </strong>It indicates the average bound of an algorithm. It represents the average case of an algorithm’s time complexity.</p><h3>Calculating Time Complexity :</h3><p>Now the most common metric for calculating time complexity is Big O notation. This removes all constant factors so that the running time can be estimated in relation to <strong>N</strong>, as N approaches infinity. In general you can think of it like this :</p><h4>statement;</h4><p>Above we have a single statement. Its Time Complexity will be <strong>Constant</strong>. The running time of the statement will not change in relation to N.</p><p><strong>Example 1.</strong></p><p>for( int i = 0 ; i &lt; N ; i++ )</p><p>{ statement; }</p><p>The time complexity for the above algorithm will be <strong>Linear</strong>. The running time of the loop is directly proportional to N. When N doubles, so does the running time.</p><p><strong>Example 2.</strong></p><p>for( int i = 0 ; i &lt; N ; i ++) {</p><p>for( int i = 0 ; j &lt; N ; j ++) {</p><p>Statement; } }</p><p>This time, the time complexity for the above code will be <strong>Quadratic</strong>. The running time of the two loops is proportional to the square of N. When N doubles, the running time increases by N * N.</p><p><strong>Example 3.</strong></p><p>An algorithm is said to take <strong>logarithmic time</strong> when <em>T</em>(<em>n</em>) = <strong>O(log <em>n</em>).</strong></p><p><strong>while(low &lt;= high) <br>{<br> mid = (low + high) / 2;<br> if (target &lt; list[mid])<br> high = mid - 1;<br> else if (target &gt; list[mid])<br> low = mid + 1;<br> else break;<br>}</strong></p><p>This is an algorithm to break a set of numbers into halves, to search a particular field. Now, this algorithm will have a <strong>Logarithmic</strong> Time Complexity. The running time of the algorithm is proportional to the number of times N can be divided by 2(N is high-low here). This is because the algorithm divides the working area in half with each iteration.</p><p><strong>Complexity of sorting algorithms :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*89cXTUbz1HKou0J1e3CdQQ.png" /></figure><blockquote>References “Wikipedia” and “Studytonight.com”</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3ace79299b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Matrix chain Multiplication]]></title>
            <link>https://medium.com/@vaibhavimaradiya17/matrix-chain-multiplication-bd4604c3b27a?source=rss-abcfe10d0649------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd4604c3b27a</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Vaibhavi Maradiya]]></dc:creator>
            <pubDate>Tue, 03 Sep 2019 04:26:08 GMT</pubDate>
            <atom:updated>2019-09-08T06:36:03.141Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Matrix chain multiplication</strong> is an optimization problem that can be solved using <strong>dynamic programming</strong>. Given a sequence of matrices, the goal is to find the most efficient way to multiply these matrices.</p><p>Here, Chain means one matrix’s column is equal to the second matrix’s row.</p><blockquote>A is a p x q matrix <br> B is a q x r matrix<br> C is a p x r matrix</blockquote><p>We have many options to multiply a chain of matrices because Matrix Multiplication operation is <strong>associative</strong> in nature rather commutative. In other words, no matter how we parenthesize the product, the result will be the same.For example, if we want to multiply above 3 matrices we would have :</p><p>A(BC) = (AB)C</p><p>If we had four matrices A, B, C, and D, we would have:</p><p>(ABC)D = (AB)(CD) = A(BCD) = A(BC)D</p><p>To find the best possible way to calculate the product, we could simply parentheses the expression in every possible fashion and count each time how many scalar multiplication are required.However, the order in which we parenthesize the product affects the number of simple arithmetic operations needed to compute the product, or the efficiency. For example, if <em>A</em> is a 10 × 30 matrix, <em>B</em> is a 30 × 5 matrix, and <em>C</em> is a 5 × 60 matrix, then</p><p>computing (<em>AB</em>)<em>C</em> needs (10×30×5) + (10×5×60) = 1500 + 3000 = 4500 operations,</p><p>while computing <em>A</em>(<em>BC</em>) needs (30×5×60) + (10×30×60) = 9000 + 18000 = 27000 operations.</p><p>Clearly the first method is more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*lba9AdXvk2XctGKLbaNifA.gif" /><figcaption>example of Matrix chain multiplication</figcaption></figure><h3>Dynamic Programming Approach</h3><p>Dynamic Programming solution involves breaking up the problems into subproblems whose solution can be combined to solve the global problem.</p><p>let us assume that all we really want to know is the minimum cost, or minimum number of arithmetic operations needed to multiply out the matrices. If we are only multiplying two matrices, there is only one way to multiply them, so the minimum cost is the cost of doing this. In general, we can find the minimum cost using the following recursive algorithm:</p><ul><li>Take the sequence of matrices and separate it into two subsequences.</li><li>Find the minimum cost of multiplying out each subsequence.</li><li>Add these costs together, and add in the cost of multiplying the two result matrices.</li><li>Do this for each possible position at which the sequence of matrices can be split, and take the minimum over all of them.</li></ul><p>For example, if we have four matrices <em>ABCD</em>, we compute the cost required to find each of (<em>A</em>)(<em>BCD</em>), (<em>AB</em>)(<em>CD</em>), and (<em>ABC</em>)(<em>D</em>), making recursive calls to find the minimum cost to compute <em>ABC</em>, <em>AB</em>, <em>CD</em>, and <em>BCD</em>. We then choose the best one. Better still, this yields not only the minimum cost, but also demonstrates the best way of doing the multiplication: group it the way that yields the lowest total cost, and do the same for each factor.</p><p>Let m [i, j] be the minimum number of scalar multiplication needed to compute the matrix Ai….j.</p><p>If i=j the chain consist of just one matrix Ai….i=Ai so no scalar multiplication are necessary to compute the product. Thus m [i, j] = 0 for i= 1, 2, 3….n.</p><p>If i&lt;j we assume that to optimally parenthesize the product we split it between Ak and Ak+1 where i≤ k ≤j. Then m [i,j] equals the minimum cost for computing the subproducts Ai….k and Ak+1….j+ cost of multiplying them together. We know Ai has dimension pi-1x pi, so computing the product Ai….k and Ak+1….jtakes pi-1 pk pj scalar multiplication, we obtain</p><blockquote>m [i,j] = m [i, k] + m [k + 1, j] + pi-1 pk pj</blockquote><p>There are only (j-1) possible values for ‘k’ namely k = i, i+1…..j-1. Since the optimal parenthesization must use one of these values for ‘k’ we need only check them all to find the best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*JoxRBRZsqoiLwU1UG7ea9Q.png" /></figure><h3>Example :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9NB19EVu9M89pITiFavTg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gY6AzKnOFXyCG0S3ze0I8Q.jpeg" /></figure><p>optimal solution =(m1 x(m2 x(m3 x m4))x m5)</p><blockquote>References “<strong>wikipedia </strong>”</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd4604c3b27a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>