Determine whether each of the following algorithms is fully correct, and prove that your answer is correct.
solution:
a. Algorithm is not fully correct.
Algorithm should return the value of log2
But when the x is not in the form of 2n (for some n initially), the log2 will return a real number. But variable p can have the value that is of type integer only, as for each iteration in the while loop, the value of p is just incremented by 1.
For example if the x value is 3, then the value of p will be 2 according to the algorithm. But the actual value of log23=1.5849.
b. Algorithm is fully correct.
In the while loop, in each iteration the value x that is obtained in the previous iteration is divided by 2. If the value is in the form of 2^n then only x will become 1 at the end. Thus returning true. Otherwise at the end it will be some rational value less than 1. Hence it will return false.
please give me like
Determine whether each of the following algorithms is fully correct, and prove that your answer is...
Implement these in Python 3 preferably.
Task: Implement the following algorithms to solve the Stock Span Problem using the ADT for a Stack in ython. The implementation of the ADT of a Stack (10 points) Implementation of computeSpans1 (20 points) Implementation of computeSpan2 (30 points) Provide the derived computational complexity of both computeSpans1 and computeSpans2 (40 points) Algorithm computeSpans1 (P) Input: an n-element list P of numbers such that P[i] is the prices of the stock on day I Output:...
Specify the running time of each of the following algorithms.
You must fully explain your answer for each of the question!
Algorithm Ex1(ai,.., an), a): for i ← 1 to n do If ai 〉 a raj return x Algorithm Ex2((ai ,..., an), (b,..., bm)): for i ← 1 to min(n, m) do ifai 〈bi return x
Determine whether the following statement is true or false. Sample evidence can prove that a null hypothesis is true. Choose the correct answer below. True O False
Question 2. (24 points. Recall that in Assignment 1, we developed recursive algorithms for implementing the specification Given a non-decreasing array Aſ1..n], and given a value v, return a number r such that • ifr=0 then v does not occur in A[1..n] • ifr #0 then 1 <r<n and A[r] = v. In this question, we shall implement this specification by an iterative algorithm, build around a while loop of the form (with AA, BB, CC and CC2 to be...
Question 11 (3 points) What does the following recursive method determine? public boolean question 16(int[]a, int[] b. intj) { if (j == 2.length) return false; else if ( == b.length) return true; else return question 16(2, b.j+1): 3 returns true if b contains less elements than a, false otherwise returns true if b contains more elements than a, false otherwise returns true if a and bare equal in size, false otherwise returns true if a's element value is larger than...
Problem 1 true in the following cases, and false otherwise: Determine whether each of the following is true or false: 10 Grades) that the universe for x and y is (1, 2, 3). Also, assume that Ptx, y) is a predicate that is (a) Vy3x (x ty A P(x, y)). (d) Vy (x 3 -> P(x, y)). (e) 3x 3y (yxP(x, y))
3a. Runtime Analysis: For each of the following recursive algorithms, state the recurrence equation that is the runtime of the algorithm. Briefly describe how you determined each term. You do not need to provide the runtime bound – just the equation. T(n) = Product(array, p) // n is size of array if (p>n) return 1 if (array[p] != 0) return array[p] * Product(array, p+1) else return Product(array, p+1) Describe terms: T(n) = Describe terms: // modified merge sort mod Merge(...
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...
1. (15 points) Prove whether the following sets are linearly dependent or independent, and determine whether they form a basis of the vector space to which they belong. s 10110 -1 ) / -1 2) / 2 1 17 ) } in M2x2(R). "11-21 )'(1 1)'( 10 )'(2 –2 )S (b) {23 – X, 2x2 +4, -2x3 + 3x2 + 2x +6} in P3(R) (the set of polynomials of degree less than 3. (c) {æ4—23+5x2–8x+6, – x4+x2–5x2 +5x-3, x4+3x2 –...
1. Determine whether the following set is linearly independent or not. Prove your clas a. [1+1, 2+2-2,1 +32"} b. {2+1, 3x +3',-6 +2"} 8. Let T be a linear transformation from a vector space V to W over R. . Let .. . be linearly independent vectors of V. Prove that if T is one to one, prove that (un)....(...) are linearly independent. (m) is ) be a spanning set of V. Prove that it is onto, then Tu... h...