I'm solving a practice quiz and came across the following question
Write down the recurrence corresponding to the below divide and conquer algorithm, labeling exactly the components for each of: dividing, conquering, and combining.
1. Foo (p, r):
2. if p = r
3. return (1)
4. else
5. s ← 1
6. for i = p to r
7. s ← s * i
8. q ← Foo(p, r − 1) * s
9. return (q)
My attempt at an answer.
Let T(n) be the work done by Foo over p to r, so T(n) is equivalent of Foo(p, r) where n is r - p + 1.
I get the following recurrence T(n) = T(n - 1) + Θ(n) + Θ(1)
The dividing part would be a constant Θ(1) which corresponds to the r-1 operation.
The conquering part would be the T(n - 1) which is recursively solving the sub-problem.
The combining part is a constant Θ(1) for the multiplication operation of T(n - 1) * s.
But that seems wrong as I didn't mention the Θ(n). What part of dividing, conquering, combining should the Θ(n) of lines 6,7 fall into?