Questions tagged [recurrence]

A recurrence relation is an equation that recursively defines a sequence, once one or more initial terms are given: each further term of the sequence is defined as a function of the preceding terms.

A recurrence relation is a set of equations that recursively define a sequence, with one or more initial terms given, and each subsequent term defined as a function of the preceding terms.

An example is the Fibonacci sequence, which can be defined as:
F(n) = F(n-1) + F(n-2), with F(0) = 1 and F(1) = 1.

Some simply defined recurrence relations can have very complex (chaotic) behaviours and they are a part of the field of mathematics known as nonlinear analysis.

Solving a recurrence relation means obtaining a closed-form solution: a non-recursive function expressed analytically in terms of a finite number of certain "well-known" functions.

Recurrence relations are of fundamental importance in analysis of algorithms. In computer science, recurrence usually emerges when we analyze the complexity of divide-and-conquer algorithms. If an algorithm is designed so that it will break a problem into smaller subproblems (divide and conquer), its running time is described by a recurrence relation.

For some typical recurrence relations, the asymptotic growth can be analyzed via the Master Theorem.

1040 questions
12
votes
3 answers

Django - How to run a function EVERYDAY?

I want to run this function everyday midnight to check expiry_date_notification. what can I do? I'm new to django and python. def check_expiry_date(request): products = Product.objects.all() for product in products: product_id =…
nabeel
  • 1,181
  • 2
  • 10
  • 24
12
votes
2 answers

When do floors and ceilings matter while solving recurrences?

I came across places where floors and ceilings are neglected while solving recurrences. Example from CLRS (chapter 4, pg.83) where floor is neglected: Here (pg.2, exercise 4.1–1) is an example where ceiling is ignored: (EDIT: I gather from public…
Tejas Patil
  • 6,149
  • 1
  • 23
  • 38
11
votes
6 answers

Can someone help solve this recurrence relation?

T(n) = 2T(n/2) + 0(1) T(n) = T(sqrt(n)) + 0(1) In the first one I use substitution method for n, logn, etc; all gave me wrong answers. Recurrence trees: I don't know if I can apply as the root will be a constant. Can some one help?
rda3mon
  • 1,709
  • 4
  • 25
  • 37
11
votes
4 answers

How to solve: T(n) = T(n - 1) + n

I have the following worked out: T(n) = T(n - 1) + n = O(n^2) Now when I work this out I find that the bound is very loose. Have I done something wrong or is it just that way?
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
11
votes
5 answers

Complexity of the recursion: T(n) = T(n-1) + T(n-2) + C

I want to understand how to arrive at the complexity of the below recurrence relation. T(n) = T(n-1) + T(n-2) + C Given T(1) = C and T(2) = 2C; Generally for equations like T(n) = 2T(n/2) + C (Given T(1) = C), I use the following method. T(n) =…
10
votes
1 answer

Cron job run every x weeks and on specific days

I want to create a cron job that runs every x weeks and on a specific weekdays. for example: run every 2 weeks on midnight every Sunday and Monday. the cron expression is stored for every "plan" and i use ncrontab function in SQL Server 2008 to…
Eddie Rozenblat
  • 832
  • 3
  • 11
  • 21
10
votes
3 answers

Find the formula of this binary recurrence equation? f(m,n) = f(m-1,n) + f(m,n-1)

SORRY GUYS! MY MISTAKE! Thanks for your reminder, I found out f(0,k) == f(k,0) == 1. This question is about how to count the number of shortest paths from grid (0,0) to (m,n). I have to solve the following equation now, find out exactly what f(m,n)…
JXITC
  • 1,110
  • 1
  • 13
  • 27
10
votes
5 answers

How to know when Big O is Logarithmic?

My question arises from the post "Plain English Explanation of Big O". I don't know the exact meaning for logarithmic complexity. I know that I can make a regression between the time and the number of operations and calculate the X-squared value,…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
10
votes
5 answers

How to solve: T(n) = T(n/2) + T(n/4) + T(n/8) + (n)

I know how to do recurrence relations for algorithms that only call itself once, but I'm not sure how to do something that calls itself multiple times in one occurrence. For example: T(n) = T(n/2) + T(n/4) + T(n/8) + (n)
Jack
  • 109
  • 1
  • 1
  • 3
10
votes
3 answers

Solve the recurrence: T(n)=2T(n/2)+n/logn

I can find the sum of each row (n/log n-i) and also I can draw its recursive tree but I can't calculate sum of its rows. T(n)=2T(n/2)+n/logn T(1) = 1
Saeedeh
  • 297
  • 1
  • 4
  • 21
9
votes
1 answer

Solving recurrence equation without the Master's Theorem

So, on a previous exam, I was asked to solve the following recurrence equation without using the Master Theorem: T(n)= 9T(n/3) + n^2 Unfortunately, I couldn't figure it out on the exam, so I used solved it using the Master's Theorem just so I could…
busebd12
  • 997
  • 2
  • 12
  • 24
9
votes
2 answers

Understanding recurrence for running time

I'm doing the exercises in Introduction to Algorithm by CLRS. This is not graded homework or anything, I'm just trying to understand the problem. The problem is as follows: We can express insertion sort as a recursive procedure as follows. In …
Harrison
  • 430
  • 2
  • 6
  • 13
9
votes
4 answers

Understanding recursion in Python

I'm really trying to wrap my brain around how recursion works and understand recursive algorithms. For example, the code below returns 120 when I enter 5, excuse my ignorance, and I'm just not seeing why? def fact(n): if n == 0: return…
suffa
  • 3,606
  • 8
  • 46
  • 66
8
votes
2 answers

Reccurrence T(n) = T(n^(1/2)) + 1

I've been looking at this reccurrence and wanted to check if I was taking the right approach. T(n) = T(n^(1/2)) + 1 = T(n^(1/4)) + 1 + 1 = T(n^(1/8)) + 1 + 1 + 1 ... = 1 + 1 + 1 + ... + 1 (a total of rad n times) = n^(1/2) So the answer would come…
ftsk33
  • 145
  • 1
  • 2
  • 4
8
votes
1 answer

Solving the recurrence relation T(n) = √n T(√n) + n

Is it possible to solve the recurrence relation T(n) = √n T(√n) + n Using the Master Theorem? It is not of the form T(n) = a ⋅ T(n / b) + f(n) but this problem is given in the exercise of CLRS chapter 4.
ahollyhock
  • 105
  • 1
  • 1
  • 3
1
2
3
69 70