⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap2.tex

📁 Concrete_Mathematics_2nd_Ed_TeX_Source_Code
💻 TEX
📖 第 1 页 / 共 5 页
字号:
"!arithmetic progression"$\alpha=\beta=a$, $\gamma=b$, and the answer is$aA(n)+aB(n)+bC(n)=a(n+1)+b(n+1)n/2$.Conversely, many recurrences can be reduced to sums; therefore thespecial methods for evaluating sums that we'll be learning laterin this chapter will help us solve recurrences that might otherwisebe difficult. The "Tower of Hanoi" recurrence is a case in point:\begindisplayT_0&=0\,;\crT_n&=2T_{n-1}+1\,,\qquad\hbox{for $n>0$}.\cr\enddisplayIt can be put into the special form \eq(|sum-rec|)if we divide both sides by $2^n$:\begindisplayT_0/2^0&=0;\crT_n/2^n&=T_{n-1}/2^{n-1}+1/2^n\,,\qquad\hbox{for $n>0$}.\cr\enddisplayNow we can set $S_n=T_n/2^n$, and we have\begindisplayS_0&=0;\crS_n&=S_{n-1}+2^{-n}\,,\qquad\hbox{for $n>0$}.\cr\enddisplayIt follows that\begindisplayS_n=\sum_{k=1}^n 2^{-k}.\enddisplay(Notice that we've left the term for $k=0$ out of this sum.)The sum of the geometric series $2^{-1}+2^{-2}+\cdots+2^{-n}=(\half )^1+(\half )^2+\cdots+(\half )^n$ will be derivedlater in this chapter; it turns out to be $1-(\half )^n$.Hence $T_n=2^nS_n=2^n-1$.We have converted $T_n$ to $S_n$ in this derivation by noticing thatthe recurrence could be divided by $2^n$. This trickis a special case of a general techniquethat can reduce virtually any "recurrence" of the form\begindisplaya_nT_n=b_nT_{n-1}+c_n\eqno\eqref|sum-factor-rec|\enddisplayto a sum. The idea is to multiply both sides by a{\it"summation factor"},~$s_n$:\begindisplays_na_nT_n=s_nb_nT_{n-1}+s_nc_n\,.\enddisplayThis factor $s_n$ is cleverly chosen to make\begindisplays_nb_n=s_{n-1}a_{n-1}\,.\enddisplayThen if we write $S_n=s_na_nT_n$ we have a sum-recurrence,\begindisplayS_n=S_{n-1}+s_nc_n\,.\enddisplayHence\begindisplayS_n=s_0a_0T_0+\sum_{k=1}^n s_kc_k=s_1b_1T_0+\sum_{k=1}^n s_kc_k\,,\enddisplayand the solution to the original recurrence \thiseq\ is\begindisplayT_n={1\over s_na_n}\biggl(s_1b_1T_0+\sum_{k=1}^n s_kc_k\biggr)\,.\eqno\eqref|sum-factor-sol|\enddisplay\g(The value of $s_1$ cancels out, so it can be anything but~zero.)\gFor example, when $n=1$ we get $T_1=(s_1b_1T_0+s_1c_1)/s_1a_1=(b_1T_0+c_1)/a_1$.But how can we be clever enough to find the right $s_n$? No problem:The relation $s_n=s_{n-1}a_{n-1}/b_n$ can be unfolded totell us that the fraction\begindisplays_n={a_{n-1}a_{n-2}\ldots a_1\over b_nb_{n-1}\ldots b_2}\,,\eqno\eqref|sum-factor|\enddisplayor any convenient constant multiple of this value, will be a suitable summation factor.For example, the Tower of Hanoi recurrence has $a_n=1$ and $b_n=2$;the general method we've just derived says that $s_n=2^{-n}$ is a goodthing to multiply by, if we want to reduce the recurrence to a sum.We don't need a brilliant flash of inspiration to discover this multiplier.We must be careful, as always, not to divide by zero. The summation-factormethod works whenever all the $a$'s and all the $b$'s are nonzero.Let's apply these ideas to a recurrence that arises in the study of``"quicksort",\qback'' one of the most important methods for "sorting"\g(Quicksort was invented by "Hoare" in 1962~[|hoare|].)\gdata inside a computer. The average number of comparison steps made byquicksort when it is applied to $n$ items in random order satisfies therecurrence\begindisplay\eqalign{C_0&=0\,;\cr   C_n	&= n+1+{2\over n}\sum_{k=0}^{n-1}C_k\,, \qquad\hbox{for $n>0$.}\cr}\eqno\eqref|quicksort-rec|\enddisplayHmmm. This looks much scarier than the recurrences we've seen before;it includes a sum over all previous values, and a division by~$n$.Trying small cases gives us some data ($C_1=2$, $C_2=5$, $C_3={26\over3}$)but doesn't do anything to quell our fears.We can, however, reduce the complexity of \thiseq\systematically, by first getting rid of the division and thengetting rid of the $\sum$ sign. The idea is tomultiply both sides by~$n$, obtaining the relation\begindisplaynC_n=n^2+n+2\sum_{k=0}^{n-1}C_k\,,\qquad\hbox{for $n>0$};\enddisplayhence, if we replace $n$ by $n-1$,\begindisplay(n-1)C_{n-1}=(n-1)^2+(n-1)+2\sum_{k=0}^{n-2}C_k\,,\qquad\hbox{for $n-1>0$}.\enddisplayWe can now subtract the second equation from the first, and the $\sum$ signdisappears:\begindisplaynC_n-(n-1)C_{n-1}=2n+2C_{n-1}\,,\qquad\hbox{for $n>1$}.\enddisplayIt turns out that this relation also holds when $n=1$, because $C_1=2$.Therefore the original recurrence for $C_n$ reduces to a much simpler one:\begindisplayC_0&=0\,;\crnC_n&=(n+1)C_{n-1}+2n\,,\qquad\hbox{for $n>0$}.\enddisplayProgress.We're now in a position to apply a summation factor, since this recurrencehas the form of \eq(|sum-factor-rec|) with $a_n=n$, $b_n=n+1$, and $c_n=2n$.The general method described on the preceding pagetells us to multiply the recurrencethrough by some multiple of\begindisplays_n={a_{n-1}a_{n-2}\ldots a_1\over b_nb_{n-1}\ldots b_2}={(n-1)\cdot(n-2)\cdot\ldots\cdot1\over(n+1)\cdot n\cdot\ldots\cdot3}={2\over(n+1)n}\,.\enddisplayThe solution, according to\g We started with a $\sum$ in the recurrence, and worked hardto get rid of it. But then after applying a summation factor,we came up with another $\sum$. Are sums good, or bad, or what?\g\eq(|sum-factor-sol|), is therefore\begindisplayC_n=2(n+1)\sum_{k=1}^n{1\over k+1}\,.\enddisplayThe sum that remains is very similar to a quantity that arises frequentlyin applications. It arises so often, in fact, that we give it a special nameand a special notation:\begindisplayH_n=1+\half +\cdots+{1\over n}=\sum_{k=1}^n {1\over k}\,.\eqno\eqref|h-def|\enddisplay\tabref|nn:hn|%The letter $H$ stands for ``harmonic''; $H_n$ is a {\it "harmonic number"},so called because the $k$th harmonic produced by a "violin" stringis the fundamental tone produced by a string that is~$1/k$ times as long.We can complete our study of the quicksort recurrence \eq(|quicksort-rec|)by putting $C_n$ into closed form; this will be possible if we canexpress $C_n$ in terms of $H_n$. The sum in our formula for $C_n$ is\begindisplay\sum_{k=1}^n{1\over k+1}=\sum_{1\le k\le n}{1\over k+1}\,.\enddisplayWe can relate this to $H_n$ without much difficulty by changing $k$ to $k-1$ and revising theboundary conditions:\begindisplay \openup2pt\sum_{1\le k\le n}{1\over k+1}&=\sum_{1\le k-1\le n}{1\over k}\cr &=\sum_{2\le k\le n+1}{1\over k}\cr &=\biggl(\sum_{1\le k\le n}{1\over k}\biggr) -{1\over 1}+{1\over n+1} = H_n-{n\over n+1}\,.\cr\enddisplayAlright! We have found the sum needed to complete the\g But your spelling is alwrong.\g solution to \eq(|quicksort-rec|):The average number of comparisons made by quicksort when it is applied to$n$~randomly ordered items of data is\begindisplayC_n=2(n+1)H_n-2n\,.\eqno\enddisplayAs usual, we check that small cases are correct: $C_0=0$, $C_1=2$, $C_2=5$.\beginsection 2.3 Manipulation of SumsThe key to success with sums is an ability to change one $\sum$ into another\g\vskip-38pt Not to be confused with finance.\gthat is simpler or closer to some goal. And it's easy to do this by learninga few basic rules of transformation and by practicing their use.Let $K$ be any finite set of integers. Sums over the elements of $K$ can betransformed by using three simple rules:\begindisplay\sum_{k\in K} ca_k&=c\sum_{k\in K}a_k\,;&\qquad\hbox{(distributive law)} \eqno\eqref|dist-law|\cr\noalign{\smallskip}\sum_{k\in K}(a_k+b_k)&=\sum_{k\in K}a_k+\sum_{k\in K}b_k\,; &\qquad\hbox{(associative law)} \eqno\eqref|assoc-law|\cr\noalign{\smallskip}\sum_{k\in K}a_k&=\sum_{p(k)\in K}a_{p(k)}\,. &\qquad\hbox{(commutative law)} \eqno\eqref|comm-law|\cr\enddisplayThe "distributive law" allows us to move constants in and out of a $\sum$.The "associative law" allows us to break a $\sum$ into two parts, or tocombine two $\sum$'s into one. The "commutative law" says that we canreorder the terms in any way we please; here $p(k)$ is any permutation\g Why not call it permutative instead of commutative?\gof the set of all integers.For example, if $K=\{-1,0,+1\}$ and if $p(k)=-k$, these three lawstell us respectively that\begindisplay&ca_{-1}+ca_0+ca_1=c(a_{-1}+a_0+a_1)\,;&\qquad\hbox{(distributive law)}\cr\noalign{\vskip2pt}&(a_{-1}+b_{-1})+(a_0+b_0)+(a_1+b_1)\cr&\quad=(a_{-1}+a_0+a_1)+(b_{-1}+b_0+b_1)\,; &\qquad\hbox{(associative law)}\cr\noalign{\vskip2pt}&a_{-1}+a_0+a_1=a_1+a_0+a_{-1}\,.&\qquad\hbox{(commutative law)}\cr\enddisplay"Gauss"'s trick in Chapter 1 can be viewed as an application of these threebasic laws. Suppose we want to compute the general sum of an{\it"arithmetic progression"},\begindisplayS=\sum_{0\le k\le n}(a+bk)\,.\enddisplayBy the commutative law we can replace $k$ by $n-k$,\g This is something like changing variables inside an integral, but easier.\g obtaining\begindisplayS=\sum_{0\le n-k\le n}\bigl(a+b(n-k)\bigr)=\sum_{0\le k\le n}(a+bn-bk)\,.\enddisplayThese two equations can be added by using the associative law:\begindisplay2S=\sum_{0\le k\le n}\bigl((a+bk)+(a+bn-bk)\bigr)  =\sum_{0\le k\le n}(2a+bn)\,.\enddisplayAnd we can now apply the distributive law and evaluate a trivial sum:\g ``What's one and one and one and one and one and one and one and oneand one and~one?''\par``I don't know,'' said~"Alice".\par ``I lost count.''\par % from Chapter 9``She can't do Addition.''\par\hfill\kern-4pt\dash---Lewis "Carroll"~[|alice-looking|]\g %\begindisplay2S=(2a+bn)\sum_{0\le k\le n}1 = (2a+bn)(n+1)\,.\enddisplayDividing by 2, we have proved that\begindisplay\sum_{k=0}^n(a+bk)=\textstyle(a+\half bn)(n+1)\,.\eqno\eqref|arith-sum|\enddisplayThe right-hand side can be remembered as the average of thefirst and last terms,namely $\half \bigl(a+(a+bn)\bigr)$, times the number of terms,namely $(n+1)$.It's important to bear in mind that the function $p(k)$ in the generalcommutative law \eq(|comm-law|)is supposed to be a permutation of all the integers. In other words,for every integer~$n$ there should be exactly one integer~$k$ such that$p(k)=n$. Otherwise the commutative law might fail; exercise~|bad-perm|illustrates this with a vengeance. Transformations like $p(k)=k+c$or $p(k)=c-k$, where $c$~is an integer constant, are alwayspermutations, so they always work.On the other hand, we can relax the permutation restriction a little"!commutative law, relaxed"bit: We need to require only that there be exactly one integer~$k$ with$p(k)=n$ when $n$ is an element of the index set~$K$. If $n\notin K$(that is, if $n$ is not in~$K$), it doesn't matter how often $p(k)=n$ occurs,because such $k$ don't take part in the sum.Thus, for example, we can argue that\begindisplay\sum\twoconditions{k\in K}{k{\rm\ even}}a_k=\sum\twoconditions{n\in K}{n{\rm\ even}}a_n=\sum\twoconditions{2k\in K}{2k{\rm\ even}}a_{2k}=\sum_{2k\in K}a_{2k}\,,\eqno\eqref|even-trick|\enddisplaysince there's exactly one $k$ such that $2k=n$ when $n\in K$ and $n$ is even."Iverson's convention", which allows us to obtain the values $0$ or~$1$from logical statements in the middle of a formula, can be usedtogether with the distributive, associative, and commutative laws to deduce\g Additional, eh?\gadditional properties of sums. For example, here is an important rule forcombining different sets of indices:If $K$ and $K'$ are any sets of integers, then\begindisplay\sum_{k\in K}a_k\;+\;\sum_{k\in K'}a_k\;=\;\sum_{k\in K\cap K'}a_k\;+\; \sum_{k\in K\cup K'}a_k\,.\eqno\eqref|set-sum|\enddisplayThis follows from the general formulas\begindisplay\sum_{k\in K}a_k\;=\;\sum_k a_k\,\[k\in K]\eqno\enddisplayand\begindisplay\[k\in K]+\[k\in K']=\[k\in K\cap K']+\[k\in K\cup K']\,.\eqno\enddisplayTypically we use rule \eq(|set-sum|) either to combine two almost-disjointindex sets, as in\begindisplay\sum_{k=1}^m a_k\;+\;\sum_{k=m}^n a_k\;=\;a_m\;+\;\sum_{k=1}^n a_k\,,\qquad\hbox{for $1\le m\le n$};\enddisplayor to split off a single term from a sum, as in\g\vskip15pt(The two sides of \eq(|set-sum|) have been switched here.)\g\begindisplay\sum_{0\le k\le n}a_k\;=\;a_0\;+\;\sum_{1\le k\le n}a_k\,,\qquad\hbox{for $n\ge0$}.\eqno\enddisplayThis operation of splitting off a term is the basis of a{\it"perturbation method"\/} that often allows us to evaluate asum in closed form. The idea is to start with an unknown sumand call it $S_n$:\begindisplayS_n=\sum_{0\le k\le n}a_k\,.\enddisplay(Name and conquer.)Then we rewrite $S_{n+1}$ in two ways, by splitting off both itslast term and its first term:\begindisplay \openup2ptS_n+a_{n+1}=\sum_{0\le k\le n+1}a_k&=a_0+\sum_{1\le k\le n+1}a_k\cr&=a_0+\sum_{1\le k+1\le n+1}a_{k+1}\cr&=a_0+\sum_{0\le k\le n}a_{k+1}\,.\eqno\eqref|perturb-setup|\cr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -