a) Produce a pseudo code design for a recursive algorithm to solve this problem. (b) Draw a call-stack diagram to show the application of your recursive algorithm when called using the sequence = (24, 8, −4, 6, −6, 3). (c) Write down the set of recurrence equations for your recursive algorithm. Remember that one of the equations should correspond to the recursive algorithm base case. (d) Using the recurrence equations you gave in your answer for part (c), determine the running time complexity of your recursive algorithm
Personal project Q5.
This question is concerned with the design and analysis of recursive algorithms.
You are given a problem statement as shown below. This problem is concerned with performing calculations on a sequence A of real numbers. Whilst this could be done using a conventional loop-based approach, your answer must be developed using a recursive
FindAverageAndProduct(a1, ...., an) such that n > 1
Input: A sequence of real values A = (a1, ...., an)
Output:, A 2-tuple (average, product) containing the average (average) of all the values and the product (product) of all the values of the elements in A.
Your recursive algorithm should use a single recursive structure to find the average and product values, and should not use two separate instances of a recursive design. You should not employ any global variables.
(a) Produce a pseudo code design for a recursive algorithm to solve this problem.
(b) Draw a call-stack diagram to show the application of your recursive algorithm when called using the sequence = (24, 8, −4, 6, −6, 3).
(c) Write down the set of recurrence equations for your recursive algorithm. Remember that one of the equations should correspond to the recursive algorithm base case.
(d) Using the recurrence equations you gave in your answer for part (c), determine the running time complexity of your recursive algorithm.
Personal project Q8.
A piece of code implementing a recursive algorithm has been produced, and a student has analysed the recurrences. They have produced the recurrence equations as shown below:
T(n) = T(n-3) + 2(n-3) + c1
T(3) = c2
So the recursive algorithm features a base case when the size of the problem is n = 3. The values of c1 and c2 are constants. You should assume the initial value of n (the size of the problem) is divisible by 3.
Determine the running time complexity of this recursive algorithm. To get the full marks, your analysis should be as complete as possible. You can verify your analysis by modelling the recurrence equations in a program like Excel or MATLAB. Your answer must include:
(a) Evidence of at least two cycles of substitutions to establish the running time function T(n).
(b) A clear statement of the generalisation of that pattern to k iterations of the recursive step.
(c) A statement of the number of iterations required to solve a problem of size n.
(d) A statement of the final overall running time complexity that follows from your previous algebra.
You may find it useful to know that the formula for a sum of an arithmetic sequence of numbers of the form (1,2,3, ... . k) is given by the formula: - attached the photo
∑m=1 m=k m = ?(k+1) /2
Step by step
Solved in 3 steps with 1 images