Question: In a new CPP file task_3.cpp, write: 1. A non-recursive function int s_ver_3(int n) that implements an O(Ign) algorithm that takes n & returns the

 In a new CPP file "task_3.cpp", write: 1. A non-recursive function

int s_ver_3(int n) that implements an O(Ign) algorithm that takes n &

In a new CPP file "task_3.cpp", write: 1. A non-recursive function int s_ver_3(int n) that implements an O(Ign) algorithm that takes n & returns the value of S(n). Use the following formula: Matrix multiplication S(n) (S(n+1) S(n) s(n-1)) = (;_ 2)" =( ( 1) () ...+ n times Hint Convert the exponentiation algorithm discussed previously into an iterative one and replace integer multiplication with matrix multiplication. 2. Write a main function that tests s_ver_3 by printing the first 15 terms of S(n) like so SOLARFARE SEMESAN Task 3: Hint M (S(n + 1) S(n) a Definition of Matrix Multiplication: 2X2 Matrices b f AB= d S(n) S(n - 1) Calculate M in 0 (Ign) time as follows: [Base case] M = 66 (M2) if n is even M = M X Mx(m":") if 2 = ae+bg af +bh ce+dg cf +dh Examples: 1 12 2 1 1 0 1 13 3 2 1 0 2 1 1 1 5 3 1 0 3 2 = (1 0 MN if n is odd (1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!