Questions tagged [recurrence-relation]

a definition of a sequence where later elements are expressed as a function of earlier elements.

A recurrence relation is a way to define a sequence in which later elements are computed from earlier elements. Note that a sequence can but need not consist of numbers; sequences of words, trees and all kinds of other things are equally possible.

Examples

  • $x_0 = 0, x_{n+1} = 2 x_n$ is a recurrence relation that defines the sequence $0,2,4,6,\dots$ or $(2k)_{k\in\mathbb{N}}$.
  • $F_0=0,F_1=1,F_{n+2}=F_{n+1}+F_n$ is the recurrence of the famous Fibonacci sequence.
  • $y_0=0, y_n = \sum_{k=0}^{n-1} (y_k + k)$ is a recurrence that uses a full history.
  • $\mathrm{reverse}([]) = [], \mathrm{reverse}(x::t) = \mathrm{reverse}(t) + [x]$ is a recurrence defines the function that reverses a list.
  • $f_0=g_0=1, f_{n+1}=f_n +g_n, g_{n+1}=f_n \cdot g_n$ is a mutual recurrence that defines two sequences simultaneously.
  • $\mathrm{Tree} = \mathrm{Leaf} \mid \mathrm{Node}(\mathrm{Tree},\mathrm{Tree})$ is a recursive type definition for full binary trees. It implies the montone recurrence $f_0 = \{\mathrm{Leaf}\}, f_{n+1}=f_n \cup \{\mathrm{Node}(l,r) \mid l,r \in f_n\}$ whose limit is the set of all such trees.

Solving a recurrence

To solve a recurrence means to find a closed form for it. This is not always possible as a closed form may not even exist.

When studying the complexity of algorithms (often ), recurrence relations over integers often arise, following the recursive structure of the algorithm. Some well-known methods for solving such recurrences include generating functions and (for asymptotic results) the Master Theorem.

With some experience it also often possible to guess the solution (for example by writing down the first few elements and their structure) and prove it correct by induction.

730 questions
12
votes
1 answer

Solving T(n) = 2T(n/2) + log n with the recurrence tree method

I was solving recurrence relations. The first recurrence relation was $T(n)=2T(n/2)+n$ The solution of this one can be found by Master Theorem or the recurrence tree method. The recurrence tree would be something like this: The solution would be:…
RajS
  • 1,667
  • 4
  • 26
  • 46
8
votes
2 answers

Reccurence $T(n) = \sqrt{n}T(\sqrt{n})+n$

Note: this is from JeffE's Algorithms notes on Recurrences, page 5. (1). So we define the recurrence $T(n) = \sqrt{n}T(\sqrt{n})+n$ without any base case. Now I understand that for most recurrences, since we're looking for asymptotic bounds, the…
7
votes
1 answer

Trouble understanding the master theorem, from Jeffrey Erickson's Notes

I'm looking at Jeffrey Erickson's Notes on the master theorem (page 10). Part (b) of the theorem states that if $T(n) = aT(\frac{n}{b})+f(n)$, $af(\frac{n}{b}) = kf(n)$ and $k>1$ then T(n) is $\Theta(n^{\log_b(a)})$. But I get a different…
Retired account
  • 204
  • 1
  • 8
6
votes
2 answers

How to solve T(n) = T(n-1) + n^2?

See title. I'm trying to apply the method from this question. What I have so far is this, but I don't know how to proceed from here on: T(n) = T(n-1) + n2 T(n-1) = T(n-2) + (n-1)2 = T(n-2) + n2 - 2n + 1 T(n-2) = T(n-3) + (n-2)2 = T(n-3) + n2 - 4n +…
Ken
  • 195
  • 1
  • 1
  • 5
6
votes
1 answer

Why is $\sum_{j=1}^{n-1}[\Pi_{k=1}^{j}[(n-k)]]=2^n$?

In CLRS book, in the road cutting example there is a recursion formula $$ 1+\sum_{j=0}^{n-1}T(j) $$ and it can be proved that the sum is $$ 2^n $$ by simple induction. In 3-rd edition it is a formula 15.3 on a page 364. As I can…
user19668
  • 163
  • 3
5
votes
1 answer

Making a conjecture of a closed form

There's a formula given $$ T(m,n) = \left\{ \begin{array}{l l} 1 & \quad \text{if $m=0$}\\ 1+T(n \mod m, m) & \quad \text{if $m>0$} \end{array} \right.$$ We're told to use repeated substitution to make a conjecture about a closed form…
4
votes
1 answer

How do I know the height from recursion tree of $T(n)=4T(n/2+2)+n$?

I already saw this answer. But I didn't understand totally. So I found the solution to this equation $T(n)=4T(n/2+2)+n$. Here is the recursion tree. But I can't compute the height as $lgn$ from this tree. How to compute height? (Image is from…
molamola
  • 353
  • 2
  • 4
  • 11
4
votes
2 answers

How to calculate the time complexity of a Catalan-like recurrence by substitution?

I was given the following problem: Calculate the computational time complexity of the recurrence $$P(n) = \begin{cases} 1 & \text{if } n = 1 \\ \sum_{k=1}^{n-1} P(k) P(n-k) & \text{if } n \geq 2 \end{cases}$$ using the substitution method. Answer:…
logo_writer
  • 215
  • 1
  • 9
4
votes
1 answer

Solving recurrence relations with two variables

I am trying to solve this recurrence relation with two variables: $$T(n, k) = T(n - 1, k - 1) + T(n - 1, k)$$ The base cases are: $T(n, k) = 1$ if $k = 0$ $T(n, k) = 0$ if $k > n$ I was wondering if standard techniques like characteristic…
3
votes
3 answers

Solving $$f(x, k) = f(x, k-1) + f(x-1, k-1) + \dots + f(1, k-1)$$ in terms of $x$

I'm having trouble determining the complexity of an algorithm. Let's say the number of operations of my algorithm is described by $$f(x, k) = f(x, k-1) + f(x-1, k-1) + f(x-2, k-1) + \dots + f(1, k-1)$$ where $f(x, 1) = x$ How can I describe the…
nave
  • 131
  • 3
3
votes
2 answers

Solving a two-variable recurrence

I've written a function. I believe the function runs in complexity: $$ T(m, n) = \begin{cases} T(m-1, n) + T(m, n-1) + T(m-1, n-1) + 1 &\text{if $m,n>0$}\\ 0 &\text{otherwise} \end{cases} $$ I have no idea…
Nevo
  • 131
  • 1
3
votes
2 answers

Solving the recurrence $T(n)=T(n−1)/T(n−2)$

How can I solve this? I saw Solving the recurrence $T(n)=T(n-1)*T(n-2)$ but I don't know how I can apply it to $T(n)=T(n-1)/T(n-2)$?
user79716
  • 33
  • 3
3
votes
0 answers

Solve Recurrence Equation Problem

How we calculate the answer of following recurrence? $$T(n)=4T\left(\frac{\sqrt{n}}{3}\right)+ \log^2n\,.$$ Any nice solution would be highly appreciated. My solution is to substitute $n=3^m$, giving $$T(3^m)=4T\left(\frac{3^{m/2}}{3}\right)+\log^2…
Mina Simin
  • 43
  • 6
3
votes
1 answer

Closed formula for two variable recurrence

I would like to know if there exists a closed form formula to the following recurrence: $f(s, 0) = 1$ $f(s,b) = \displaystyle\sum_{i=1}^{min(s, b)} \left[ (s-i+1)\times f(i, b-i) \right] $ This recurrence gives the solution to problem F of the…
3
votes
1 answer

Solving recurrence relation with different rules for odd and even n

Assume $T(1) = 1$, and $T(n) = 2T(n/2) + n^2$ for even $n$, $T(n) = T(n − 1) + n$ for odd $n$. I'm new of learning to solve recurrence problem, for 1, it seems we can apply Master Theorem directly and we got $a = 2$, $b = 2$, $d = 2$, therefore…
hh vh
  • 361
  • 2
  • 13
1
2 3
8 9