递归公式
递归可以由两个属性定义。基本情况和递归步骤。基本情况是不使用递归来产生结果的终止方案。递归步骤由一组规则组成,这些规则将连续案例减少到转发到基本案例。
递归公式
递归函数是使用前一项定义序列的每个项的函数,即,下一项取决于一个或多个已知的先前项。递归函数h(x) 写成——
h(x) = a 0 h(0) + a 1 h(1) + a 2 h(2) + ... + a x – 1 h(x – 1)
其中 a i ≥ 0 且 i = 0, 1, 2, 3, ... x – 1
递归公式是使用前项/前项定义序列的每个项的公式。它定义了以下参数
- 序列的第一项
- 从之前的术语中获取任何术语的模式规则。
很少有递归公式可以根据给定数据的模式找到第n项。他们是,
- nth term of Arithmetic Progression an = an – 1 + d for n ≥ 2
- nth term of Geometric Progression an = an – 1 × r for n ≥ 2
- nth term in fibonacci Sequence an = an – 1 + an – 2 for n ≥ 2 and a0 = 0 & a1 = 1
Where d is common difference and r is the common ratio
示例问题
问题1:给定一系列数字,中间1、11、21、?、41有一个缺失的数字。使用递归公式找到缺失的项。
解决方案:
Given,
1, 11, 21, _, 41
First term (a) = 1
Difference between terms = 11 – 1 = 10
21 – 11 = 10
So the difference between numbers is same.
Common Difference (d) = 10
Recursive Function to find nth term is an = an-1 + d
a4 = a4-1 + d
= a3 + d
= 21 + 10
a4 = 31
Missing term in the given series is 31.
问题 2:给定数列 5, 9, 13, 17, 21,... 从给定数列中找出递归公式
解决方案:
Given number series
5, 9, 13, 17, 21,…
first term (a) = 5
Difference between terms = 9 – 5 = 4
13 – 9 = 4
17 – 13 = 4
21 – 17 = 4
So the difference between numbers is same.
Common Difference (d) = 4
The given number series is in Arithmetic progression.
So recursive formula an = an-1 + d
an = an-1 + 4
问题3:给定一系列数字,中间1、3、9、_、81、243有一个缺失的数字。使用递归公式找到缺失的项。
解决方案:
Given,
1, 3, 9, _, 81, 243
First term (a) = 1
The difference between numbers are large so It should not be in Arithmetic progression.
Let’s check whether it is in Geometric progression or not,
a2/a1 = 3/1 = 3
a3/a2 = 9/3 = 3
a5/a4 = 243/81 = 3
Hence ratio between adjacent numbers are same. So given series is in Geometric Progression
Common Ratio (r) = 3
Recursive Function to find nth term is an = an-1 × r
a4 = a4-1 × r
= a3 × r
= 9 × 3
a4 = 27
Missing term in the given series is 27.
问题 4:给定数列 2, 4, 8, 16, 32, ... 从给定数列中找出递归公式。
解决方案:
Given number series,
2, 4, 8, 16, 32, …
First term (a) = 2
Difference between terms = 4 – 2 = 2
8 – 4 = 4
It is not in A.P as difference between numbers are not same.
Let’s check whether it is in Geometric progression or not
a2/a1 = 4/2 = 2
a3/a2 = 8/4 = 2
a4/a3 = 16/8 = 2
Common Ratio (r) = 2
The given number series is in Geometric progression.
So recursive formula an = an-1 × r
an = an-1 × 2
问题 5:如果第3项和第 4项分别为 2,3,则在斐波那契数列中找到第 5 项。
解决方案:
Given that number series is in fibonacci series form.
Also given a3 = 2
a4 = 4
Then a5 = a3 + a4
= 2 + 3
a5 = 5
问题 6:在给定系列 1、1、2、3、5、8、13 中找到下一项
解决方案:
Given,
1, 1, 2, 3, 5, 8, 13,…
The given series is in fibonacci form because every nth term is the result of addition between two previous terms i.e., n – 1th & n – 2th terms
Example: a3 = a1 + a2
3 = 1 + 2
Then a8 = a7 + a6
= 13 + 8
a8 = 21