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
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
It basically returns the minimum element in the array A[0...n-1]
Kindly revert for any queries
Thanks.
Algorithm Riddle(A[0..n-1]) //Input: An array A[0..n-1] of real numbers if n=1 return A[0] else temp =...
Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer numbers for i leftarrow 0 to n - 2 do for j leftarrow i +1 to n - 1 do if A[i] = = A[j] return false return true a) What does this algorithm do? b) Compute the running time of this algorithm.
ALGORITHM X(A[0..n - 1]) // Input: A contains n real numbers for it 0 to n - 2 do for jt i +1 to n - 1 do if Aj] > A[i] swap A[i] and A[j] 1. What does this algorithm compute? 2. What is the basic operation? 3. How many times is the basic operation executed? 4. What is the efficiency class of this algorithm?
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...
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!
2) Given an array of n nonzero real numbers a[0]…a[n-1], write a function to partition the array (not sort) so that all its negative elements come before all its positive elements. Your algorithm should have O(n) time complexity. The function prototype is void negpospartition(float a[], int n) Please use C language
Algorithm ComparisonCountingSorting(A[0..n-1], S[0..n-1] ) //Input: Array A[0..n-1] of orderable values //Output: Array S[0..n-1] of A's values in ascending order for i ← 0 to n – 1 do Count[i] ← 0 for i ← 0 to n – 2 do for j ← i + 1 to n – 1 do if A[i] < A[j] Count[j] ← Count[j] + 1 // increment counter of larger else Count[i] ← Count[i] + 1 for i ← 0 to n –...
Pseudocode Algorithm Sub(n) if n = 1 or n = 2 return n - 1 else return Sub(n - 1) + Sub(n - 1) Let Sub(n) be the number of "substraction operation" as the basic operation on input of size n. what is the recurrence for Sub(n). please show working.
Design an algorithm to rearrange elements of a given array of n real numbers so that all its negative elements precede all its positive elements. Your algorithm should be both time efficient and space efficient. (run the code in a programming language and present the running result)
How to prove G(n)=n+1 in this algorithm?
1. if (n 0) 2. return 1 3. else if (n1) f 4. return 2 5. else if (n 2) 6. return 3 7. else if (n3) t 8. return 4 else f 9. int OGnew int[n 11 10. G[O]1 12. G[2]3 13. G[3]4 14. int i:-4 15. while (i<n) t 16. if (i mod 20) else ( 20. return G[n]
1. if (n 0) 2. return 1 3. else if (n1) f...
Subject: Algorithm
need this urgent please thank you.
4. Give pseudocode for an algorithm that will solve the following problem. Given an array A[1..n) that contains every number between 1 and n +1 in order, except that one of the numbers is missing. Find the miss sorted ing mber. Your algorithm should run in time (log n). (Hint: Modify Binary search). A pseudocode means an algorithm with if statements and loops, etc. Don't just write a paragraph. Also, if your...