<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Algorithms Q&amp;A - Recent questions and answers in Divide &amp; Conquer</title>
<link>https://notexponential.com/qa/d%26c</link>
<description>Powered by Question2Answer</description>
<item>
<title>Answered: Three Set Sum: Given an integer k and 3 sets A, B and C, find a, b, c such that a + b + c = k</title>
<link>https://notexponential.com/475/three-set-sum-given-an-integer-k-and-3-sets-a-and-find-such-that?show=964#a964</link>
<description>&lt;p&gt;&lt;span style=&quot;font-size:12px&quot;&gt;&lt;span style=&quot;font-family:Arial,Helvetica,sans-serif&quot;&gt;Given sets A, B, C of size n each and integer k, determine if there exist a, b, c (a ∈ A, b ∈ B, c ∈ C) such that&amp;nbsp;&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;a + b + c = k&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;Divide and Conquer Algorithm:&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;Divide If n = 1, directly check if a + b + c = k&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;If n &amp;gt; 1, split A, B, C into halves: A1, A2 = split(A) B1, B2 = split(B) C1, C2 = split(C)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;Conquer Recursively solve 8 subproblems:&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A1, B1, C1, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A1, B1, C2, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A1, B2, C1, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A1, B2, C2, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A2, B1, C1, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A2, B1, C2, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A2, B2, C1, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;T(A2, B2, C2, k)&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;If any returns true, return true. Else return false.&lt;/span&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:Arial,Helvetica,sans-serif&quot;&gt;Combine Return result of conquer step.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:Arial, Helvetica, sans-serif&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;The recurrence is T(n) = 8T(n/2) + O(n) which solves to O(n^2) by Master&#039;s theorem.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:Arial, Helvetica, sans-serif&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;As a result, examining all 8 options in a recursive fashion solves the issue in optimal O(n^2) time. Due to halving, the recursion tree depth decreases quickly, resulting in an efficient algorithm.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/475/three-set-sum-given-an-integer-k-and-3-sets-a-and-find-such-that?show=964#a964</guid>
<pubDate>Fri, 22 Dec 2023 18:14:44 +0000</pubDate>
</item>
<item>
<title>Answered: Solve or estimate this recurrence relation T(n) = 2 T(n/3) + T(n/2) + n</title>
<link>https://notexponential.com/768/solve-or-estimate-this-recurrence-relation-t-n-2-t-n-3-t-n-2-n?show=961#a961</link>
<description>&lt;p&gt;Use the Akra-Bazzi method:&lt;/p&gt;&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://notexponential.com/?qa=blob&amp;amp;qa_blobid=374327373741466866&quot; style=&quot;height:322px; width:600px&quot;&gt;&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/768/solve-or-estimate-this-recurrence-relation-t-n-2-t-n-3-t-n-2-n?show=961#a961</guid>
<pubDate>Wed, 20 Dec 2023 08:05:37 +0000</pubDate>
</item>
<item>
<title>Answered: Solving this recurrence relation: T(n) = 2 T(n/2) + f(n)</title>
<link>https://notexponential.com/696/solving-this-recurrence-relation-t-n-2-t-n-2-f-n?show=948#a948</link>
<description>&lt;p&gt;Using Master&#039;s Theorem:&lt;/p&gt;&lt;p&gt;1.) n&lt;sup&gt;log&lt;span style=&quot;font-size:11.1111px&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size:x-small&quot;&gt;&amp;nbsp;&lt;sub&gt;b&lt;/sub&gt; a&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/sup&gt;&lt;span style=&quot;font-size:x-small&quot;&gt;=&lt;/span&gt;&amp;nbsp;n&amp;nbsp;&lt;sup&gt;log&amp;nbsp; &lt;sub&gt;2&lt;/sub&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/sup&gt;= n&amp;nbsp; &amp;nbsp;||&amp;nbsp; For instance,&amp;nbsp;&lt;strong&gt;f(n) is n*log&lt;sup&gt;k&lt;/sup&gt;n .&lt;/strong&gt; Then&amp;nbsp;the Time Complexity of the&amp;nbsp;recurrence relation would be &lt;strong&gt;Theta(&amp;nbsp;n*log&lt;sup&gt;k+1&lt;/sup&gt;n).&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;2.)&amp;nbsp; n&lt;sup&gt;log&lt;span style=&quot;font-size:11.1111px&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size:x-small&quot;&gt;&amp;nbsp;&lt;sub&gt;b&lt;/sub&gt;&amp;nbsp;a&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/sup&gt;&lt;span style=&quot;font-size:x-small&quot;&gt;=&lt;/span&gt;&amp;nbsp;n&amp;nbsp;&lt;sup&gt;log&amp;nbsp;&amp;nbsp;&lt;sub&gt;2&lt;/sub&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/sup&gt;= n&amp;nbsp; ||&amp;nbsp; &amp;nbsp;For instance, &lt;strong&gt;f(n) is O(n&lt;sup&gt;1-e&lt;/sup&gt;).&lt;/strong&gt; Then the Time Complexity for the recurrence relation would be &lt;strong&gt;Theta(n).&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;3.)&amp;nbsp; n&lt;sup&gt;log&lt;span style=&quot;font-size:11.1111px&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size:x-small&quot;&gt;&amp;nbsp;&lt;sub&gt;b&lt;/sub&gt;&amp;nbsp;a&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/sup&gt;&lt;span style=&quot;font-size:x-small&quot;&gt;=&lt;/span&gt;&amp;nbsp;n&amp;nbsp;&lt;sup&gt;log&amp;nbsp;&amp;nbsp;&lt;sub&gt;2&lt;/sub&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/sup&gt;= n&amp;nbsp;&amp;nbsp;||&amp;nbsp; For instance,&lt;strong&gt; f(n) is omega(n&lt;sup&gt;1+e)&lt;/sup&gt;.&lt;/strong&gt; Then the Time Complexity for the recurrence relation would be &lt;strong&gt;Theta(f(n)).&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/696/solving-this-recurrence-relation-t-n-2-t-n-2-f-n?show=948#a948</guid>
<pubDate>Sat, 16 Dec 2023 18:03:35 +0000</pubDate>
</item>
<item>
<title>Answered: Solve the recurrence relation: T(n) = 3 T(n/2) + n^1.5 log n</title>
<link>https://notexponential.com/420/solve-the-recurrence-relation-t-n-3-t-n-2-n-1-5-log-n?show=939#a939</link>
<description>Given, T(n) = 3T(n/2) + n^1.5 log n&lt;br /&gt;
&lt;br /&gt;
Using Master&amp;#039;s theorem, &lt;br /&gt;
&lt;br /&gt;
a=3, b=2, f(n) = n^1.5 log^1 n , here k=1.5, p=1&lt;br /&gt;
&lt;br /&gt;
Calculating log a base b = log 3 base 2 = 1.58, k=1.5&lt;br /&gt;
&lt;br /&gt;
Clearly log a base b &amp;gt; k (case 1)&lt;br /&gt;
&lt;br /&gt;
T(n) &amp;nbsp;= theta(n^log a base b)&lt;br /&gt;
&lt;br /&gt;
T(n) = theta(n^1.58)</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/420/solve-the-recurrence-relation-t-n-3-t-n-2-n-1-5-log-n?show=939#a939</guid>
<pubDate>Thu, 14 Dec 2023 01:25:40 +0000</pubDate>
</item>
<item>
<title>Answered: Solve this recurrence relation: T(n) = T(n-1) + T(n/2) + 1</title>
<link>https://notexponential.com/707/solve-this-recurrence-relation-t-n-t-n-1-t-n-2-1?show=931#a931</link>
<description>&lt;p&gt;T(n) = T(n-1) + T(n/2) + 1&lt;/p&gt;&lt;p&gt;Using estimation method, we get&lt;/p&gt;&lt;p&gt;R(n) = 2R(n-1) + 1 &amp;amp; S(n) = 2S(n/2) + 1&lt;/p&gt;&lt;p&gt;Solving using the Master&#039;s Theorem&amp;nbsp;we get,&amp;nbsp;&lt;/p&gt;&lt;p&gt;R(n) = O(n*2&lt;sup&gt;n&lt;/sup&gt;)&amp;nbsp; &amp;amp; S(n) = n&lt;/p&gt;&lt;p&gt;Therefore, the time complexity is &lt;strong&gt;(n*2&lt;sup&gt;n&lt;/sup&gt;)&lt;/strong&gt; in the worst case.&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/707/solve-this-recurrence-relation-t-n-t-n-1-t-n-2-1?show=931#a931</guid>
<pubDate>Wed, 13 Dec 2023 00:09:53 +0000</pubDate>
</item>
<item>
<title>Answered: Solve the recurrence Relation: T(n) = T(n/3) + T(2n/3) + n</title>
<link>https://notexponential.com/419/solve-the-recurrence-relation-t-n-t-n-3-t-2n-3-n?show=849#a849</link>
<description>Came across an alternative approach to solve this question,&lt;br /&gt;
&lt;br /&gt;
The Akra-Bazzi theorem provides a method for solving certain types of recurrence relations that don&amp;#039;t fit directly into the standard forms covered by the master theorem. The Akra-Bazzi theorem is applicable to recurrence relations of the form:&lt;br /&gt;
&lt;br /&gt;
T(n) = g(n) + Σ_{i=1to k} ai *T(bi *n + h_i(n)),&lt;br /&gt;
&lt;br /&gt;
where ai and &amp;nbsp;bi are constants, and hi(n) are functions satisfying certain conditions. In this case, k = 2, a1 = a2 = 1, b1 = 1/3, b2 = 2/3, and h1(n) = h2(n) = 0.&lt;br /&gt;
&lt;br /&gt;
First we check conditions ,as we can see all conditions satisfied from above.&lt;br /&gt;
&lt;br /&gt;
next we check Regularity Condition:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Σ_{i=1to k} |ai/ bi^{-1}|^p = 1.&lt;br /&gt;
&lt;br /&gt;
Σ_{i=1to k} |ai/ bi^{-1}|^p = (1/(1/3)^p) + (1/(2/3)^p) = 3^p + (3/2)^p ~= 1 for all p&amp;gt;1&lt;br /&gt;
&lt;br /&gt;
The Akra-Bazzi theorem states that if the conditions are satisfied, the solution T(n) is equivalent to &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Θ (n^p (1 + ∫_{1to n} g(u) / u^{1+p} du)).&lt;br /&gt;
&lt;br /&gt;
Here g(n) = n and p = |ai / bi| *(1 + hi&amp;#039;(n) / n^{1 + hi(n)}) = 3^{-1} + (2/3)^{-1} = 1. [Since, h1(n) = h2(n) = 0]. By substituting the values in above equation stated, &amp;nbsp;we get &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Θ (n (1 + ∫_{1to n} u / u2 du)) = Θ (n (1 + ∫_{1to n} &amp;nbsp;1/u du)) = Θ (n (1 + log n)) = Θ (n + n log n) &lt;br /&gt;
&lt;br /&gt;
= Θ (n log n)</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/419/solve-the-recurrence-relation-t-n-t-n-3-t-2n-3-n?show=849#a849</guid>
<pubDate>Tue, 21 Nov 2023 09:58:14 +0000</pubDate>
</item>
<item>
<title>Answered: N-th power of complex number z = x + iy in O(log n) time</title>
<link>https://notexponential.com/709/n-th-power-of-complex-number-z-x-iy-in-o-log-n-time?show=752#a752</link>
<description>We can use divide and conquer for this problem, only because the we observe the squaring in this case to the power of 2 repeated. We also observe a constant c in this problem, which empowers us to us the standard mathematical model big O(1) as a multiplier. Thus the pseudocode for this problem: &lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
power(int z, int n) { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;if (n ==1) &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return z &lt;br /&gt;
&lt;br /&gt;
//division of integer, return the largest integer value that is smaller than or equal to the number (z) &lt;br /&gt;
&lt;br /&gt;
mid = int n/2 &lt;br /&gt;
&lt;br /&gt;
int previous = power (a,mid); // this recursive call else if&lt;br /&gt;
&lt;br /&gt;
if n%2 == 1 &lt;br /&gt;
&lt;br /&gt;
return prev * prev * z&lt;br /&gt;
&lt;br /&gt;
else &lt;br /&gt;
&lt;br /&gt;
return prev*prev&lt;br /&gt;
&lt;br /&gt;
//end&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Recurrence Relation: T(n) = T(n/2) + 1 &lt;br /&gt;
&lt;br /&gt;
Time Complexity: O(log n ) time</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/709/n-th-power-of-complex-number-z-x-iy-in-o-log-n-time?show=752#a752</guid>
<pubDate>Fri, 10 Jul 2020 02:28:31 +0000</pubDate>
</item>
<item>
<title>Answered: Solve this recurrence relation: T(n) = 3 T(n/4) + O(n^0.75)</title>
<link>https://notexponential.com/708/solve-this-recurrence-relation-t-n-3-t-n-4-o-n-0-75?show=747#a747</link>
<description>&lt;h1 style=&quot;margin-top: 0px; margin-bottom: 1em; padding: 12px 8px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; width: auto; max-height: 600px; overflow: auto; background-color: var(--black-050); border-radius: 3px; overflow-wrap: normal; color: rgb(36, 39, 41);&quot;&gt;&lt;/h1&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif; color: rgb(0, 0, 0); vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border:1pt none windowtext; color:#242729; padding:0in&quot;&gt;Master theorem:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color:#242729&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 12pt; font-size: 12pt; font-family: Calibri, sans-serif; color: rgb(0, 0, 0); vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color:#242729&quot;&gt;Using MT: a = 3, b = 4, f(n) = n^0.75&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 12pt; font-size: 12pt; font-family: Calibri, sans-serif; color: rgb(0, 0, 0); vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color:#242729&quot;&gt;Comparing n^(log_4(3)) to n^0.75&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 12pt; font-size: 12pt; font-family: Calibri, sans-serif; color: rgb(0, 0, 0); vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color:#242729&quot;&gt;Thus, case 1: Θ(n^log_4(3))&lt;/span&gt;&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/708/solve-this-recurrence-relation-t-n-3-t-n-4-o-n-0-75?show=747#a747</guid>
<pubDate>Thu, 02 Jul 2020 02:08:23 +0000</pubDate>
</item>
<item>
<title>Answered: Solve this recurrence relation: T(n) = T(n/3) + T(n/5) + T(n/6) + n</title>
<link>https://notexponential.com/693/solve-this-recurrence-relation-t-n-t-n-3-t-n-5-t-n-6-n?show=694#a694</link>
<description>&lt;h2&gt;Preliminary Work, to build our hypothesis&lt;/h2&gt;&lt;p&gt;T(n) = T(n/3) + T(n/5) + T(n/6) + n&lt;/p&gt;&lt;p&gt;We know that n/3 + n/5 + n/6 = n (10/30 + 6/30 + 5/30) = n 21/30 = 7n/10.&lt;/p&gt;&lt;p&gt;So, we could write this recurrence as similar to: R(n) = R(7n/10) + n&lt;/p&gt;&lt;p&gt;n represents 3/10&amp;nbsp;part of the overall work.&amp;nbsp; So, it APPEARS that&amp;nbsp;T(n) = 10n/3.&amp;nbsp; By &quot;Appears&quot; we mean that this is not a proof, this is just an exercise to reach a good guess.&amp;nbsp; Proof is what comes next.&lt;/p&gt;&lt;h2&gt;Proof by Induction&lt;/h2&gt;&lt;p&gt;Our hypothesis is: T(s) &amp;lt;= 10s/3 &amp;nbsp;for all s&lt;/p&gt;&lt;h3&gt;Base Case&lt;/h3&gt;&lt;p&gt;T(1) = C, this works, as long as C &amp;lt;= 10/3.&amp;nbsp; (Sure, we say that it is.)&lt;/p&gt;&lt;h3&gt;Induction Hypothesis&lt;/h3&gt;&lt;p&gt;Assume that T(s) &amp;lt;= 10s/3&amp;nbsp;for all s &amp;lt;= n-1&lt;/p&gt;&lt;h3&gt;Inductive Step&lt;/h3&gt;&lt;p&gt;We now need to prove the hypothesis for n.&lt;/p&gt;&lt;p&gt;So, for n, &lt;span style=&quot;background-color:null&quot;&gt;T(n) = T(n/3) + T(n/5) + T(n/6) + n&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color:null&quot;&gt;Using Induction Hypothesis (which applies for cases n/3, n/5 and n/6), we have that:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;T(n) &amp;lt;= 10(n/3)/3&amp;nbsp;+ 10 (n/5)/3&amp;nbsp;+ 10(n/6)/3&amp;nbsp;+ n&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; = n (10/9 + 10/15 + 10/18 + 1)&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;= n 10/3&lt;/p&gt;&lt;p&gt;Therefore, T(n) &amp;lt;= 10n/3 for all n.&lt;/p&gt;&lt;p&gt;Therefore, by PMI, our hypothesis is valid.&lt;/p&gt;&lt;p&gt;Now, we can go back to Asymptotic notation, and conclude that:&lt;/p&gt;&lt;p&gt;T(n) = O(n).&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/693/solve-this-recurrence-relation-t-n-t-n-3-t-n-5-t-n-6-n?show=694#a694</guid>
<pubDate>Sun, 22 Sep 2019 23:00:00 +0000</pubDate>
</item>
<item>
<title>Answered: The Subarray with the Minimum Peak</title>
<link>https://notexponential.com/596/the-subarray-with-the-minimum-peak?show=675#a675</link>
<description>divide&lt;br /&gt;
&lt;br /&gt;
find the right peak left peak and peak&lt;br /&gt;
&lt;br /&gt;
merge</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/596/the-subarray-with-the-minimum-peak?show=675#a675</guid>
<pubDate>Thu, 02 May 2019 06:08:47 +0000</pubDate>
</item>
<item>
<title>Answered: How to find the &quot;joint&quot; median of 3 sorted lists, in less than linear time?</title>
<link>https://notexponential.com/174/how-find-the-joint-median-sorted-lists-less-than-linear-time?show=658#a658</link>
<description>Change this question to find the medium of n sorted list n1~nn</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/174/how-find-the-joint-median-sorted-lists-less-than-linear-time?show=658#a658</guid>
<pubDate>Thu, 02 May 2019 03:10:23 +0000</pubDate>
</item>
<item>
<title>Answered: Rectangles overlap</title>
<link>https://notexponential.com/395/rectangles-overlap?show=651#a651</link>
<description>&lt;p&gt;&lt;a href=&quot;https://algnotes.wordpress.com/2015/05/20/intersection-of-rectangles/&quot; rel=&quot;nofollow&quot; style=&quot;text-decoration-line: none; color: rgb(1, 121, 181); font-family: Helvetica, Arial, sans-serif; font-size: 12px; background-color: rgb(250, 250, 250);&quot;&gt;https://algnotes.wordpress.com/2015/05/20/intersection-of-rectangles/&lt;/a&gt;&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/395/rectangles-overlap?show=651#a651</guid>
<pubDate>Thu, 02 May 2019 00:51:56 +0000</pubDate>
</item>
<item>
<title>Answered: Find the smallest domain value where the function becomes negative.</title>
<link>https://notexponential.com/595/find-smallest-domain-value-where-function-becomes-negative?show=607#a607</link>
<description>First we find a k that makes f(k) &amp;lt; 0&lt;br /&gt;
&lt;br /&gt;
Then we can find n by a simple binary search.&lt;br /&gt;
&lt;br /&gt;
1. Finding k&lt;br /&gt;
&lt;br /&gt;
Make k0 = some small constant for example 1&lt;br /&gt;
&lt;br /&gt;
Check if f(k0) &amp;lt; 0, if not, double the k0&amp;#039;s value and repeat.&lt;br /&gt;
&lt;br /&gt;
the final k0 is k.&lt;br /&gt;
&lt;br /&gt;
if f(0) &amp;lt; 0, vice visa, we can find a k that makes f(k) &amp;gt; 0 where k &amp;lt; 0 in the same way.&lt;br /&gt;
&lt;br /&gt;
2. Finding n&lt;br /&gt;
&lt;br /&gt;
since now f(k) * f(0) &amp;lt; 0, we can perform a single binary search to find n.&lt;br /&gt;
&lt;br /&gt;
Time complexity:&lt;br /&gt;
&lt;br /&gt;
Step 1 takes O(log n) time: finding k takes O(log k) time, and since k &amp;gt; n and k / 2 &amp;lt; n, finding the k takes O(log n) time too.&lt;br /&gt;
&lt;br /&gt;
Step2 takes O(log n) time. It&amp;#039;s trivial. The proof is left for practicing.&lt;br /&gt;
&lt;br /&gt;
Phase 1 can go faster under certain conditions. For example, if there is a range for n (Such as something a double or long can hold), we can completely skip phase 1. Or you can make that phase faster by changing the k0 in a faster, different way such as i^i in step i. For example, 1, 4, 27, 256... In this case the k0 grows much faster speed.&lt;br /&gt;
&lt;br /&gt;
However it doesn&amp;#039;t change the time complexity in phase 2, so the total time complexity is still O(log n). &lt;br /&gt;
&lt;br /&gt;
To reduce the time complexity even more you need a complete different algorithm than binary search. For example, Newton&amp;#039;s method to find the root of the equation in O(log n * F(n)) time where F(n) is the time complexity to calculate f&amp;#039;(n). The time complexity seems the same but the constant associated with it is much smaller.</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/595/find-smallest-domain-value-where-function-becomes-negative?show=607#a607</guid>
<pubDate>Sun, 27 Jan 2019 16:55:20 +0000</pubDate>
</item>
<item>
<title>Answered: Solve the recurrence relation: T(n)=T(n/2)+T(n/3)+T(n/4) + n</title>
<link>https://notexponential.com/431/solve-the-recurrence-relation-t-n-t-n-2-t-n-3-t-n-4-n?show=446#a446</link>
<description>&lt;p&gt;How about to solve it this way?&lt;/p&gt;&lt;p&gt;Because T(n/2)+T(n/3)+T(n/4)&amp;lt;=3T(n/2)&lt;/p&gt;&lt;p&gt;So T(n)=O(3T(n/2)+n)&lt;/p&gt;&lt;p&gt;T(n)=O(n^log&lt;span style=&quot;font-size:8px&quot;&gt;2&lt;/span&gt;3)&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/431/solve-the-recurrence-relation-t-n-t-n-2-t-n-3-t-n-4-n?show=446#a446</guid>
<pubDate>Tue, 07 Mar 2017 21:30:07 +0000</pubDate>
</item>
<item>
<title>Answered: In Quickselect, T(n)&lt;=T(n/5)+T(7n/10)+cn, prove that T(n) = O(n)</title>
<link>https://notexponential.com/425/in-quickselect-t-n-t-n-5-t-7n-10-cn-prove-that-t-n-o-n?show=426#a426</link>
<description>Assume that T(n) &amp;lt;= 10cn, where c is a constant.&lt;br /&gt;
&lt;br /&gt;
Prove it by induction:&lt;br /&gt;
&lt;br /&gt;
First, there is T(1) = O(1), satisfying that T(1) &amp;lt;= 10cn.&lt;br /&gt;
&lt;br /&gt;
Assume that T(m)&amp;lt;=10cm for all m &amp;lt;= n-1&lt;br /&gt;
&lt;br /&gt;
thus, for n, we have T(n) &amp;lt;= T(n/5) + T(7n/10) + cn&lt;br /&gt;
&lt;br /&gt;
since n/5 &amp;lt;= n-1, 7n/10 &amp;lt;= n-1&lt;br /&gt;
&lt;br /&gt;
For n, there is:&lt;br /&gt;
&lt;br /&gt;
T(n) &amp;lt;= 10c * n/5 + 10c * 7n/10 + cn = 2cn + 7cn + cn = 10cn&lt;br /&gt;
&lt;br /&gt;
Thus, T(n) &amp;lt;= 10cn for all n&amp;#039;s. So that T(n) = O(n)</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/425/in-quickselect-t-n-t-n-5-t-7n-10-cn-prove-that-t-n-o-n?show=426#a426</guid>
<pubDate>Wed, 08 Feb 2017 01:07:41 +0000</pubDate>
</item>
<item>
<title>Answered: MVCS using Divide and Conquer</title>
<link>https://notexponential.com/392/mvcs-using-divide-and-conquer?show=393#a393</link>
<description>&lt;p&gt;&lt;strong&gt;We use D&amp;amp;C&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Divide the array into two halfs:&lt;/p&gt;&lt;p&gt;Left side recursive call: T(n/2) time to find MVCS in A[1..n/2]&lt;/p&gt;&lt;p&gt;Right side recursive call: T(n/2) time to find MVCS in A[n/2 + 1..n]&lt;/p&gt;&lt;p&gt;If we can solve the &quot;left-right&quot; case in O(n) time, we will have our T(n) = 2 T(n/2) + O(n) recurrence relation, which then leads to T(n) = O(n log n) analysis.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;How to solve the boundary case in O(n) time&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;To solve boundary case, we realize, that it must include both A[n/2] and A[n/2 + 1]. &amp;nbsp;We simply find the maximum in both directions and add those up. &amp;nbsp;For example:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;rightMax = MINUS_INFINITY&lt;/p&gt;&lt;p&gt;rightSum = 0&lt;/p&gt;&lt;p&gt;for (j = n/2 + 1 to n) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;rightSum += a[j]&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;rightMax = max(rightMax, rightSum)&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This finds the rightMax. &amp;nbsp;Similarly we find leftMax&lt;/p&gt;&lt;p&gt;middleMax is then simply leftMax + rightMax&lt;/p&gt;&lt;p&gt;Overall algorithm can be written as:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;MVCS(A,1,n) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; leftOnlyMax = MVCS(A,1,n/2)&lt;/p&gt;&lt;p&gt;&amp;nbsp; rightOnlyMax = MVCS(A,n/2+1,n)&lt;/p&gt;&lt;p&gt;&amp;nbsp; middleMax = as calculated in the merge routine above&lt;/p&gt;&lt;p&gt;&amp;nbsp; overallMax = max(leftOnlyMax, rightOnlyMax, middleMax);&lt;/p&gt;&lt;p&gt;&amp;nbsp; return overallMax&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/392/mvcs-using-divide-and-conquer?show=393#a393</guid>
<pubDate>Sat, 03 Dec 2016 13:46:21 +0000</pubDate>
</item>
<item>
<title>Answered: Tree method or PMI?</title>
<link>https://notexponential.com/336/tree-method-or-pmi?show=337#a337</link>
<description>&lt;p&gt;Each method has its own advantages and disadvantages, but the analysis given in the question is not correct.&amp;nbsp; The time complexity of this recurrence is not O(n&lt;sup&gt;1.5&lt;/sup&gt;).&lt;/p&gt;&lt;p&gt;[The analysis presented above should be checked again.&amp;nbsp; For example, consider this statement:&amp;nbsp;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Then the bottom level is n*T(1) since the tree&amp;nbsp;has n leaves.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I am not sure this statement is supported by analysis.&lt;/p&gt;</description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/336/tree-method-or-pmi?show=337#a337</guid>
<pubDate>Wed, 28 Sep 2016 21:31:03 +0000</pubDate>
</item>
<item>
<title>Can T(n) = 2T(n/2) + nlogn use master theorem?</title>
<link>https://notexponential.com/306/can-t-n-2t-n-2-nlogn-use-master-theorem</link>
<description></description>
<category>Divide &amp; Conquer</category>
<guid isPermaLink="true">https://notexponential.com/306/can-t-n-2t-n-2-nlogn-use-master-theorem</guid>
<pubDate>Wed, 21 Sep 2016 03:51:57 +0000</pubDate>
</item>
</channel>
</rss>