Answer:
The algorithm is as follows:
1. Start
2. Input List
3. Input Sum
4. For i = 0 to length of list - 1
4.1 num1 = List[i]
5. For j = i to length of list - 1
5.1 num2 = List[j]
6. If SUM = num1 + num2
6.1 Print(num1, num2)
6.2 Break
The algorithm is implemented in python as follows:
def checklist(mylist,SUM):
for i in range(0, len(mylist)):
num1 = mylist[i]
for j in range(i+1, len(mylist)):
num2 = mylist[j]
if num1 + num2== SUM:
print(num1,num2)
break;
Explanation:
I'll explain the Python code
def checklist(mylist,SUM):
This line iterates from 0 to the length of the the last element of the list
for i in range(0, len(mylist)):
This line initializes num1 to current element of the list
num1 = mylist[i]
This line iterates from current element of the list to the last element of the list
for j in range(i+1, len(mylist)):
This line initializes num1 to next element of the list
num2 = mylist[j]
This line checks for pairs equivalent to SUM
if num1 + num2== SUM:
The pair is printed here
print(num1,num2)
break;