Question 1: Complexity
Take a look at the following algorithm written in pseudocode:
procedure mystery(a1, a2, …, an: integer)
i := 1
while (i < n and ai ≤ ai+1)
i := i + 1
if i == n then print “Yes!”
else print “No!”
What property of the input sequence {an} does this algorithm test?
What is the computational complexity of this algorithm, i.e., the number of comparisons being computed as a function of the input size n?
Provide a reasonable upper bound for the growth of the complexity function by using the big-O notation (no proof necessary).
Question 2: The Boston Powerflower
Botanists at UMass Boston recently discovered a new local flower species that they named the Boston powerflower. It has a beautiful, blue blossoms, and each plant lives for only one summer. During that time, each plant produces ten seeds. Two of these seeds will turn into plants in the following year, and the remaining eight seeds will turn into flowers the year after. As the name powerflower suggests, these seeds always turn into flower plants; there is no failure ever.
During the year of this discovery (let us call it year one), the scientists found two powerflowers on the UMass campus, and in the following year, there were already four of them.
Devise a recurrence relation for the number of flower plants fn in year n, and specify the initial conditions.
Use the above recurrence relation to predict the number of plants on the UMass campus in years 3, 4, 5, and 6.
Find an explicit formula for computing the number of plants in any given year without requiring iteration, i.e., repeated application of a formula. You should (but do not have to) check the correctness of your formulas using some of the results you obtained in (b). Remember that our initial conditions are for a1 and a2.
Question 3: Induction
a. Use mathematical induction to show that the following equation is true for all natural numbers n:
20 + 21 + 22 + … + 2n = 2n+1 – 1
b. Show by induction that every power of 6 ends in 6.
Question 4: Prime Factor Examples
Write down the prime factorization (in ascending order)
of each of the following integers
(Example: 720 = 24⋅32⋅5).
16777216
103
255
10000
Question 5: Euclidean Algorithm
Use the Euclidean algorithm to determine the following greatest common divisors. Write down every step in your calculation.
Gcd(12211, 10422)
gcd(1755, 855)
gcd(62525, 625)
Answer 1)
It tests the property that whether the elements of the input sequence are in non-decreasing order.
Number of computations: In worst case there might be n comparisons of i < n and n comparisons of ai < ai+1 . Also, theres a single comparison i == n. So, there are a total of (2n + 1) comparisons.
Complexity : O(n) [Since, O(2n+1) = O(n)]
Answer 2)
Devise a recurrence relation for the number of flower plants fn in year n, and specify the initial conditions.
Recurrence relation: fn= 2fn-1+8fn-2
Initial conditions: f1= 2, f2= 4
Use the above recurrence relation to predict the number of plants on the UMass campus in years 3, 4, 5, and 6.
f3= 2f2+8f1= 8 + 16 = 24
f4= 2f3+8f2= 48 + 32 = 80
f5= 2f4+8f3= 160 + 192 = 352
f6= 2f5+8f4= 704 + 640 = 1344
Find an explicit formula for computing the number of plants in any given year without requiring iteration, i.e., repeated application of a formula. You should (but do not have to) check the correctness of your formulas using some of the results you obtained in (b). Remember that our initial conditions are for a1 and a2.
Answer 3)
Let P(n) be 20+21+22+.....+2n = 2n+1 - 1
We will show P(n) is true for all n ∈ ℕ.
For our base case, we need to show P(0) is true, meaning the sum of the first zero powers of two is 20 – 1. Since the sum of the first zero powers of two is 0 = 20 – 1, we see P(0) is true.
For the inductive step, assume that for some k ∈ ℕ that P(k) holds, meaning that 20+21+22+.....+2k = 2k+1 - 1. We need to show that P(k + 1) holds, meaning that the sum of the first k + 2 powers of two is 2k+2 – 1.
Consider the sum of the first k + 2 powers of two. This is the sum of the first k+1 powers of two, plus 2k+1 . Using the inductive hypothesis, we see that
20+21+22+.....+2k+1 = (20+21+22+.....+2k) + 2k+1 = 2k+1 – 1 + 2k+1 = 2(2k+1) – 1 = 2k+2 – 1
Thus P(n + 1) is true, completing the induction.
Answer 4)
16777216 = 224
103 = 103
255 = 3*5*17
10000 = 24*54
Question 1: Complexity Take a look at the following algorithm written in pseudocode: procedure mystery(a1, a2,...
Given the following algorithm: Algorithnm Input: a1, a2,...,an, a sequence of numbers n, the length of the sequence x, a number Output: ?? i:- 1 While (x2 # a, and i < n) i+1 End-while If (x- - a) Return(i) Return(-1) 3, -1, 2,9, 36,-7, 6,4 a) What is the correct output of the Algorithm with the following input: a1, a2,..an b) What is the asymptotic worst-case time complexity of the Algorithm? Algorithnm Input: a1, a2,...,an, a sequence of numbers...
You are given a set of integer numbers A = {a1, a2, ..., an}, where 1 ≤ ai ≤ m for all 1 ≤ i ≤ n and for a given positive integer m. Give an algorithm which determines whether you can represent a given positive integer k ≤ nm as a sum of some numbers from A, if each number from A can be used at most once. Your algorithm must have O(nk) time complexity.
) Consider the following algorithm procedure polynomial (c, a0,a1, …, an) power :=1 y≔a0 for i=1 to n power≔power*c y≔y+ai*power return y Find a big-O estimate for the number of additions and multiplications used by this algorithm.
Discrete math question 2. Consider to the following two algorithms procedure SortA(a1,a2, ..., an: a list of real numbers with n 2 2) 1, for j := 2 to n 2. i:= 1 3. while aj > ai 4. 5. m: 6. or k 0toj -i-1 7. i:-i+1 aj-k:aj-k-1 ai := m
Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a and b are integers while (a>0) B- a/2 A a-2 end while return b; i. What is the time complexity of the IterativeFunction pseudocode shown above? ii. What is the space complexity of the IterativeFunction pseudocode shown above? 2. What is the time complexity of the following algorithm (Note that n(n+1) 2,2 n(n+1)(2n+1) 2 and ): Provide both T(n) and order, e(f(n)). int A=0;...
Question 1 result in a grade of zero for the assignment and will bo subject to disciplinary action. Part I: Strong Induction (50 pt.) (40 pt., 20/10 pt. each) Prove each of the following statements using strong induction. For each statement, answer the following questions. a. (4/2 pt.) Complete the basis step of the proof by showing that the base cases are true. b. (4/2 pt.) What is the inductive hypothesis? C. (4/2 pt.) what do you need to show...
Can someone answer number 4 for me? (60 pt., 12 pt. each) Prove each of the following statements using induction. For each statement, answer the following questions. a. (2 pt.) Complete the basis step of the proof b. (2 pt.) What is the inductive hypothesis? c. (2 pt.) What do you need to show in the inductive step of the proof? d. (6 pt.) Complete the inductive step of the proof. 1. Prove that Σ(-1). 2"+1-2-1) for any nonnegative integer...
Part A Analyze the following recurrences and show their time complexity functions using (I) iteration method and (2) Master Theorem. AI. T(n) = 2T 3 A2. T(n) = 3T 2n АЗ. Т(п) — Т(п — 2) + 3 А4. Т(п) — 2Т (п — 1) + 1 A5. T(n)= 4T +n log n A6. T(n) = 3T +n log n n2 A7. T(n) = 27 Part B Do 2.3-4 (р39) and Problem 2-1 (р39) Part C Implement MERGE-SORT() algorithm that...
[Recursive Cost] [ALGORITHM] Improving Efficiency PLEASE explain in DETAIL the following question in detail. The algorithm is also given below. Thank You! 1.a) Define recursively the worst case cost Kn of the Knapsack function for n items. Remember that you need to provide both the base case and the recurrence relation. Also do not forget to include the cost of the function Worth in your cost. Justify your answer (i.e. explain what each component of the formula represents). [5points] 1.b) Use...