Consider the recurrence relation an=n2an−1−an−2an=n2an−1−an−2
with initial conditions a0=1a0=1 and a1=2a1=2.
Write a Python function called sequence_slayer
that takes a nonnegative integer argument NN less than 50 and
returns the NN-th term in the sequence defined by the above
recurrence relation.
For example, if N=2N=2, your function should return
sequence_slayer(2) = 7, because
aN=a2=(2)2⋅(2)−(1)=7aN=a2=(2)2⋅(2)−(1)=7.
For example:
Test | Result |
---|---|
print(sequence_slayer(2)) |
7 |
print(sequence_slayer(3)) |
61 |
print(sequence_slayer(8)) |
2722564729 |
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU
ANSWER:
CODE:
def sequence_slayer(n):
if n==0:
return 1
elif n==1:
return 2
else:
return ( (n*n*(sequence_slayer(n-1))) - sequence_slayer(n-2) )
print(sequence_slayer(2))
print(sequence_slayer(3))
print(sequence_slayer(8))
Consider the recurrence relation an=n2an−1−an−2an=n2an−1−an−2 with initial conditions a0=1a0=1 and a1=2a1=2. Write a Python function called...
) Solve the following recurrence relation with the given initial conditions: an=10an-1-21an-2 a0=-3 a1=5
: Let a1, a2, a3, . . . be the sequence of integers defined by a1 = 1 and defined for n ≥ 2 by the recurrence relation an = 3an−1 + 1. Using the Principle of Mathematical Induction, prove for all integers n ≥ 1 that an = (3 n − 1) /2 .
8. Solve the recurrence relation together with the initial conditions an--an_ 1 +an-2 + an-3 for n 23,a0-0, al = 1,a2-6.
Consider the sequence {an} defined recursively as: a0 = a1 = a2 = 1, an = an−1+an−2+an−3 for any integer n ≥ 3. (a) Find the values of a3, a4, a5, a6. (b) Use strong induction to prove an ≤ 3n−2 for any integer n ≥ 3. Clearly indicate what is the base step and inductive step, and indicate what is the inductive hypothesis in your proof.
Solve and show work for problem 8 Problem 8. Consider the sequence defined by ao = 1, ai-3, and a',--2an-i-an-2 for n Use the generating function for this sequence to find an explicit (closed) formula for a 2. Problem 1. Let n 2 k. Prove that there are ktS(n, k) surjective functions (n]lk Problem 2. Let n 2 3. Find and prove an explicit formula for the Stirling numbers of the second kind S(n, n-2). Problem 3. Let n 2...
write the solution of the program by python 3 language : I need the program using list : You are given a non-decreasing sequence of n positive integers a1,a2,…,an. Print the number of distinct values in the sequence. For example, if the sequence is 1,2,2,2,3,4,4,5,7,10, the answer is 6 since distinct values are 1,2,3,4,5,7,10. Input The first line contains a positive integer n (1≤n≤1000) — the length of the sequence. The second line contains n space-separated positive integers a1,a2,…,an (1≤ai≤1000)...
MATLAB 1. The Fibonacci sequence is defined by the recurrence relation Fn = Fn-1+Fn-2 where Fo = 0 and F1 = 1. Hence F2 = 1, F3 = 2, F4 = 3, etc. In this problem you will use three different methods to compute the n-th element of the sequence. Then, you will compare the time complexity of these methods. (a) Write a recursive function called fibRec with the following declaration line begin code function nElem = fibrec (n) end...
USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...
python Write a function that takes as input a single integer parametern and computes the nth Fibonacci Sequence number The Fibonacci sequence first two terms are 1 and 1(so, if n - 2 your function should return 1). From there, the previous two values are summed to come up with the next result in the sequence 1.1,2,3,5,8,13, 21, 34, 55, etc.) For example, if the input is 7 then your function should return 13 26561.1615880 1 def Fibonacci(n): # your...
Question 1: Complexity Take a look at the following algorithm written in pseudocode: procedure mystery(a1, a2, …, an: integer) i := 1 while (i < n and ai ≤ ai+1) i := i + 1 if i == n then print “Yes!” else print “No!” What property of the input sequence {an} does this algorithm test? What is the computational complexity of this algorithm, i.e., the number of comparisons being computed as a function of the input size n? Provide...