complete the questions using this photo in python Problem 1 (Factorial with loops) Complete the…

complete the questions using this photo in python Problem 1 (Factorial with loops) Complete the function factorial_loop(num) that takes an integer num and returns the value of num!, i.e., num! = num * (num-1) * (num-2) * … *1. This function must use a loop (iteration) to compute the value of num!. Problem 2 (Factorial with recursion) Complete the function factorial_recursive(num) that takes an integer num and returns the value of num!, i.e., num! = num * (num-1) * (num-2) * … *1. This function must use a recursive design to compute the value of num!. Problem 3 (Factorial with memoization)Memoization is a technique that stores (memorizes) the results of expensive function calls in some data structures, and then returns the stored results whenever the function is called again with the same inputs. This method is useful for speeding up the functions by adding some extra memory space (data structures). A “memoized” function “remembers” the results corresponding to a given input. Subsequent function calls can just return those stored results when necessary rather than recalculating it. Let us take the example of the recursive function factorial_recursive(num) that returns the factorial value of a positive integer num. Suppose we call factorial_recursive(num) three times in the same run, with num = 3, 5 and 7. What happens then is this: factorial_recursive(3) – computes 3! recursively, that is, to compute 3! it has to compute 2! and 1!. factorial_recursive(5) – computes 5! recursively, that is, to compute 5! it has to compute 4!, 3!, 2! and 1!. factorial_recursive(7) – computes 7! recursively, that is, to compute 7! it has to compute 6!, 5!, 4!, 3!, 2! and 1!. Some operations in the above run are done redundantly and we can save time by memoizing that recursive function. factorial_memoized(num, memo_dict) is the ‘memoized’ function that takes an integer num and a dictionary memo_dict as arguments. The function must recursively calculate the factorial value. Additionally, this function must use/update the dictionary memo_dict to save any intermediate calculation results and terminate early if a required value can be found in memo_dict. For example, upon completion of factorial_memoized(5), which computes the value of 5! (i.e., 5*4*3*2*1), memo_dict should store the values of 5!, 4!, 3!, 2!, and 1!. So next time we run the function for 7! (i.e., 7*6*5*4*3*2*1), it should not need to recursively compute the 5*4*3*2*1 part again. Instead, it should be able to use the value of 5! stored in memo_dict and stop early. Problem 4 (Comparing run times in python) Python has a module called time. The method called time.time() returns the time in seconds since the Unix epoch time (the number of seconds since January 1st, 1970 – ignoring the leap seconds) as a floating point number. Try print(time.time()) to see the current time This method can be used to measure and compare runtime of several programs/functions as follows. 1. Measure start_time 2. Perform computation 3. Measure end_time 4. Compute time_taken = end_time – start_time In the commented part of the main() function, the program creates a list of num_tot random integers, and measures and compares the runtimes of three versions of factorial functions mentioned above by using time.time(). Uncomment the code and run the program to find the results. 1.Try running this program with different values of num_tot=50,100,500 and 1000. 2. What happens and any idea why? using Python Programming

Don't use plagiarized sources. Get Your Custom Essay on
complete the questions using this photo in python Problem 1 (Factorial with loops) Complete the…
For as low as $13/Page
Order Essay

Order a unique copy of this paper

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
Top Academic Writers Ready to Help
with Your Research Proposal

Order your essay today and save 15% with the discount code VACCINE