1) the algorithm compute the sorting of array in descending order .
2) the operation of this algorithm is swapping if no, are not arranged in descending order
3) in worst case the no. of operation is performed is
n + (n-1) + (n-2) + ….. + (n-(n-1))
so it is;-n×(n+1)/2=O(n^2)
4) it totally depend upon the element of array
but is o(n^2)
ALGORITHM X(A[0..n - 1]) // Input: A contains n real numbers for it 0 to n...
Solve ques no. 2 a, b, c, d . Algorithm 1 Sort a list al,..., an for i=1 to n-1 do for j=1 to n-i do if aj > aj+1 then interchange a; and a;+1 end if end for end for (b) Algorithm 1 describes a sorting algorithm called bubble sort for a list al,...,an of at least two numbers. Prove that the algorithm is complete, correct and terminates. (2) Complexity of Algorithms (Learning Target C2) (a) What is the...
f(x) = 2.10 Consider the following algorithm (known as Horner's rule) to evaluate -ax': poly = 0; for( i=n; i>=0; i--) poly = x * poly + ai a. Show how the steps are performed by this algorithm for x = 3, f(x) = 4x + 8x + x + 2. b. Explain why this algorithm works. c. What is the running time of this algorithm?
Problem 44) Prove: n!> 2" for n24. Problem 45) Prove by induction: For n>0·AT- i=1
Prove this using the definition R7: log(n*) is O(log n) for any fixed x > 0
Suppose an > 0 for n = 1,2,3,... Let An = %=1 a; for n = 1,2,3,..., Suppose &j=1 a; diverges. Show that: no aj diverges. {j=11taj wat AN an+j > 1-1 i=1 AN+) AN+k a Show that &j=1 N for k = 1,2,3,..., Hence show that I diverges. Show th: .-1 for n = 1,2,3,..., Hence show that Lj=, converges. C. An
Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do if A[i]A[i+1] > A[i+2) then return i it i+1 return -1 4. Calculate how many times the comparison A[i]A[i+1] > A[i+2] is done for a worst-case input of size n. Show your work. 5. Calculate how many times the comparison A[i]A[i+1] > A[i+2] is done for a best-case input of size n. Show your work.
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...
check if e-1/4/ f(x) if x > 0 if x < 0 is differentiable at 0.
Prepare a flowchart and MATLAB program that will calculate Q2: Fibonacci series is f1=1 f2=1 fn=fn-1+fn-2 (n>2) What is f20?
Construct NFA that accept L1 L2 , where Li = {a”bam+1, n > 0, m>0}; } = {a,b} L2 = {ab”, n >0}; £ = {a,b}