- Published on
The Algorithm Design Manual (3rd) Exercise Solution 'E2-41'
Table of Contents
Introduction
This series is my solutions for algorithm exercises in'The Algorithm Design Manual' 3rd edition.
It's my solutions, not model answers, so if you find some mistakes or more sophisticated solutions, please post in comment area below.
Repository
Exercise 2-41
Question
Consider the following code fragment:
for i=1 to n/2 do
for j=i to n-i do
for k=1 to j do
output ‘‘foobar’’
Assume is even. Let denote the number of times “foobar” is printed as a function of .
(a) Express as three nested summations.
(b) Simplify the summation. Show your work.
Solution
(a)
(b)
Here, we use a new variable :
Rethink the expansion of .