Given algorithm- procedure factorial (n: nonnegative integer) if n = 0 then return 1 else return n*factorial(n-1) {output is n!} Trace the above algorithm when it is given n = 7 as input. That is, show all steps used by above algorithm to find 7!

factorial(1) = 1 factorial(2) = 2 * factorial(1) = 2 * 1 = 2 factorial(3) = 3 * factorial(2) = 3 * 2 = 6 factorial(4) = 4 * factorial(3) = 4 * 6 = 24 factorial(5) = 5 * factorial(4) = 5 * 24 = 120 factorial(6) = 6 * factorial(5) = 6 * 120 = 720 factorial(7) = 7 * factorial(6) = 7 * 720 = 5040
Given algorithm- procedure factorial (n: nonnegative integer) if n = 0 then return 1 else return...
Recursive definition for factorial: a0 = 1, an = n * an-1 procedure factorial(n: nonnegative integer) if n = 0 then return 1 else return n * factorial( n - 1 ) Trace the execution of the factorial algorithm described above for input 7. Track the number of times factorial is invoked (with the first invocation with input 7 as invocation 0) and the value returned by each invocation.
ALGORITHM RecS(n) // Input: A nonnegative integer n ifn=0 return 0 else return RecS(n+ n n n Determine what this algorithm computes. You must justify your answer. made by this algorithm and solve it. You must justify your answer. same thing using for/while loop(s) developed in (3). You must justify your answer. 1) 2) Set up the initial condition and recurrence relation for the number of multiplications 3) Write the pseudocode for the non-recursive version of this algorithm, i.e., compute...
5. (10 points) The factorial of a nonnegative integer n is written n! and is defined as follows. n 2) ..1 (for values of n greater than 1) nn (n-l) and n-# 1 (for n 0 or n-1) l. Write a program that reads a nonnegative integer and computes and prints its factoria
What is the time-complexity of the algorithm abc? Procedure abc(n: integer) s := 0 i :=1 while i ≤ n s := s+1 i := 2*i return s consider the following algorithm: Procedure foo(n: integer) m := 1 for i := 1 to n for j :=1 to i2m:=m*1 return m c.) Find a formula that describes the number of operations the algorithm foo takes for every input n? d.)Express the running time complexity of foo using big-O/big-
permutations are there with people)? 34. A class has enough time for 4 questions. 10 students are present. Suppose a student can ask up to 4 questions, how many combinations can there be of students asking questions? (How many 4- combinations are there from 10 students, with repetition)? 35. Show that if there are 30 students in a class, then at least two of the students have first names that 3pts begin with the same letter. What principle can you...
The factorial of a nonnegative n written as n! is defined as follows: n!= n*(n-1)*(n-2) * .... *1 (for all values of n greater than 0) and 0! =1. For example 5! = 5*4*3*2*1 which is 120. (can also be 1*2*3*4*5) Write a C++ program that reads a nonnegative integer and computes and prints its factorial.
Write a C++ function to find factorial of an integer number N >0. Using the factorial function print the factorial of two inputs as shown below: Sample input: 1 4 Expected output: 1 24
1. Let m be a nonnegative integer, and n a positive integer. Using the division algorithm we can write m=qn+r, with 0 <r<n-1. As in class define (m,n) = {mc+ny: I,Y E Z} and S(..r) = {nu+ru: UV E Z}. Prove that (m,n) = S(n,r). (Remark: If we add to the definition of ged that gedan, 0) = god(0, n) = n, then this proves that ged(m, n) = ged(n,r). This result leads to a fast algorithm for computing ged(m,...
Algorithm Riddle(A[0..n-1]) //Input: An array A[0..n-1] of real numbers if n=1 return A[0] else temp = Riddle(A[0..n-2]) if temp<=A[n-1] return temp else return A[n-1] what does it compute? explain please
urgent
L. Consider the following pseudocode for finding binomial coefficients: Binom(n, r) Input: integers n and r Output: n choose r if r-0 or r-n thern return 1 end else return Binom(n-1, r-1) Binom(n-1, r); end running time of this algorithm. Prove your bound for the upper bound. (5 points) Rewrite the above algorithm so that it is efficient. (You have 2 choices!) Analyze the worst case time of your new algorithm. (5 points) Find the edit distance between "SPOKE...