From 1e35801bf4b8c6593d5e1cdec79ba73d80c35b39 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Thu, 25 May 2017 16:26:22 +0300 Subject: [PATCH] Clarify number of calls --- chapter02.tex | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/chapter02.tex b/chapter02.tex index f7d3875..e1ed62c 100644 --- a/chapter02.tex +++ b/chapter02.tex @@ -169,15 +169,19 @@ void g(int n) { \end{lstlisting} In this case each function call generates two other calls, except for $n=1$. -Hence, the call $\texttt{g}(n)$ causes the following calls: +Let us see what happens when $g$ is called +with parameter $n$. +The following table shows the function calls +this single call yields: \begin{center} \begin{tabular}{rr} -parameter & number of calls \\ +function call & number of calls \\ \hline -$n$ & 1 \\ -$n-1$ & 2 \\ +$g(n)$ & 1 \\ +$g(n-1)$ & 2 \\ +$g(n-2)$ & 4 \\ $\cdots$ & $\cdots$ \\ -$1$ & $2^{n-1}$ \\ +$g(1)$ & $2^{n-1}$ \\ \end{tabular} \end{center} Based on this, the time complexity is