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

(a) Design and implement in pseudocode an algorithm that gets as input a list of

ID: 3797386 • Letter: #

Question

(a) Design and implement in pseudocode an algorithm that gets as input a list of k integers N1, . . . , Nk as well as a special value SUM. Your algorithm must locate a pair of values in the list that sum to the value SUM. For example, if your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm should output “either” the two values 2 and 18, “or” the two values 3 and 17. If your algorithm cannot find any pair of values that sum to the value SUM, then it should print out the message “sorry, there is no such pair of values”.

(b) What is the time complexity of your algorithm in O notation?

-Please use simple psudocode

Explanation / Answer

a) Pseudo code:

START

DECLARE arr as list
DECLARE SUM,k as int

DISPLAY "Enter how many number of elements in the list:"
READ k
DISPLAY "Enter elements of list:"
FOR i=0 to k
READ arr[i]
END FOR
DISPLAY "Enter SUM value:"
READ SUM

FOR i=0 to k-1:
FOR j=i+1;j<=k;j++)
   IF arr[i]+arr[j]==SUM
       Display arr[i],arr[j]
       Break
   END IF
END FOR
END FOR

STOP

b)

Time complexity is: O(n2)