<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Algorithms Q&amp;A - Recent questions in Asymptotic Analysis</title>
<link>https://notexponential.com/questions/asymptotic-analysis</link>
<description>Powered by Question2Answer</description>
<item>
<title>Analyze Double Loop - j starts from i*i</title>
<link>https://notexponential.com/976/analyze-double-loop-j-starts-from-i-i</link>
<description>&lt;p&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;for (int i = 1 to n) {&lt;/span&gt;&lt;br style=&quot;font-family: Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;&amp;nbsp;&amp;nbsp;for (int j = i*i to n) {&lt;/span&gt;&lt;br style=&quot;font-family: Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;&amp;nbsp; &amp;nbsp;sum += a[i]*b[j]&lt;/span&gt;&lt;br style=&quot;font-family: Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;br style=&quot;font-family: Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family:Helvetica,Arial,sans-serif; font-size:14px&quot;&gt;}&lt;/span&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/976/analyze-double-loop-j-starts-from-i-i</guid>
<pubDate>Fri, 22 Nov 2024 15:11:57 +0000</pubDate>
</item>
<item>
<title>Analyze Triple Loop - j and k start with i^2 and j^2 respectively</title>
<link>https://notexponential.com/975/analyze-triple-loop-j-and-k-start-with-i-2-and-j-2-respectively</link>
<description>for (int i = 1 to n) {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;for (int j = i*i to n) {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (int k = j*j to n) {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum += a[i]*b[j]*c[k]&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
}</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/975/analyze-triple-loop-j-and-k-start-with-i-2-and-j-2-respectively</guid>
<pubDate>Mon, 04 Nov 2024 16:01:18 +0000</pubDate>
</item>
<item>
<title>Nested loop analysis, outer loop grows by sqrt n, inner randomly</title>
<link>https://notexponential.com/839/nested-loop-analysis-outer-loop-grows-by-sqrt-inner-randomly</link>
<description>&lt;pre class=&quot;Code&quot; style=&quot;margin: 0in;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;j = 1
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;while (j &amp;lt; n) {&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp;&amp;nbsp;k = j&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp;&amp;nbsp;while (k &amp;lt; log n) {&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;if (random() &amp;lt; 0.5) {&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;k += k&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;} else {&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;k += 1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;Code&quot; style=&quot;margin: 0in; font-size: 11pt; font-family: &amp;quot;Lucida Console&amp;quot;; color: rgb(0, 0, 0); text-align: left;&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&amp;nbsp;&amp;nbsp;j += 0.1 * sqrt(n)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size:10pt&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Lucida Sans Unicode,Lucida Grande,sans-serif&quot;&gt;&lt;span style=&quot;color:#000000; line-height:15.3333px&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/839/nested-loop-analysis-outer-loop-grows-by-sqrt-inner-randomly</guid>
<pubDate>Fri, 10 Nov 2023 17:03:51 +0000</pubDate>
</item>
<item>
<title>Solve this recurrence using master theorem: T(n) = 2 T(n/2) + n^0.75</title>
<link>https://notexponential.com/831/solve-this-recurrence-using-master-theorem-t-n-2-t-n-2-n-0-75</link>
<description></description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/831/solve-this-recurrence-using-master-theorem-t-n-2-t-n-2-n-0-75</guid>
<pubDate>Sun, 10 Sep 2023 19:08:00 +0000</pubDate>
</item>
<item>
<title>Asymptotically compare 14 T(n/4) + O(n) and 7 R(n/2) + O(n).</title>
<link>https://notexponential.com/770/asymptotically-compare-14-t-n-4-o-n-and-7-r-n-2-o-n</link>
<description>&lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; text-align: justify; line-height: 16.8667px; font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 0, 0);&quot;&gt;Asymptotically compare recurrence relations T and R.&amp;nbsp; Express your answer by writing asymptotic relation between T and R.&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; text-align: justify; line-height: 16.8667px; font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 0, 0);&quot;&gt;T(n) = 14 T(n/4) + O(n).&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; R(n) = 7 R(n/2) + O(n).&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/770/asymptotically-compare-14-t-n-4-o-n-and-7-r-n-2-o-n</guid>
<pubDate>Sat, 10 Dec 2022 20:38:22 +0000</pubDate>
</item>
<item>
<title>Use the limit method to prove the asymptotic relation between these 3 functions</title>
<link>https://notexponential.com/767/limit-method-prove-asymptotic-relation-between-functions</link>
<description>&lt;p&gt;Use the limit method to prove the asymptotic relation between these 3 functions:&lt;/p&gt;&lt;p&gt;n&amp;nbsp;&lt;/p&gt;&lt;p&gt;2n&lt;/p&gt;&lt;p&gt;n^2&lt;/p&gt;&lt;p&gt;&lt;strong&gt;The limit method says that: lim (n --&amp;gt; infinity)&amp;nbsp; f(n) / g(n)&amp;nbsp; &amp;nbsp;tends to 0, then f(n) = o(g(n)).&amp;nbsp; Similarly, if the limit tends to infinity, then f(n) = small omega (g(n)), and if the limit tends to a constant, then f(n) = theta (g(n)).&lt;/strong&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/767/limit-method-prove-asymptotic-relation-between-functions</guid>
<pubDate>Tue, 25 May 2021 02:10:27 +0000</pubDate>
</item>
<item>
<title>Highest sum of tree heights when one recoloring is allowed</title>
<link>https://notexponential.com/706/highest-sum-of-tree-heights-when-one-recoloring-is-allowed</link>
<description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color:white&quot;&gt;You are given a sequence of &lt;em&gt;n&lt;/em&gt; trees.&amp;nbsp; The height of the &lt;em&gt;i-&lt;/em&gt;th tree is &lt;em&gt;h[i]&lt;/em&gt;.&amp;nbsp; Each tree could be of one of &lt;em&gt;k&lt;/em&gt;&lt;/span&gt; different colors.&amp;nbsp; You are allowed to do ONE recoloring operation, in which you can recolor ALL trees with color C1, to color C2.&amp;nbsp; Your objective is to MAXIMIZE the total height of contiguous block of trees of one color.&amp;nbsp; Present an algorithm for this problem, and present its time complexity.&lt;/p&gt;&lt;p&gt;For example, suppose your trees are:&lt;/p&gt;&lt;p&gt;Tree T1, Height 17, Color: R (Red)&lt;/p&gt;&lt;p&gt;Tree T2, Height 20, Color: Y (Yellow)&lt;/p&gt;&lt;p&gt;Tree T3, Height 1, Color: G (Green)&lt;/p&gt;&lt;p&gt;Tree T4, Height 5, Color: G (Green)&lt;/p&gt;&lt;p&gt;Tree T5, Height 6, Color: Y (Yellow)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, if you color Y&lt;span style=&quot;font-family:Wingdings&quot;&gt;à&lt;/span&gt;G (or G&lt;span style=&quot;font-family:Wingdings&quot;&gt;à&lt;/span&gt;Y), then the maximum height of G trees is 32.&amp;nbsp; However, if you recolor Y&lt;span style=&quot;font-family:Wingdings&quot;&gt;à&lt;/span&gt;R (or R&lt;span style=&quot;font-family:Wingdings&quot;&gt;à&lt;/span&gt;Y), then the maximum contiguous height becomes 37, and is therefore the correct answer.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/706/highest-sum-of-tree-heights-when-one-recoloring-is-allowed</guid>
<pubDate>Tue, 05 May 2020 22:54:14 +0000</pubDate>
</item>
<item>
<title>outer loop until log n, inner loop exponential increase</title>
<link>https://notexponential.com/579/outer-loop-until-log-n-inner-loop-exponential-increase</link>
<description>&lt;div style=&quot;left: 379.857px; top: 332.937px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;Given:&lt;/div&gt;&lt;div style=&quot;left: 379.857px; top: 332.937px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;left: 379.857px; top: 332.937px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;&lt;div style=&quot;left: 451.05907189542484px; top: 332.9373284313725px; font-size: 14.534901960784314px; font-family: monospace;&quot;&gt;int j = 5&lt;/div&gt;&lt;div style=&quot;left: 513.361px; top: 347.472px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;while (j &amp;lt; log n) {&lt;/div&gt;&lt;div style=&quot;left: 468.8596px; top: 362.3616421568629px; font-size: 14.534901960784314px; font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int k = 5&lt;/div&gt;&lt;div style=&quot;left: 397.658px; top: 377.251px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (k &amp;lt; n) {&lt;/div&gt;&lt;div style=&quot;left: 459.959px; top: 391.786px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum += a[j]*b[k]&lt;/div&gt;&lt;div style=&quot;left: 451.059px; top: 406.675px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k = k^1.3&lt;/div&gt;&lt;div style=&quot;left: 397.65763529411765px; top: 421.5647794117648px; font-size: 14.534901960784314px; font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style=&quot;left: 397.658px; top: 436.1px; font-size: 14.5349px; font-family: monospace; transform: scaleX(0.988858);&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j = 1.3 * j&lt;/div&gt;&lt;div style=&quot;left: 379.8571071895425px; top: 450.98909313725494px; font-size: 14.534901960784314px; font-family: monospace;&quot;&gt;}&lt;/div&gt;&lt;/div&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/579/outer-loop-until-log-n-inner-loop-exponential-increase</guid>
<pubDate>Mon, 09 Jul 2018 01:18:16 +0000</pubDate>
</item>
<item>
<title>Solve the Recurrence Relation: T(n) = T(n/4) + T(3n/4) + n^2</title>
<link>https://notexponential.com/557/solve-the-recurrence-relation-t-n-t-n-4-t-3n-4-n-2</link>
<description></description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/557/solve-the-recurrence-relation-t-n-t-n-4-t-3n-4-n-2</guid>
<pubDate>Tue, 08 May 2018 02:40:02 +0000</pubDate>
</item>
<item>
<title>Time Complexity 0.25 * n and k +=k</title>
<link>https://notexponential.com/513/time-complexity-0-25-n-and-k-k</link>
<description>&lt;pre&gt;j = 1
while (j &amp;lt; n) {
    k = j
    while (k &amp;lt; n) {
        Sum += a[k] * b[k]
        k += k
    }
     j += 0.25 * n
}&lt;/pre&gt;&lt;pre&gt;From midterm practice&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/513/time-complexity-0-25-n-and-k-k</guid>
<pubDate>Sun, 04 Mar 2018 19:27:16 +0000</pubDate>
</item>
<item>
<title>Time Complexity (3 loops with gcd)</title>
<link>https://notexponential.com/512/time-complexity-3-loops-with-gcd</link>
<description>&lt;pre&gt;for (int i = 1 to n) {
    for(int j = i to n) {
        for(int k = j to n) {
            Sum += a[i] * b[j] * c[k]
        }
        if (gcd(i, j) == 1) {
            j = n
        }
    }
}
&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/512/time-complexity-3-loops-with-gcd</guid>
<pubDate>Sun, 04 Mar 2018 19:21:54 +0000</pubDate>
</item>
<item>
<title>Time Complexity increasing by n^(1/3)log(n)</title>
<link>https://notexponential.com/509/time-complexity-increasing-by-n-1-3-log-n</link>
<description>&lt;pre&gt;int j = 2
while (j &amp;lt; n) {
    int k = j
    while (k &amp;lt; n) {
        Sum += a[k] * b[k]
        k += n^(1/3) log(n)
    }
    j = j * sqrt(5)
}

From the midterm practice&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/509/time-complexity-increasing-by-n-1-3-log-n</guid>
<pubDate>Sun, 04 Mar 2018 17:42:39 +0000</pubDate>
</item>
<item>
<title>What&#039;s the time complexity when j increases by j += log(j+5)?</title>
<link>https://notexponential.com/479/whats-the-time-complexity-when-j-increases-by-j-log-j-5</link>
<description>&lt;p&gt;Consider the following code:&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10px&quot;&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;int j = 1;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10px&quot;&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;while (j &amp;lt; n) {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10px&quot;&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&amp;nbsp; &amp;nbsp; j += log( j + 5 )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10px&quot;&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;How to calculate the time complexity?&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/479/whats-the-time-complexity-when-j-increases-by-j-log-j-5</guid>
<pubDate>Sun, 10 Sep 2017 18:51:36 +0000</pubDate>
</item>
<item>
<title>Time Complexity Analysis - Nested Loops - Inner Increments by sqrt(k)</title>
<link>https://notexponential.com/467/time-complexity-analysis-nested-loops-inner-increments-sqrt</link>
<description>&lt;p&gt;What is the time complexity of this algorithm:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;j = 1
while (j &amp;lt; n) {
   k = j
   while (k &amp;lt; n){
      sum += a[k]*b[k]
      k += sqrt(k)
  }
  j += 0.25*n
}&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/467/time-complexity-analysis-nested-loops-inner-increments-sqrt</guid>
<pubDate>Wed, 12 Jul 2017 17:41:00 +0000</pubDate>
</item>
<item>
<title>log(n!) = Theta(nlogn)</title>
<link>https://notexponential.com/459/log-n-theta-nlogn</link>
<description>How to explain this equation? &amp;nbsp;It seems to be clear that log(n!) = O(n log n), since log (1.2.3.4.5....n) &amp;lt;= log (n.n.n.n...n) &amp;nbsp;&amp;nbsp;&amp;nbsp;(n times).&lt;br /&gt;
&lt;br /&gt;
However, how do we prove that log (n!) = Omega (n log n)</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/459/log-n-theta-nlogn</guid>
<pubDate>Wed, 10 May 2017 03:31:10 +0000</pubDate>
</item>
<item>
<title>Solve the recurrence relation: T(n)=T(n/2)+T(n^0.5)+n</title>
<link>https://notexponential.com/436/solve-the-recurrence-relation-t-n-t-n-2-t-n-0-5-n</link>
<description></description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/436/solve-the-recurrence-relation-t-n-t-n-2-t-n-0-5-n</guid>
<pubDate>Thu, 02 Mar 2017 21:04:44 +0000</pubDate>
</item>
<item>
<title>How to get the time complexity of these algorithms, in terms of n in quiz 2?</title>
<link>https://notexponential.com/434/how-to-get-the-time-complexity-of-these-algorithms-terms-quiz</link>
<description>&lt;h1&gt;&lt;strong&gt;&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;Question 1&lt;/span&gt;&lt;/strong&gt;&lt;/h1&gt;&lt;pre&gt;&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;j= 2
while (j &amp;lt; n) { &lt;/span&gt;
&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;    k=2
    while (k &amp;lt; n) { &lt;/span&gt;
&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;        sum += a[k]*b[k] &lt;/span&gt;
&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;        k = k * sqrt(k)
    } &lt;/span&gt;
  &lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;j += 5*j/3
} &lt;/span&gt;&lt;/pre&gt;&lt;h1&gt;&lt;strong&gt;&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;Question 2&lt;/span&gt;&lt;/strong&gt;&lt;/h1&gt;&lt;pre&gt;&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;for (int j = 1 to n)  {
    int k = j &lt;/span&gt;
&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;    while (k &amp;lt; n) {
        Sum += a[k]*b[k]
        k += n^(1/3)&lt;/span&gt;&lt;span style=&quot;font-family:calibri; font-size:7.000000pt&quot;&gt; &lt;/span&gt;
&lt;span style=&quot;font-family:calibri; font-size:11.000000pt&quot;&gt;    }
} &lt;/span&gt;&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/434/how-to-get-the-time-complexity-of-these-algorithms-terms-quiz</guid>
<pubDate>Sat, 18 Feb 2017 20:13:03 +0000</pubDate>
</item>
<item>
<title>Solve the recurrence Relation T(n)=T(n/5)+T(7n/10)+(n^2)</title>
<link>https://notexponential.com/428/solve-the-recurrence-relation-t-n-t-n-5-t-7n-10-n-2</link>
<description></description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/428/solve-the-recurrence-relation-t-n-t-n-5-t-7n-10-n-2</guid>
<pubDate>Wed, 08 Feb 2017 22:40:39 +0000</pubDate>
</item>
<item>
<title>The executive time of program in eclipse seems to be randomly when the times are not very large</title>
<link>https://notexponential.com/421/executive-time-program-eclipse-seems-randomly-times-large</link>
<description>public class test2 {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static void main(String []args){&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long start = System.nanoTime();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double j = 2;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double n = 100000000; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int count1 = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int count3 = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (j &amp;lt; n) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double k = 2;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int count2 = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count1++;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//System.out.println(&amp;quot;first while loop for &amp;quot; + count1 + &amp;quot; times&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (k &amp;lt; n) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;k = k * k;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count2++;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count3++;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;j += j/2;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;second while loop for &amp;quot; + count2 + &amp;quot; times&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;total loop for &amp;quot; + count3 + &amp;quot; times&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long end = System.nanoTime();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;TimeCost: &amp;quot; + (end - start) + &amp;quot; NS&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
This is the program I wrote to test its executive time. I add System.nanoTime() to record the time. But when the times are not very large, like 50 or 200 times, by changing the value of n, the executive time of 200 times sometimes is shorter than that of 50 times. However, when the times are added to like 10000000, it obviously takes longer time. I wonder if there is another way to measure the executive time of program more accurately.</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/421/executive-time-program-eclipse-seems-randomly-times-large</guid>
<pubDate>Mon, 23 Jan 2017 02:57:54 +0000</pubDate>
</item>
<item>
<title>Loop i through log n incremented by constant multiplication</title>
<link>https://notexponential.com/394/loop-i-through-log-incremented-by-constant-multiplication</link>
<description>&lt;p&gt;What is the time complexity of the following loop?&lt;/p&gt;&lt;pre&gt;double j = 1.0
while (j &amp;lt; log n) {
    j = 1.3 * j
}

&lt;/pre&gt;&lt;p&gt;The loop, if it was j &amp;lt; n, then it would be log n. However, it goes from j = 1 to log n instead of n. How do you combine that to find the total complexity?&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/394/loop-i-through-log-incremented-by-constant-multiplication</guid>
<pubDate>Mon, 05 Dec 2016 01:52:40 +0000</pubDate>
</item>
<item>
<title>Time Complexity - Recursive function - Two recursive calls, and double nested loop</title>
<link>https://notexponential.com/348/complexity-recursive-function-recursive-calls-double-nested</link>
<description>&lt;pre&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:medium&quot;&gt;function T(int n) {&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  int n1 = T((n-1)/4) &lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  int n2 = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:medium&quot;&gt;T((n+1)/4) &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  int sum = 0 &lt;/span&gt;

&lt;span style=&quot;font-size:medium&quot;&gt;  for i = 1 to n {&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;    for j = 1 to n {&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;      sum+=n1*i + n2*j&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;    }&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  }&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  return sum&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:medium&quot;&gt;T(n) =&amp;nbsp;?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/348/complexity-recursive-function-recursive-calls-double-nested</guid>
<pubDate>Wed, 05 Oct 2016 16:46:20 +0000</pubDate>
</item>
<item>
<title>Time complexity of recursive function - Single recursive call of size n/3 and n^2 loop</title>
<link>https://notexponential.com/342/time-complexity-recursive-function-single-recursive-call</link>
<description>&lt;pre&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:medium&quot;&gt;function T(int n) {&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  int n1 = 2T(n/3) + 5&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  int n2 = 2*n1*n1&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  int sum = 0 &lt;/span&gt;

&lt;span style=&quot;font-size:medium&quot;&gt;  for i = 1 to n {&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;    for j = 1 to n {&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;      sum+=n1*i + n2*j&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;    }&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  }&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;  return sum&lt;/span&gt;
&lt;span style=&quot;font-size:medium&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:medium&quot;&gt;// Assume T(1) = 1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:medium&quot;&gt;T(n) =&amp;nbsp;?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/342/time-complexity-recursive-function-single-recursive-call</guid>
<pubDate>Mon, 03 Oct 2016 15:24:17 +0000</pubDate>
</item>
<item>
<title>MT for T(n) = 2T(n/2) + n^2 log n</title>
<link>https://notexponential.com/323/mt-for-t-n-2t-n-2-n-2-log-n</link>
<description>How do we use MT to solve T(n) = 2T(n/2) + n^2 log n?&lt;br /&gt;
&lt;br /&gt;
c = 2 &amp;gt; log_b(a) here, but f(n) = Theta (n^2 log n) instead of purely Theta(n^2).&lt;br /&gt;
&lt;br /&gt;
Besides, for T(n) = 2T(n/2) + n logn, f(n) / n^log_b(a) = log n, there is a non-polynomial difference right? Then why can we use MT for it?</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/323/mt-for-t-n-2t-n-2-n-2-log-n</guid>
<pubDate>Thu, 22 Sep 2016 15:25:55 +0000</pubDate>
</item>
<item>
<title>Recurrence relation : T(n) = T(n/3) + 2 T(2n/3) + n</title>
<link>https://notexponential.com/293/recurrence-relation-t-n-t-n-3-2-t-2n-3-n</link>
<description>Solve the recurrence relation:T(n)=T(n/3)+2T(2n/3)+n.</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/293/recurrence-relation-t-n-t-n-3-2-t-2n-3-n</guid>
<pubDate>Fri, 16 Sep 2016 00:44:00 +0000</pubDate>
</item>
<item>
<title>Prove Ө(log 1 + log2 + log3 + log4 +... + logn) = Ө(n log n)</title>
<link>https://notexponential.com/284/prove-%D3%A9-log-1-log2-log3-log4-logn-%D3%A9-n-log-n</link>
<description>Prove Ө(log2 *log3 *log4 *...*logn) = Ө(n log n)&lt;br /&gt;
&lt;br /&gt;
That is, prove both the the big Oh and big Omega side.</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/284/prove-%D3%A9-log-1-log2-log3-log4-logn-%D3%A9-n-log-n</guid>
<pubDate>Thu, 15 Sep 2016 20:12:54 +0000</pubDate>
</item>
<item>
<title>For-While Nested Loops Time Complexity - Inner Loop increments by n^1/3</title>
<link>https://notexponential.com/277/for-while-nested-loops-time-complexity-inner-loop-increments</link>
<description>&lt;pre&gt;for (int j = 1 to n) {
  int k = j
  while (k &amp;lt; n) {
    Sum += a[k]*b[k]
    k += n^1/3
  }
}&lt;/pre&gt;&lt;p&gt;For this one I came across the answer of O(n^2) but the answer key was n^5/3&lt;/p&gt;&lt;p&gt;Anyone can explain when we can ignore the constants? Thx&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/277/for-while-nested-loops-time-complexity-inner-loop-increments</guid>
<pubDate>Thu, 15 Sep 2016 06:09:59 +0000</pubDate>
</item>
<item>
<title>Given f(n) = o(g(n)), prove that 2^f(n) = o(2^g(n))</title>
<link>https://notexponential.com/261/given-f-n-o-g-n-prove-that-2-f-n-o-2-g-n</link>
<description>Given f(n) = o(g(n)), prove that 2^f(n) = o(2^g(n))</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/261/given-f-n-o-g-n-prove-that-2-f-n-o-2-g-n</guid>
<pubDate>Mon, 12 Sep 2016 21:27:35 +0000</pubDate>
</item>
<item>
<title>Given f(n) = o(g(n)), show that it is not necessary that  log (f(n)) = o(log (g(n)))</title>
<link>https://notexponential.com/260/given-f-n-o-g-n-show-that-it-is-not-necessary-that-log-f-n-o-log-g-n</link>
<description>&lt;p&gt;Given f(n) = o(g(n)), show that it is not necessary that&amp;nbsp; log (f(n)) = o(log (g(n)))&lt;/p&gt;&lt;p&gt;&lt;em&gt;[Hint, use a counterexample]&lt;/em&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/260/given-f-n-o-g-n-show-that-it-is-not-necessary-that-log-f-n-o-log-g-n</guid>
<pubDate>Mon, 12 Sep 2016 20:39:25 +0000</pubDate>
</item>
<item>
<title>Count Primes - Time Complexity</title>
<link>https://notexponential.com/250/count-primes-time-complexity</link>
<description>&lt;p&gt;&lt;span style=&quot;font-size:14px&quot;&gt;&lt;strong&gt;What is the time complexity of this algorithm, in terms of n?&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:14px&quot;&gt;public int countPrimes(int n) {&lt;br&gt;&amp;nbsp; &amp;nbsp;boolean[] isPrime = new boolean[n];&lt;br&gt;&amp;nbsp; &amp;nbsp;for (int i = 2; i &amp;lt; n; i++) {&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; isPrime[i] = true;&lt;br&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:14px&quot;&gt;&amp;nbsp;&amp;nbsp; // Loop&#039;s ending condition is i * i &amp;lt; n instead of i &amp;lt; sqrt(n)&lt;br&gt;&amp;nbsp; &amp;nbsp;// to avoid repeatedly calling an expensive function sqrt().&lt;br&gt;&amp;nbsp; &amp;nbsp;for (int i = 2; i * i &amp;lt; n; i++) {&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if (!isPrime[i]) continue;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; for (int j = i * i; j &amp;lt; n; j += i) {&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;isPrime[j] = false;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br&gt;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp; &amp;nbsp;int count = 0;&lt;br&gt;&amp;nbsp; &amp;nbsp;for (int i = 2; i &amp;lt; n; i++) {&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if (isPrime[i]) count++;&lt;br&gt;&amp;nbsp; &amp;nbsp;}&lt;br&gt;&amp;nbsp; &amp;nbsp;return count;&lt;br&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Credit:&amp;nbsp;&lt;a href=&quot;https://leetcode.com/problems/count-primes/&quot; rel=&quot;nofollow&quot;&gt;https://leetcode.com/problems/count-primes/&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/250/count-primes-time-complexity</guid>
<pubDate>Sun, 11 Sep 2016 06:47:05 +0000</pubDate>
</item>
<item>
<title>Compare 2^n^2 and 10^n asymptotically</title>
<link>https://notexponential.com/249/compare-2-n-2-and-10-n-asymptotically</link>
<description>&lt;p&gt;Prove that 10&lt;sup&gt;n&amp;nbsp;&lt;/sup&gt;&amp;nbsp;= o(2&lt;sup&gt;n^2&lt;/sup&gt;)&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/249/compare-2-n-2-and-10-n-asymptotically</guid>
<pubDate>Sat, 10 Sep 2016 22:16:07 +0000</pubDate>
</item>
<item>
<title>Order these time complexities from best (lowest) to worst (highest)</title>
<link>https://notexponential.com/233/order-these-time-complexities-from-best-lowest-worst-highest</link>
<description>&lt;p&gt;O(n)&lt;/p&gt;&lt;p&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/p&gt;&lt;p&gt;O(n&lt;sup&gt;3&lt;/sup&gt;)&lt;/p&gt;&lt;p&gt;O(log n^ log n)&lt;/p&gt;&lt;p&gt;O(log log n ^ log log n)&lt;/p&gt;&lt;p&gt;O(log n ^ log log n)&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/233/order-these-time-complexities-from-best-lowest-worst-highest</guid>
<pubDate>Thu, 01 Sep 2016 02:22:55 +0000</pubDate>
</item>
<item>
<title>Time Complexity Analysis - Double Loop - Second increments by 0.01</title>
<link>https://notexponential.com/214/time-complexity-analysis-double-loop-second-increments-by</link>
<description>&lt;pre&gt;What is the time complexity of the following program?&lt;/pre&gt;&lt;hr&gt;&lt;pre&gt;for (int j = 1 to n) {
  int k = j
  while (k &amp;lt; n) {
    Sum += a[k]*b[k]
    k += 0.01 * n
  }
}&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/214/time-complexity-analysis-double-loop-second-increments-by</guid>
<pubDate>Sat, 20 Aug 2016 20:00:28 +0000</pubDate>
</item>
<item>
<title>Asymptotic Analysis - Triple Loop - k starts from j^2</title>
<link>https://notexponential.com/181/asymptotic-analysis-triple-loop-k-starts-from-j-2</link>
<description>What is the time complexity of this program?&lt;br /&gt;
&lt;br /&gt;
for i = 1 to n&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for j = i to n&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for k = j*j to n&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum++;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/181/asymptotic-analysis-triple-loop-k-starts-from-j-2</guid>
<pubDate>Sat, 02 Jul 2016 12:50:03 +0000</pubDate>
</item>
<item>
<title>Trichotomy in Context of Asymptotic Functions</title>
<link>https://notexponential.com/162/trichotomy-in-context-of-asymptotic-functions</link>
<description>&lt;p&gt;Given two functions &lt;em&gt;f(n)&lt;/em&gt; and &lt;em&gt;g(n)&lt;/em&gt;, both strictly increasing with &lt;em&gt;n&lt;/em&gt;, is it possible that &lt;em&gt;f(n)&lt;/em&gt; and &lt;em&gt;g(n)&lt;/em&gt; cannot be compared asymptotically? Either prove that such two functions can always be compared asymptotically, or give a counter example, such that neither &lt;em&gt;f(n)&lt;/em&gt; is in &lt;em&gt;O(g(n))&lt;/em&gt; nor is &lt;em&gt;g(n)&lt;/em&gt; in &lt;em&gt;O(f(n))&lt;/em&gt;.&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/162/trichotomy-in-context-of-asymptotic-functions</guid>
<pubDate>Fri, 29 Jan 2016 13:00:46 +0000</pubDate>
</item>
<item>
<title>Time Complexity Analysis - Odd Even - Big Jumps</title>
<link>https://notexponential.com/144/time-complexity-analysis-odd-even-big-jumps</link>
<description>&lt;pre&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;j = 1&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;while ( j &amp;lt; n ) {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;     k = j&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;     while ( k &amp;lt; n ) {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;          If  ( k is odd )&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;              k++&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;          else   &lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;              k + = 0.01 * n&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;    j+=0.1*n&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;&lt;span style=&quot;font-size:14px&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/144/time-complexity-analysis-odd-even-big-jumps</guid>
<pubDate>Tue, 19 Jan 2016 17:30:01 +0000</pubDate>
</item>
<item>
<title>Time Complexity Analysis - 2 (2nd by log n)</title>
<link>https://notexponential.com/143/time-complexity-analysis-2-2nd-by-log-n</link>
<description>&lt;p&gt;&lt;span style=&quot;font-size:14px&quot;&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;for (int j=1 to n) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;k=j;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (k&amp;lt;n) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Sum += a[k]*b[k];&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;k += logn;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/143/time-complexity-analysis-2-2nd-by-log-n</guid>
<pubDate>Tue, 19 Jan 2016 16:24:13 +0000</pubDate>
</item>
<item>
<title>Time Complexity Analysis - Inner loop var gets squared</title>
<link>https://notexponential.com/127/time-complexity-analysis-inner-loop-var-gets-squared</link>
<description>&lt;pre&gt;j = 1
while (j &amp;lt; n) {
  k = 2
  while (k &amp;lt; n) {
    Sum += a[j]*b[k]
    k = k * k
  }
  j++
}&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/127/time-complexity-analysis-inner-loop-var-gets-squared</guid>
<pubDate>Fri, 15 Jan 2016 11:13:41 +0000</pubDate>
</item>
<item>
<title>Time complexity of GCD algorithm</title>
<link>https://notexponential.com/126/time-complexity-of-gcd-algorithm</link>
<description>&lt;pre&gt;&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;gcd(n,m) {&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;  r = n%m&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;  if r == 0 return m;&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;  // else&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;  return gcd(m, r)&lt;/span&gt;
&lt;span style=&quot;font-family:lucida sans unicode,lucida grande,sans-serif&quot;&gt;}&lt;/span&gt;

&lt;/pre&gt;</description>
<category>Asymptotic Analysis</category>
<guid isPermaLink="true">https://notexponential.com/126/time-complexity-of-gcd-algorithm</guid>
<pubDate>Fri, 15 Jan 2016 00:20:21 +0000</pubDate>
</item>
</channel>
</rss>