Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Whenever you are designing an algorithm you must address the three questions we

ID: 3881199 • Letter: W

Question

Whenever you are designing an algorithm you must address the three questions we are typically posing (correctness, complexity and improvement potential). The faster your algorithm, the better your mark. Assignment 1 Question 1: Consider the following algorithm // L is a list and n is its length// // For the purpose of this assignment we assume that n= 4**k, for k21// Alg1 (L,n) remove the smallest and largest element from L fn-2> (4"k)/2 call Alg1 (L, n-2) a) What is the algorithm intended to do? b) Is it correct? If it is not correct discover the error(s) when trying to prove c) d) correctness and fix it (them). Then, reprove the correctness. What is its time complexity? Can it be improved? You may use any algorithm discussed in class.

Explanation / Answer

a) algorithm Will call recursively itself up to n-2 is greater than (4**k)/2

b) no, it is not correct, because k value is not defined..

To fix it let k=L

c) Time complexity in worst case is O(n)

d) no, because it is linear decreament

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote