Question: Problem 3. ( 20 pints) Run-time Determination Consider the following algorithms (written in pseudocode): 1 Alg1 (A,n) begin{tabular}{l|l} 2 & Input: Array A of integers
Problem 3. ( 20 pints) Run-time Determination Consider the following algorithms (written in pseudocode): 1 Alg1 (A,n) \begin{tabular}{l|l} 2 & Input: Array A of integers of length n \\ 3 & sum =0 \\ 4 \\ 5 & for i=1 to n do \\ 6 \\ 7 & j=i \\ 8 & while jn and (A[j]modi)>0 do \\ tmp=A[j]modi \\ sum im+sum+tmp \\ j=j+1 \end{tabular} Formally analyze the worst-case running time of Alg1 and Alg2, and give a tight big O upper bound on the worst-case running time of each algorithm. You must show your work - clearly and rigorously derive a tight upper bound f(n) on the worst-case running time, and obtain a tight big O upper bound for f(n) by following the definition of the big O notation. Let a positive constant d be an upper bound on the cost of executing any line once in each of Alg1 and Alg2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
