Line 25: | Line 25: | ||
Then we have: | Then we have: | ||
<math>T(2^m) = 2 T(2^{\frac{m}{2}}) + \log {2^m} = 2 T(2^{\frac{m}{2}}) + m</math>. | <math>T(2^m) = 2 T(2^{\frac{m}{2}}) + \log {2^m} = 2 T(2^{\frac{m}{2}}) + m</math>. | ||
− | |||
We denote the running time in terms of <math>m</math> is <math>S(m)</math>, so <math>S(m) = T(2^m)</math>, where <math>m = \log n</math>. | We denote the running time in terms of <math>m</math> is <math>S(m)</math>, so <math>S(m) = T(2^m)</math>, where <math>m = \log n</math>. | ||
so we have <math>S(m) = 2S(\frac{m}{2})+ m</math>. | so we have <math>S(m) = 2S(\frac{m}{2})+ m</math>. | ||
Line 37: | Line 36: | ||
For the given recurrence, we replace n with <math>2^m</math> and denote the running time as <math>S(m)</math>. Thus,we have <math>S(m) = T(2^m) = 2 T(2^{\frac{m}{2}}) + m</math> | For the given recurrence, we replace n with <math>2^m</math> and denote the running time as <math>S(m)</math>. Thus,we have <math>S(m) = T(2^m) = 2 T(2^{\frac{m}{2}}) + m</math> | ||
− | (b) <math>3^{f(n)}</math> is NOT <math>O(3^{g(n)}</math>, here is an counter example: Let <math>f(n) = n</math> and <math>g(n)=\frac{n}{2}</math>. Then </math>f(n) = O(g(n))</math>. | + | (b) <math>3^{f(n)}</math> is NOT <math>O(3^{g(n)}</math>, here is an counter example: |
− | + | Let <math>f(n) = n</math> and <math>g(n)=\frac{n}{2}</math>. Then </math>f(n) = O(g(n))</math>. | |
Now, <math>3^{f(n)}=3^n</math>, <math>f(3^{f(n)})=O(3^n)</math>; however, <math>O(3^{g(n)})=O(3^{\frac{n}{2}})</math>. So <math>f(3^{f(n)}) \neq O(3^{g(n)})</math>. | Now, <math>3^{f(n)}=3^n</math>, <math>f(3^{f(n)})=O(3^n)</math>; however, <math>O(3^{g(n)})=O(3^{\frac{n}{2}})</math>. So <math>f(3^{f(n)}) \neq O(3^{g(n)})</math>. | ||
Revision as of 17:26, 20 July 2017
Computer Engineering(CE)
Question 1: Algorithms
August 2013
Solution 1
(a) First, let us change the variable. Let $ n = 2^{m} $, so equivalently, we have $ m = \log_2 n $. Thus, $ \sqrt[]{n} = 2^{\frac{m}{2}} $.
Then we have: $ T(2^m) = 2 T(2^{\frac{m}{2}}) + \log {2^m} = 2 T(2^{\frac{m}{2}}) + m $. We denote the running time in terms of $ m $ is $ S(m) $, so $ S(m) = T(2^m) $, where $ m = \log n $. so we have $ S(m) = 2S(\frac{m}{2})+ m $.
Now this recurrence can in in the form of $ T(m) = aT(\frac{m}{b})+ f(m) $, where $ a=2 $, $ b=2 $, and $ f(m)=m $.
$ f(m) = m = \Theta(n^{\log _{b}{a}}) = \Theta(n) $. So the second case of master's theorem applies, we have $ S(k) = \Theta(k^{\log _{b}{a}} \log k) = \Theta(k \log k) $.
Replace back with $ T(2^m) =S(m) $, and $ m = \log_2 n $, we have $ T(n) = \Theta((\log n) (\log \log n)) $.
For the given recurrence, we replace n with $ 2^m $ and denote the running time as $ S(m) $. Thus,we have $ S(m) = T(2^m) = 2 T(2^{\frac{m}{2}}) + m $
(b) $ 3^{f(n)} $ is NOT $ O(3^{g(n)} $, here is an counter example: Let $ f(n) = n $ and $ g(n)=\frac{n}{2} $. Then </math>f(n) = O(g(n))</math>. Now, $ 3^{f(n)}=3^n $, $ f(3^{f(n)})=O(3^n) $; however, $ O(3^{g(n)})=O(3^{\frac{n}{2}}) $. So $ f(3^{f(n)}) \neq O(3^{g(n)}) $.