Editing Asymptotic analysis

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 292: Line 292:
 
The authoritative statement of the '''master theorem''' is from CLRS<ref name="CLRS">Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. ''Introduction to Algorithms'', Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Sections 4.3 (The master method) and 4.4 (Proof of the master theorem), pp. 73–90.</ref>. Suppose that <math>a \geq 1</math> and <math>b > 1</math> above, and <math>f</math> is positive. Then, there are three cases:
 
The authoritative statement of the '''master theorem''' is from CLRS<ref name="CLRS">Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. ''Introduction to Algorithms'', Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Sections 4.3 (The master method) and 4.4 (Proof of the master theorem), pp. 73–90.</ref>. Suppose that <math>a \geq 1</math> and <math>b > 1</math> above, and <math>f</math> is positive. Then, there are three cases:
 
# If <math>f(n) \in O(n^{\log_b a - \epsilon})</math> for some <math>\epsilon > 0</math>, then the overall running time is <math>\Theta(n^{\log_b a})</math>.
 
# If <math>f(n) \in O(n^{\log_b a - \epsilon})</math> for some <math>\epsilon > 0</math>, then the overall running time is <math>\Theta(n^{\log_b a})</math>.
# If <math>f(n) \in \Theta(n^{\log_b a} \log^k n)</math>, for some <math>k \geq 0</math>, then the overall running time is <math>\Theta(n^{\log_b a} log^{k+1} n)</math>.
+
# If <math>f(n) \in \Theta(n^{\log_b a} log^k n)</math>, for some <math>k \geq 0</math>, then the overall running time is <math>\Theta(n^{\log_b a} log^{k+1} n)</math>.
 
# If <math>f(n) \in \Omega(n^{\log_b a + \epsilon})</math> for some <math>\epsilon > 0</math>, and, furthermore, <math>af\left(\frac{n}{b}\right) \leq cf(n)</math> for some <math>c < 1</math> and all sufficiently large <math>n</math>, then the overall running time is <math>\Theta(f(n))</math>.
 
# If <math>f(n) \in \Omega(n^{\log_b a + \epsilon})</math> for some <math>\epsilon > 0</math>, and, furthermore, <math>af\left(\frac{n}{b}\right) \leq cf(n)</math> for some <math>c < 1</math> and all sufficiently large <math>n</math>, then the overall running time is <math>\Theta(f(n))</math>.
  
 
For example, Karatsuba multiplication falls into the first case, since <math>f(n) = n</math> and <math>\log_2 3 \approx 1.58</math>. The theorem then tells us that the overall running time is <math>O(n^{\log_2 3})</math>. What is happening here is that as we proceed from one level to the next, the amount of work done on the current level increases exponentially or faster. In this particular case, each level entails 1.5 times as much work as the previous level. Intuitively, this means most of the work is done on the lowest level, on which we have <math>n</math> subproblems, each with size 1. The earlier analysis then applies. The reason why we need <math>f(n) \in O(n^{\log_b a - \epsilon})</math> is precisely to ensure this exponential growth. If <math>f(n)</math> is exactly <math>n^{\log_b a}</math>, then we will have <math>af\left(\frac{n}{b}\right) = a\frac{n^{\log_b a}}{b^{\log_b a}} = n^{\log_b a} = f(n)</math>, that is, the amount of work done on each level will be the same. But if <math>f(n)</math> grows more slowly than this, then <math>f(n)</math> will be less than <math>af\left(\frac{n}{b}\right)</math>. If it grows polynomially more slowly (that is, by a factor of <math>n^\epsilon</math> or more), then the desired exponential growth will be attained.
 
For example, Karatsuba multiplication falls into the first case, since <math>f(n) = n</math> and <math>\log_2 3 \approx 1.58</math>. The theorem then tells us that the overall running time is <math>O(n^{\log_2 3})</math>. What is happening here is that as we proceed from one level to the next, the amount of work done on the current level increases exponentially or faster. In this particular case, each level entails 1.5 times as much work as the previous level. Intuitively, this means most of the work is done on the lowest level, on which we have <math>n</math> subproblems, each with size 1. The earlier analysis then applies. The reason why we need <math>f(n) \in O(n^{\log_b a - \epsilon})</math> is precisely to ensure this exponential growth. If <math>f(n)</math> is exactly <math>n^{\log_b a}</math>, then we will have <math>af\left(\frac{n}{b}\right) = a\frac{n^{\log_b a}}{b^{\log_b a}} = n^{\log_b a} = f(n)</math>, that is, the amount of work done on each level will be the same. But if <math>f(n)</math> grows more slowly than this, then <math>f(n)</math> will be less than <math>af\left(\frac{n}{b}\right)</math>. If it grows polynomially more slowly (that is, by a factor of <math>n^\epsilon</math> or more), then the desired exponential growth will be attained.
  
Merge sort and the closest pair of points algorithm are covered by case 2. For merge sort, we have <math>k = 0</math> (there is no log factor at all). Here the time spent on each level is the same, since <math>f(n) = af\left(\frac{n}{b}\right)</math> if <math>f(n) = n^{\log_b a}</math>, so we simply multiply <math>f(n)</math> by the number of levels, that is, <math>\log_b n \in \Theta(\log n)</math>. For the closest pair of points algorithm, we have <math>k = 1</math>. When <math>k > 0</math>, then there is a decrease in the amount of work done as we go further down, but it is slower than an exponential decay. In each case the average amount of work done per level is on the order of the amount of work done on the topmost level, so in each case we obtain <math>\Theta(f(n) \log n)</math> time.
+
Merge sort and the closest pair of points algorithm are covered by case 2. For merge sort, we have <math>k = 0</math> (there is no log factor at all). Here the time spent on each level is the same, since <math>f(n) = af\left(\frac{n}{b}\right)</math> if <math>f(n) = n^{log_b a}</math>, so we simply multiply <math>f(n)</math> by the number of levels, that is, <math>\log_b n \in \Theta(\log n)</math>. For the closest pair of points algorithm, we have <math>k = 1</math>. When <math>k > 0</math>, then there is a decrease in the amount of work done as we go further down, but it is slower than an exponential decay. In each case the average amount of work done per level is on the order of the amount of work done on the topmost level, so in each case we obtain <math>\Theta(f(n) \log n)</math> time.
  
 
Case 3 is not often encountered in practice. When <math>f(n) \geq \frac{1}{c}af\left(\frac{n}{b}\right)</math> (with <math>\frac{1}{c} > 1</math>), there is an exponential (or faster) decay as we proceed from the top to the lower levels, so most of the work is done at the top, and hence the <math>\Theta(f(n))</math> behaviour is obtained. The condition that <math>f(n) \in \Omega(n^{\log_b a + \epsilon})</math> is not actually needed in the statement of Case 3, since it is implied by the condition that <math>af\left(\frac{n}{b}\right) \leq cf(n)</math>. The reason why the theorem is stated as it is above is that if <math>f(n)</math> is actually of the form <math>cn^{\log_b a + \epsilon}\log^k n</math>, which covers most of the cases, then the other condition is implied, and we don't need to explicitly check it, but can instead just look at the form of <math>f(n)</math>. However, there are some possibilities for <math>f(n)</math> that are not "well-behaved", and will not satisfy the condition <math>af\left(\frac{n}{b}\right) \leq cf(n)</math>.
 
Case 3 is not often encountered in practice. When <math>f(n) \geq \frac{1}{c}af\left(\frac{n}{b}\right)</math> (with <math>\frac{1}{c} > 1</math>), there is an exponential (or faster) decay as we proceed from the top to the lower levels, so most of the work is done at the top, and hence the <math>\Theta(f(n))</math> behaviour is obtained. The condition that <math>f(n) \in \Omega(n^{\log_b a + \epsilon})</math> is not actually needed in the statement of Case 3, since it is implied by the condition that <math>af\left(\frac{n}{b}\right) \leq cf(n)</math>. The reason why the theorem is stated as it is above is that if <math>f(n)</math> is actually of the form <math>cn^{\log_b a + \epsilon}\log^k n</math>, which covers most of the cases, then the other condition is implied, and we don't need to explicitly check it, but can instead just look at the form of <math>f(n)</math>. However, there are some possibilities for <math>f(n)</math> that are not "well-behaved", and will not satisfy the condition <math>af\left(\frac{n}{b}\right) \leq cf(n)</math>.

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)