3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <=...
3) [16 points totall Consider the following algorithm: int SillyCalc (int n) { int i; int Num, answer; if (n < 4) 10; return n+ else f SillyCalc(Ln/4) answer Num Num 10 for (i-2; i<=n-1; i++) Num + = answer + answer; answer return answer } Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2*...
3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...
4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...
pleas answer asap 3. (20 points) Algorithm Analysis and Recurrence There is a mystery function called Mystery(n) and the pseudocode of the algorithm own as below. Assume that n 3* for some positive integer k21. Mystery (n) if n<4 3 for i1 to 9 5 for i-1 to n 2 return 1 Mystery (n/3) Print "hello" 6 (1) (5 points) Please analyze the worst-case asymptotic execution time of this algorithm. Express the execution time as a function of the input...
7. Consider the following proposed sorting algorithm supersort (int n, int start, int end, keytype SI1)1 if(n > 1) { if (SIstart] > S[end]) swap SIstart] with Stend]; supersort(n-l, start, end-1, s) supersort (n-1, start+, end, S) a) 3 pts) Give a recurrence relation (with initial condition) that describes the complexity of this sort algorithm b) (4 pts) Solve the recurrence froma) c) (3 pts) Is supersort guaranteed to correctly sort the list of items? Justify your answer. (A formal...
Consider the following recursive algorithm for computing the sum of the first n cubes: S(n) = 13 + 23 + … + n3. (a) Set up a recurrence relation for the number of multiplications made by this algorithm. (b) Provide an initial condition for the recurrence relation you develop at the question (a). (c) Solve the recurrence relation of the question (a) and present the time complexity as described at the question number 1. Algorithm S n) Input: A positive...
4. [16 marks total (6 marks each)] Do a worst-case analysis for the following algorithm segments, counting the number of multiplications which occur. I have marked the lines with the multiplications you are to count with ). For all of these algorithms, use n as your fixed input size (even though n doesn't really represent the "size" of the input). Be sure to include an explanation with your answers to obtain full marks. (a) t-10; for (i-1;in-H) t-5*t; (b) (For...
3. 0 marks Suppose you have an algorithm which has the following recurrence relation for W(n), assuming n is a power of 2, i.e. assuming n-2, k20: for n for n- W()-2W(n/2)+2n+ 2 W(n)- Using back substitution and assuming n is a power of 2, ie. n-2, find an exact (ie non-recursive) formula for Win). Be sure to show your work and to simplify your final answer as much as possible. Note that you do NOT need to verify your...
Consider the following algorithms int add.them (int n, int AI) index iふk; j=0; for (i = 1; n; i++) jsjtA[i]; for (i = 1; n; i++) return j+ int anysqual (int n, int A) index i,j,k.m; for ( iSn i++) for G-1:jSnj++) for (k = 1; k n: k++) for (m t= 1; m n: m++) return 1 return 0 Note: The array parameter A[ I[1 in any equal is an n x n two-dimensional array. For example when n...
Q4) [5 points] Consider the following two algorithms: ALGORITHM 1 Bin Rec(n) //Input: A positive decimal integer n llOutput: The number of binary digits in "'s binary representation if n1 return 1 else return BinRec(ln/2)) +1 ALGORITHM 2 Binary(n) tive decimal integer nt io 's binary representation //Output: The number of binary digits in i's binary representation count ←1 while n >1 do count ← count + 1 return count a. Analyze the two algorithms and find the efficiency for...