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 stepSolved in 3 steps with 1 images
- Python Using recursion only No loops Note that in a correct solution the isdigit method or in operator will never be applied to the entire string s. The function must return and not print the resulting string. def getDigits(s):arrow_forwardPlease help me with this using java and recursionarrow_forwardWrite a recursive method that returns the value of N! (N factorial) using the definition given in this chapter. Explain why you would not normally use recursion to solve this problem.arrow_forward
- T/F 3. Iteratively traversing a labyrinth is much faster than recursively traversing one.arrow_forwardCS211 Non-recursive solution for Towers of Hanoi Using the algorithm discussed in class, write an iterative program to solve the Towers of Hanoi problem. The problem: You are given three towers a, b, and c. We start with n rings on tower a and we need to transfer them to tower b subject to the following restrictions: 1. We can only move one ring at a time, and 2. We may never put a larger numbered ring on top of a smaller numbered one. There are always 3 towers. Your program will prompt the user for the number of rings. Here is the algorithm. Definition: A ring is "available" if it is on the top of one of the towers. Definition: The "candidate" is the smallest available ring that has not been moved on the most recent move. The first candidate is ring 1. The Algorithm: 1. Find the candidate. 2. Move the candidate (right or left, depending if the number of rings is odd or even) to the closest tower on which it can be placed. Move "around the circle" if necessary. 3. If not done, go back…arrow_forwardBacktracking normally uses ______ to find out all solutions to a computational problem. (recursion, iteration).arrow_forward
- T/F 11. A recursion will still be replaced by an iteration and the other way around.arrow_forwardWhen recursion is used to solve a problem, why must the recursive method call itself to solve a smaller version of the original problem?arrow_forwardJava source code writing - a recursive algorithm. Please use non-recursive and recursive ways to compute the nth Harmonic number, defined as H. Turn in your java source code file with three methods, including one main() method.arrow_forward
- 10. write general plan for analyzing recursive algorithms.arrow_forwarddiscrete matharrow_forwardThe Tower of Hanoi is a puzzle where n disks of different sizes arestacked in ascending order on one rod and there are two other rods with nodisks on them. The objective is to move all disks from the first rod to thethird, such that:- only one disk is moved at a time- a larger disk can never be placed on top of a smaller oneWrite a recursive function that outputs the sequence of steps needed tosolve the puzzle with n disks.Write a test program in C++ that allows the user to input number of disks andthen uses your function to output the steps needed to solve the puzzle.Hint: If you could move up n−1 of the disks from the first post to thethird post using the second post as a spare, the last disk could be moved fromthe first post to the second post. Then by using the same technique you canmove the n−1 disks from the third post to the second post, using the firstdisk as a spare. There! You have the puzzle solved. You only have to decidewhat the nonrecursive case is, what the recursive…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education