Assessment Review | Full Questions, Correct
Answers, and Worked Solutions | Latest
2026/2027 Update | 100% Correct.
Question:
Pre-Assessment: Algorithms - Algorithm Structures: i,- i,- i,- i,-
Question 1: i,-
Consider the following pseudocode that merges two lists of numbers into
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
one:
Merge0(List1, List2) i,- i,-
i,- Set OUTlist to empty
i,- i,- i,- i,-
i,- While List1 is not empty OR List2 is not empty
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i,- If one list is empty and the other is not,
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i,- Remove the first number from the non-empty list and add it to OUTlist
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i,- If both lists are non-empty,
i,- i,- i,- i,- i,-
i,- Remove the first number from List1 and add it to OUTlist
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i,- Remove the first number from List2 and add it to OUTlist
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i,- Return OUTlist i,-
If ListA is [1, 3, 5] and ListB is [2, 4, 6] then what is the result of Merge0
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
(ListA, Merge0 (ListB, ListA))??
i,- i,- i,-
,Answer:
[ 1, 2, 3, 1, 5, 4, 3, 6, 5 ]
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
Step 1: i,-
To solve this, we need to understand how the Merge0 function works. It
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
merges two lists by taking the first element of each list and adding it to
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
the output list in ascending order. If one list is empty and the other is not,
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
it removes the first element from the non-empty list and adds it to the
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
output list. i,-
Using the given example, we have:
i,- i,- i,- i,- i,-
i,- ListA = [1, 3, 5] i,- i,- i,- i,-
i,- ListB = [2, 4, 6] i,- i,- i,- i,-
Now, let's analyze the innermost function Merge0(ListB, ListA):
i,- i,- i,- i,- i,- i,- i,-
1. OUTlist = empty
i,- i,- i,-
2. OUTlist = [2]
i,- i,- i,-
3. OUTlist = [2, 1]
i,- i,- i,- i,-
4. OUTlist = [2, 1, 4]
i,- i,- i,- i,- i,-
5. OUTlist = [2, 1, 4, 3]
i,- i,- i,- i,- i,- i,-
6. OUTlist = [2, 1, 4, 3, 6]
i,- i,- i,- i,- i,- i,- i,-
7. OUTlist = [2, 1, 4, 3, 6, 5]
i,- i,- i,- i,- i,- i,- i,- i,-
8. ListA is now empty, so we return OUTlist = [2, 1, 4, 3, 6, 5]
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
Step 2: i,-
Now, let's use the result of Merge0(ListB, ListA) as the second argument
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
for the outer Merge0 function. So we have:
i,- i,- i,- i,- i,- i,- i,-
i,- List1 = ListA = [1, 3, 5]
i,- i,- i,- i,- i,- i,-
,i,- List2 = Merge0(ListB, ListA) = [2, 1, 4, 3, 6, 5]
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
Using the Merge0 function with these lists, we have:
i,- i,- i,- i,- i,- i,- i,- i,-
1. OUTlist = empty
i,- i,- i,-
2. OUTlist = [1]
i,- i,- i,-
3. OUTlist = [1, 2]
i,- i,- i,- i,-
4. OUTlist = [1, 2, 3]
i,- i,- i,- i,- i,-
5. OUTlist = [1, 2, 3, 1]
i,- i,- i,- i,- i,- i,-
6. OUTlist = [1, 2, 3, 1, 5]
i,- i,- i,- i,- i,- i,- i,-
7. OUTlist = [1, 2, 3, 1, 5, 4]
i,- i,- i,- i,- i,- i,- i,- i,-
8. OUTlist = [1, 2, 3, 1, 5, 4, 3]
i,- i,- i,- i,- i,- i,- i,- i,- i,-
9. OUTlist = [1, 2, 3, 1, 5, 4, 3, 6]
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
10. OUTlist = [1, 2, 3, 1, 5, 4, 3, 6, 5]
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
11. return OUTlist = [1, 2, 3, 1, 5, 4, 3, 6, 5]
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
Therefore, the result of Merge0(ListA, Merge0(ListB, ListA)) is [1, 2, 3, 1, 5,
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
4, 3, 6, 5].
i,- i,- i,-
Question:
Pre-Assessment: Algorithms - Algorithm Structures: i,- i,- i,- i,-
Question 2: i,-
Given this pseudocode: i,- i,-
S = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
, x=2 i,- i,-
While(x<11): i,-
i,- For i in S: i,- i,- i,- i,-
i,- If 0 ≡ i mod x and i ≠ x:
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i,- delete i from S i,- i,- i,- i,-
i,- end-If i,-
i,- end-For i,-
i,- x=x+1 i,- i,- i,- i,-
end-While
What is S at the end of this code??
i,- i,- i,- i,- i,- i,- i,- i,-
Answer:
{2, 3, 5, 7, 11, 13, 17, 19}
i,- i,- i,- i,- i,- i,- i,-
This code is nothing but finding the prime numbers from the given set.
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
Start from x = 2 i,- i,- i,- i,-
1) When x = 2, we have to delete that elements from S which satisfy 0 ==
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i mod 2 and i ≠ 2 i.e multiples of 2 except 2. So we remove {4, 6, 8, 10, 12,
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
14, 16, 18, 20} i,- i,- i,-
x = x+1
i,- i,-
2) When x = 3, we have to delete that elements from S which satisfy 0 ==
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
i mod 3 and i ≠ 3 i.e multiples of 3 except 3. So we remove {6, 9, 12, 15,
i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,- i,-
18}
x = x+1
i,- i,-