(GFO1) (PGFO)
Attempt #1
Status: Passed
1. Consider the following pseudocode that merges two lists of numbers into one:
Merge0(List1, List2)
Set OUTlist to empty
While List1 is not empty OR List2 is not empty
If one list is empty and the other is not,
Remove the first number from the non-empty list and add it to OUTlist
If both lists are non-empty,
Remove the first number from List1 and add it to OUTlist
Remove the first number from List2 and add it to OUTlist
Return OUTlist
If ListA is [1, 3, 5] and ListB is [2, 4, 6] then what is the result of Merge0 (ListA, Merge0 (ListB, ListA))?
YOUR CORRECT
ANSWER ANSWER
[ 1, 2, 3, 4, 5, 6 ]
[ 1, 1, 3, 2, 5, 3, 4, 5, 6 ]
[ 2, 1, 4, 3, 6, 5 ]
[ 1, 2, 3, 1, 5, 4, 3, 6, 5 ]
,2. Given this pseudocode:
S = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
x=2
While(x<11):
For i in S:
If 0 ≡ i mod x and i ≠ x:
delete i from S
end-If
end-For
x=x+1
end-While
What is S at the end of this code?
YOUR CORRECT
ANSWER ANSWER
∅
{2, 3, 5, 7}
{11, 13, 17, 19}
{2, 3, 5, 7, 11, 13, 17, 19}
3. Given the pseudocode fragment:
x := 2
count := 4
while (count > 0)
x := 2 × x
count := count - 1
End-while
What is the final value for x?
YOUR CORRECT
ANSWER ANSWER
4
16
32
64
, 4. Given this pseudocode that extracts a sample sequence from the data sequence of length N:
Function Sampler (Sequence Data)
Set Sample to an empty sequence
Set N to the length of Data
While N>=1
Append element N of Data to Sample
N:= N/2
Return Sample
What is the worst-case run time for Function Sampler?
YOUR CORRECT
ANSWER ANSWER
O(log2N)
O(N/2)
O(N)
O(Nlog2N)