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.

749 questions
98
votes
11 answers

Solving or approximating recurrence relations for sequences of numbers

In computer science, we have often have to solve recurrence relations, that is find a closed form for a recursively defined sequence of numbers. When considering runtimes, we are often interested mainly in the sequence's asymptotic growth. Examples…
24
votes
2 answers

Changing variables in recurrence relations

Currently, I am self-studying Intro to Algorithms (CLRS) and there is one particular method they outline in the book to solve recurrence relations. The following method can be illustrated with this example. Suppose we have the recurrence $$T(n) =…
21
votes
1 answer

Solving divide & conquer reccurences if the split-ratio depends on $n$

Is there a general method to solve the recurrence of the form: $T(n) = T(n-n^c) + T(n^c) + f(n)$ for $c < 1$, or more generally $T(n) = T(n-g(n)) + T(r(n)) + f(n)$ where $g(n),r(n)$ are some sub-linear functions of $n$. Update: I have gone through…
Plummer
  • 443
  • 2
  • 7
20
votes
1 answer

Rigorous proof for validity of assumption $n=b^k$ when using the Master theorem

The Master theorem is a beautiful tool for solving certain kinds of recurrences. However, we often gloss over an integral part when applying it. For example, during the analysis of Mergesort we happily go from $\qquad T(n) = T\left(\left\lfloor…
Raphael
  • 73,212
  • 30
  • 182
  • 400
19
votes
5 answers

How long does the Collatz recursion run?

I have the following Python code. def collatz(n): if n <= 1: return True elif (n%2==0): return collatz(n/2) else: return collatz(3*n+1) What is the running-time of this algorithm? Try: If $T(n)$ denotes the…
19
votes
1 answer

Proving the (in)tractability of this Nth prime recurrence

As follows from my previous question, I've been playing with the Riemann hypothesis as a matter of recreational mathematics. In the process, I've come to a rather interesting recurrence, and I'm curious as to its name, its reductions, and its…
18
votes
5 answers

Solving a recurrence relation with √n as parameter

Consider the recurrence $\qquad\displaystyle T(n) = \sqrt{n} \cdot T\bigl(\sqrt{n}\bigr) + c\,n$ for $n \gt 2$ with some positive constant $c$, and $T(2) = 1$. I know the Master theorem for solving recurrences, but I'm not sure as to how we could…
seeker
  • 283
  • 1
  • 2
  • 6
16
votes
5 answers

Efficient algorithm to compute the $n$th Fibonacci number

The $n$th Fibonacci number can be computed in linear time using the following recurrence: def fib(n): i, j = 1, 1 for k in {1...n-1}: i, j = j, i+j return i The $n$th Fibonacci number can also be computed as $\left[\varphi^n /…
augurar
  • 271
  • 2
  • 6
16
votes
3 answers

Solving Recurrence Equations containing two Recursion Calls

I am trying to find a $\Theta$ bound for the following recurrence equation: $$ T(n) = 2 T(n/2) + T(n/3) + 2n^2+ 5n + 42 $$ I figure Master Theorem is inappropriate due to differing amount of subproblems and divisions. Also recursion trees do not…
Laura
  • 544
  • 1
  • 3
  • 10
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,737
  • 5
  • 28
  • 50
12
votes
3 answers

Understanding an algorithm for the gas station problem

In the gas station problem we are given $n$ cities $\{ 0, \ldots, n-1 \}$ and roads between them. Each road has length and each city defines price of the fuel. One unit of road costs one unit of fuel. Our goal is to go from a source to a destination…
Wojciech Kulik
  • 223
  • 3
  • 10
12
votes
2 answers

Master theorem not applicable?

Given the following recursive equation $$ T(n) = 2T\left(\frac{n}{2}\right)+n\log n$$ we want to apply the Master theorem and note that $$ n^{\log_2(2)} = n.$$ Now we check the first two cases for $\varepsilon > 0$, that is whether $n\log n \in…
11
votes
1 answer

Intuition behind the Master Theorem

The Master Theorem provides a method of solving recurrence relations for divide-and-conquer algorithms. It was first presented to me in my intro algorithms class as the following: For a recurrence of the form $T(n) = aT(\frac{n}{b})+f(n)$ with…
roctothorpe
  • 1,168
  • 8
  • 20
10
votes
3 answers

Error in the use of asymptotic notation

I'm trying to understand what is wrong with the following proof of the following recurrence $$ T(n) = 2\,T\!\left(\left\lfloor\frac{n}{2}\right\rfloor\right)+n $$ $$ T(n) \leq 2\left(c\left\lfloor\frac{n}{2}\right\rfloor\right)+n \leq cn+n =…
10
votes
1 answer

Solving recurrence relation with two recursive calls

I'm studying the worst case runtime of quicksort under the condition that it will never do a very unbalanced partition for varying definitions of very. In order to do this I ask myself the question what the runtime $T(n, p)$ would be in the case…
orlp
  • 13,988
  • 1
  • 26
  • 41
1
2 3
49 50