0% found this document useful (0 votes)
131 views31 pages

CS1033 2021intake FinalExam

The document is an examination paper for a Programming Fundamentals course. It provides instructions to candidates regarding the structure of the closed-book exam, which consists of 90 multiple choice questions worth 1 mark each. Candidates are to select only one choice per question and are informed that there is no penalty for wrong answers. The exam accounts for 90% of the course assessment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views31 pages

CS1033 2021intake FinalExam

The document is an examination paper for a Programming Fundamentals course. It provides instructions to candidates regarding the structure of the closed-book exam, which consists of 90 multiple choice questions worth 1 mark each. Candidates are to select only one choice per question and are informed that there is no penalty for wrong answers. The exam accounts for 90% of the course assessment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

UNIVERSITY OF MORATUWA

Faculty of Engineering

Department of Computer Science and Engineering

B.Sc. Engineering

Semester 1 Examination (2021 Intake)

CS 1033 Programming Fundamentals

Time allowed: 3 Hours December 2022

Instructions to candidates

• The Answer Sheet for this exam is on the next page (overleaf). Remove this sheet from
the remainder before starting to answer the questions. Return only the Answer Sheet at
the end of the exam.
• Write your Registration Number clearly on top of the Answer Sheet.
• This is a closed-book examination.
• Calculators are not permitted for this examination.
• This paper consists of 31 pages, including this page.
• This paper consists of 90 multiple-choice questions; each question is worth 1 mark.
o Select only one choice among the given choices. Writing none or more than one
choice or illegibly will result in a zero mark. There is no penalty for wrong
choices.
• This examination accounts for 90% of the course module assessment.
• Python version 3.10 is assumed in this examination (the same as during the semester).
• Note on number representations: In Python, hexadecimal, octal and binary numbers are
specified with the prefix ‘0x’, ‘0o’ and ‘0b’, respectively. For example, 1910 is
represented in hexadecimal, octal and binary as 0x13, 0o23 and 0b10011, respectively.

-----------------------------
CS1033-2021 Intake S1 (Dec 2022)

Consider the flowchart in Fig. 1 to


answer the next four (4) questions. Start

The algorithm takes as input two


Input lists L1, L2
lists L1 and L2. The starting index
of a list is 0. The function len()
returns the length of the argument. N1 ← len(L1)
The “=” symbol checks equality.
N2 ← len(L2)
count ← 0
i←0
1. If L1=[3,7,9,5,1] and
L2=[9,2,7,4,6,8], what will be
the output?
j←0
(a) 5
(b) 2
(c) 6 Yes
(d) 11 Is L1[i] = L2[j]?

(e) 0
No count ← count + 1

2. The running time of this j←j+1


algorithm will be
No
(a) Proportional to N1 Is j = N2?
(b) Proportional to N2
Yes
(c) Proportional to N1+N2
i←i+1
(d) Proportional to N1×N2
(e) Independent of N1, N2 No
Is i = N1?

Yes
Output count

Stop Fig. 1

3. Consider the following statements regarding the algorithm in Fig. 1.

I. The algorithm contains a nested loop.


II. The algorithm will work even if we interchange i and j everywhere they appear.
III. The algorithm will work even if “Is i = N1?” is changed as “Is i > N1?”.

Which of the statements above is/are correct?


(a) I only

Page 3 of 31
CS1033-2021 Intake S1 (Dec 2022)

(b) II only
(c) III only
(d) I and II only
(e) All I, II and III

4. When three students were asked to express in pseudo-code the algorithm in Fig. 1, they
came up with the following.

BEGIN BEGIN BEGIN


INPUT L1, L2 INPUT L1, L2 INPUT L1, L2
N1 ← len(L1) N1 ← len(L1) N1 ← len(L1)
N2 ← len(L2) N2 ← len(L2) N2 ← len(L2)
count ← 0 count ← 0 count ← 0
i ← 0 FOR i=0 TO N1-1 i ← 0
REPEAT FOR j=0 TO N2-1 WHILE i < N1
j ← 0 IF L1[i]=L2[j] j ← 0
REPEAT count ← count + 1 WHILE j < N2
IF L1[i]=L2[j] ENDIF IF L1[i]=L2[j]
count ← count + 1 ENDFOR count ← count + 1
ENDIF ENDFOR ENDIF
UNTIL j = N2 OUTPUT count ENDWHILE
UNTIL i = N1 END ENDWHILE
OUTPUT count OUTPUT count
END END
I II III

Which of these three pseudo-code algorithms correctly express the algorithm in Fig. 1?
(a) I only
(b) II only
(c) III only
(d) I and II only
(e) II and III only

5. Ama writes down a number between 1 and 1,000. Charith must identify that number by
making a few guesses. For each guess, Ama will respond whether the guess is “too high”,
“too low” or “correct”. Charith knows that Ama always tells the truth. If Charith aims to
find the number as quickly as possible, then he will determine the answer at the end of
exactly how many guesses in the worst case?

(a) 1,000
(b) 999
(c) 500
(d) 32
(e) 10

6. Which of the following decimal numbers has and exact representation in binary
representation?

Page 4 of 31
CS1033-2021 Intake S1 (Dec 2022)

(a) 0.5
(b) 0.4
(c) 0.3
(d) 0.2
(e) 0.1

7. While developing a program, a programmer mistakenly inserts code to multiply two


numbers where the requirement was to add them. Which tool can be used to detect this
error automatically?

(a) The compiler or the interpreter


(b) The compiler only
(c) The interpreter only
(d) The editor or IDE
(e) None of the above

8. Consider the following statements about program translation.

I. Compilation and interpretation both cannot be used in a single translation


operation.
II. An interpreted program usually runs faster than a compiled program.
III. For some programming languages only the compilation option will work for
program translation.

Which of the statements above is/are correct?


(a) I only
(b) II only
(c) III only
(d) I and II only
(e) None

9. Suppose there are two algorithms A and B to solve a problem. Algorithm A is much
longer (has more lines of code) than algorithm B. Consider the following statements.

I. Algorithm A will always take more time to execute than algorithm B.


II. A Python program based on algorithm A will generally have more lines of code
than a Python program based on algorithm B.
III. For the same input, the outputs of algorithm A and B can be different.

Which of the statements above is/are correct?


(a) I only
(b) II only
(c) III only

Page 5 of 31
CS1033-2021 Intake S1 (Dec 2022)

(d) I and II only


(e) None

Consider the following algorithm to answer the next two (2) questions.

The algorithm is expected to take as input two positive integers 𝑥 and 𝑛 and output 𝑥 𝑛 , that is
the 𝑛-th power of 𝑥. The algorithm is recursive and it uses the following properties:
(1). If 𝑛 is odd: 𝑥 𝑛 = (𝑥 ∗ 𝑥)𝑛⁄2 ∙ 𝑥 where 𝑛/2 denotes integer (floor) division.
(2). If 𝑛 is even: 𝑥 𝑛 = (𝑥 ∗ 𝑥)𝑛⁄2
Note that “%” and “/” are modulo division and integer division operators, respectively.

Power (x, n)
BEGIN
IF n=0
RETURN 1
ELSEIF (n%2=1)
RETURN Power(x*x, n/2) * x
ELSE
RETURN Power(x*x, n/2)
ENDIF
END

10. How many multiplications are executed as a result of the call Power(3, 8)?

(a) 8
(b) 7
(c) 6
(d) 5
(e) 4

11. Consider the following statements about computing 𝑥 𝑛 and the algorithm given above.

I. An iterative algorithm can be developed based on the same two properties (1) and
(2) corresponding to the cases where 𝑛 is odd and even.
II. The given algorithm will compute 𝑥 𝑛 with fewer number of multiplications than
an algorithm that is based on the property 𝑥 𝑛 = 𝑥 ∙ (𝑥 𝑛−1 ).
III. The given algorithm will not work correctly if 𝑥 = 0.

Which of the above is/are correct?


(a) I only.
(b) II only.
(c) III only.
(d) I and II only.
(e) I, II and III – all are correct.

12. What will be the result when the following Python code is executed?

Page 6 of 31
CS1033-2021 Intake S1 (Dec 2022)

5 ** (False == 2)
(a) 1
(b) 5
(c) 10
(d) 25
(e) An error message

13. What will be the output of the following Python code?


print((9%5)**len([2,3,4])+2)
(a) 1
(b) 3
(c) 66
(d) 1024
(e) An error message

14. Consider the following Python code:

a , b , c = 1050, 2050, 3050


a , b , c = b , a , 2*a+b

Which of the following statements is correct about the result of execution of the code?

(a) At the end: a =1050, b=2050 and c=3050.


(b) At the end: a =2050, b=1050 and c=3050.
(c) At the end: a =2050, b=1050 and c=5150.
(d) At the end: a =2050, b=1050 and c=4150.
(e) The code will result in an error.

15. Consider the following statements about objects in Python.

I. The operations that can be performed on an object depends on its identity.


II. The identity of a mutable object can change.
III. There can be two objects having the same identity.

Which of the above statements is/are correct?


(a) I only.
(b) II only.
(c) I and II only.
(d) III only.
(e) None.

16. Consider the following Python code.

Page 7 of 31
CS1033-2021 Intake S1 (Dec 2022)

x = [1,'football',[2, "cricket", 3, 4], 5]


x[2][1] = 5
x[1] = x[2] * 3

Which of the following is correct about the above 3 lines of code?


(a) Code will be executed without a problem.
(b) The first line has an error; there is no other error.
(c) The second line has an error; there is no other error.
(d) The third line has an error; there is no other error.
(e) The second and third lines have errors; there is no other error.

17. Consider the following Python code.


x = [1,'football',[2, "cricket", 3, 4], 5]
x[1][0] = "p"
x[2][1] += 3
x[2][1] *= 3

Which of the following is correct about the above 4 lines of code?


(a) Code will be executed without a problem.
(b) The second line has an error; there is no other error.
(c) The third line has an error; there is no other error.
(d) The fourth line has an error; there is no other error.
(e) The second and third lines have errors; there is no other error.

18. What will be the value of c after the following Python code is executed?
x = [1,'football',[2, "cricket", 3, 4], 5]
a = 2
b = 'ball'
c = b in x and a in x or b in x[1]

(a) True
(b) False
(c) 'ball'
(d) 'football'
(e) 'ball2football'

19. What will be the value of the following Python expression?

(0b10111010 >> 0o3) ^ (~1 & 0xEE)

(a) 6
(b) 23
(c) 238

Page 8 of 31
CS1033-2021 Intake S1 (Dec 2022)

(d) 249
(e) 255

20. What will be the output of the following Python code, if the input is “9 3 1 6 4”?

ins = input('Enter your input: ')


s = ins.split()
s.sort()
print(s)

(a) 9 3 1 6 4
(b) 1 3 4 6 9
(c) ['9', '3', '1', '6', '4']
(d) ['1', '3', '4', '6', '9']
(e) ['9', '6', '4', '3', '1']

21. Consider the following Python code, with line numbers (not part of the code) shown on the
left. The intention is to read data from a file and process the data.

1 try:
2 fo = open('Data.txt', 'r')
3 s = fo.read() # Read from file
4 _____(P)_____ IOError:
5 print('Error in file access.')
6 else:
7 print('Finished reading the file.')
8 ...... # close the file

What should fill the blank (P) at the beginning of line 4 to make the code work?

(a) if
(b) else
(c) except
(d) finally
(e) match

22. What will be the output of the following Python code, if the input is ‘9’ ?
num = int(input('Enter an integer: '))
match num:
case 1: print("Red")
case 2: print("Blue")
case 3 | 4: print("Green")
case _: print("Black")

(a) Red

Page 9 of 31
CS1033-2021 Intake S1 (Dec 2022)

(b) Blue
(c) Green
(d) Black
(e) An error message or exception

23. What will be the output of the following Python code, if the input is ‘111’ ?

x = int(input('Enter x: '))
if (x > 100):
if (x >= 200):
k = x * 2
elif (x < 300):
k = x * 3
else:
k = x * 4
else:
k = x * 5
print(k)

(a) 222
(b) 333
(c) 444
(d) 555
(e) An error message or exception

24. What will be the output of the following Python code?


count = 10
total = 0
while (count < 12):
total = total + 1
count += 2
else:
total = total + 10
total = total + 10
print (total)
(a) 21
(b) 20
(c) 40
(d) 11
(e) 12

25. What will be the output of the following Python code?


total=0
for i in [1,0,1,0,1,0]:

Page 10 of 31
CS1033-2021 Intake S1 (Dec 2022)

total += 2
break
else:
total += 1
print(total)

(a) 2
(b) 1
(c) 6
(d) 12
(e) 3

26. What will be the output of the following Python code?


total = 0
for counter in range(0,11,2):
total += counter
print(total)
(a) 20
(b) 30
(c) 55
(d) 1
(e) 32

27. What will be the output of the following Python code?


total=0
for i in range(3):
for j in range(3):
if i == j:
pass
total += i+j
print(total)
(a) 36
(b) 12
(c) 9
(d) 54
(e) 18

28. How should we fill the blank (P) in the Code segment to produce the factorial of 5 which
is 120?

Note: Factorial of n is computed by n! = n * (n-1) * (n-2) * …* 2 * 1

Page 11 of 31
CS1033-2021 Intake S1 (Dec 2022)

fact=1
for num in range(5):
_____(P)_____
print("factorial of 5 is = ",fact)

(a) fact *= num


(b) fact *= num-1
(c) fact *= num+1
(d) fact = num*(num-1)
(e) fact = num*(num+1)

29. What will be the output of the following Python code?


i = 3
while (i < 10) :
j = 0
while j < i:
if i != 5:
j += 1
continue
print(9-j, end="")
j += 1
i += 1

(a) 9857
(b) 01234
(c) 12345
(d) 1357
(e) 98765

30. What will be the output of the following Python code?


myL = ['u', 'n', 'i', 'v', 'e','r','s','i','t','y']
myL[-6] = 6
print (myL[4])

(a) 6
(b) e
(c) 4
(d) univ
(e) r

31. What will be the output of the following Python code?


p = "Prog Fundamentals"
print (p[5:-9])

Page 12 of 31
CS1033-2021 Intake S1 (Dec 2022)

(a) p[5:-9]
(b) Prog
(c) mental
(d) Fun
(e) Ema

32. What will be the output of the following Python code?


c1 = complex(4)
c2 = complex(-2,-3)
print(c1-c2)

(a) (4-2,-3j)
(b) (6,3j)
(c) (6+3j)
(d) (2-3j)
(e) (2+7j)

33. What will be the output of the following Python code?


a = 12
b = a
a += 0
print(id(a)==id(b))
(a) True
(b) False
(c) 12
(d) 0
(e) ValueError

34. What will be the output of the following Python code?


print ("%x%x%x%x%x%x" % (13,14,12,0,13,14))
(a) decde
(b) dec0de
(c) facade
(d) abc0ba
(e) decode

35. What will be printed as the output of the following Python code?
print("%6.2f"%(123456))

Page 13 of 31
CS1033-2021 Intake S1 (Dec 2022)

(a) 0123456.0
(b) 3456.00
(c) 123456
(d) 123456.00
(e) %6.2f 123456

36. What will be the output of the following Python code?


a=3
for i in range(a):
print('*'*a)

(a) ***
***
***
(b) *
**
***
(c) *********
(d) ***
(e) *** *** ***

37. What will be the output of the following Python code?


a = [[[0, 1, 2],[3, 4, 5]],[[6, 7, 8], [9, 10, 11]]]
print (a[1][1][1])

(a) 01
(b) 10
(c) 11
(d) 0
(e) 111

38. What will be the output of the following Python code?

def printMe(a="", b = "Computer", c = "Science"):


print(a, b, c, sep="_", end="!!!")
return

printMe(b = "Data")

(a) _Data_Science!!!

Page 14 of 31
CS1033-2021 Intake S1 (Dec 2022)

(b) Data_Science!!!
(c) _Data_Science
(d) !!!Data!!!Science_
(e) None of the above

39. How should we fill the blank (P) in the given code segment to produce a Christmas tree
for a given positive integer? For example for an input of 4 the following should be
printed.
*
* | *
** | **
*** | ***
**** | ****

h = int(input())
for a in range(h+1):
stars='*'*a
_____(P)_____
print(spaces,end='')
print(stars,end='')
if (a>0):
print(' | ',end='')
else:
print(' * ',end='')
print(stars,end='')
print(spaces)
(a) pass
(b) spaces *= h-a
(c) spaces = ' '*(h-a)
(d) spaces = ' '*h
(e) spaces = a

40. What will be the output of the following Python code?

def changeMe(value):
value += 10

p = 190
changeMe(value=p)
print(p)

(a) 10
(b) 190
(c) 200
(d) 190+10
(e) None of the above

Page 15 of 31
CS1033-2021 Intake S1 (Dec 2022)

41. What will be the output of the following Python code?

def printMe(name):
NAME_STR = "name"
print(f"My {NAME_STR} is {name}!")
return

printMe("Alice")

(a) My Alice is name!


(b) My name is Alice!
(c) My {name} is {Alice}!
(d) My {Alice} is {name}!
(e) None of the above

42. Which of the following statements is true about function definitions in Python?
(a) Function body can be empty (no statements).
(b) Convention is to use single quotation marks for denoting docstrings
(documentation of the function).
(c) Without a return statement, it is not possible to access the outcome of executing a
function from the main program.
(d) Return expressions are optional.
(e) Function begins with the keyword “func”.

43. What will be the output of the following Python code?

def changeMe( myListInFunc ):


myListInFunc.append([1,2,3,4])
return

mylist= ['a', 'b', 'c']


print (changeMe(mylist))

(a) ['a', 'b', 'c']


(b) ['a', 'b', 'c', [1, 2, 3, 4]]
(c) AttributeError: 'int' object has no attribute 'append'
(d) IndexError: list index out of range
(e) None

44. What will be the output of the following Python code?

Page 16 of 31
CS1033-2021 Intake S1 (Dec 2022)

def pass_by_ref(a):
a[1]='c'
return

x=[10,20,30]
pass_by_ref(x)
print(x)

(a) None
(b) IndexError: list index out of range
(c) [10, 'c', 30]
(d) [10, 20, 30]
(e) ‘c’

45. What will be the output of the following Python code?

def myFunc(a = 100, *b):


for p in b:
a += p
return a

print (myFunc(10,20,30,40))
(a) 90
(b) TypeError: myFunct() got multiple values for argument 'b'
(c) 100
(d) SyntaxError: positional argument follows keyword argument
(e) TypeError: myFunct() got multiple values for argument 'a'

46. What is the minimum length of the register (number of bits) that can be used to represent
-98110 in two’s complement?
(a) 10
(b) 9
(c) 12
(d) 11
(e) 16

47. An integer is represented in 8-bit two’s complement notation as 100110012. What is the
correct decimal value of this integer?
(a) -10310
(b) 10310
(c) -10210
(d) 10210

Page 17 of 31
CS1033-2021 Intake S1 (Dec 2022)

(e) -10410

48. Which of the following statements is false about floating point representation using
mantissa, base, and the exponent?
(a) The width of the mantissa defines the precision of the representation of the real
number.
(b) Any real number can be precisely represented by this notation.
(c) Being constrained to use a finite number of digits for the mantissa is a practical
problem encountered by computers.
(d) Any base can be used to represent an approximate value of a real number using
the floating-point representation.
(e) Decimal (radix) point can be floated to the left or right based on the scaling given
by the exponent.

The IEEE double-precision format for floating-point representation uses 64 bits, which is
divided as follows:
sign → 1 bit
exponent → 11 bits
mantissa → 52 bits

The bias value for the exponent of the double precision format is 1023.

Answer the next two (2) questions based on the IEEE-754 Double Precision format.

49. If the decimal number 25.25 is represented in this format, what is the exponent?
(a) 00000000100
(b) 00000100
(c) 10000000011
(d) 10000000010
(e) None of the above.

50. How many insignificant zero digits (trailing zeros) are there in the mantissa?
(a) 46
(b) 52
(c) 45
(d) 47
(e) 6

51. Which of the following statements is false regarding representation of non-numeric data?
(a) Unicode can represent emojis and symbols.

Page 18 of 31
CS1033-2021 Intake S1 (Dec 2022)

(b) Unicode provides a unique code for every character but depending on the platform
the code could be different (e.g.: Windows vs Linux).
(c) Unicode can use up to 32 bits to represent a given character.
(d) Unicode is designed in such a way to ensure that ASCII is a subset of Unicode.
(e) ASCII code can represent 128 characters only.

52. What will be the output of the following Python code?


data = [1,0,1,0,1,0,1,0,1,0]
sum = 0
for x in data[-1::]:
sum += x
print(sum)
(a) 0
(b) 1
(c) 3
(d) 4
(e) 5

53. What will be the output of the following Python code?


data = [1,0,1,0,1,0,1,0,1,0]
sum = 0
for x in data[::-1]:
sum += x
print(sum)
(a) 0
(b) 1
(c) 3
(d) 4
(e) 5

54. What will be the output of the following Python code?


data1 = [1,0,1,0,1,0,1,0,1,0]
data2 = [0,1]
sum = 0
for x in data1[1:-1]:
sum += data2[x]
print(sum)
(a) 0
(b) 1
(c) 3
(d) 4
(e) 5

Page 19 of 31
CS1033-2021 Intake S1 (Dec 2022)

55. What will be the output of the following Python code?


data = (1,) * 3 + (2,) * 3
sum = 0
for x in data:
sum += x
print(sum)
(a) 0
(b) 3
(c) 6
(d) 9
(e) 12

56. What will be the output of the following Python code?


a = 1
b = 2
(a,b) = (b,a)
data = (a,) * 1 + (b,) * 2
sum = 0
for x in data:
sum += x
print(sum)

(a) 0
(b) 3
(c) 4
(d) 5
(e) 6

57. What will be the output of the following Python code?


a = 1
b = 2
data = (a,a) + (a,b) + (b,a) + (b,b)
sum = 0
for x in data[-7:-2]:
sum += x
print(sum)
(a) 9
(b) 2
(c) 7
(d) 11
(e) 12

58. What will be the output of the following Python code? (Consider left to right evaluation
and standard logical operator precedence order.)

Page 20 of 31
CS1033-2021 Intake S1 (Dec 2022)

A = {0,1,2,3,4,5}
B = {4,5,6,7,8,9}
print(A&B-A|B)
(a) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
(b) {0, 1, 2, 3, 6, 7, 8, 9}
(c) {0, 1, 2, 3, 4, 5}
(d) {4, 5, 6, 7, 8, 9}
(e) {4, 5}

59. What will be the output of the following Python code? (Consider left to right evaluation
and standard logical operator precedence order.)
A = {0,1,2,3,4,5}
B = {4,5,6,7,8,9}
print(A|B-A&B)
(a) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
(b) {0, 1, 2, 3, 6, 7, 8, 9}
(c) {0, 1, 2, 3, 4, 5}
(d) {4, 5, 6, 7, 8, 9}
(e) {4, 5}

60. Which of the following statements is true about the following Python code? (Consider
left to right evaluation and standard logical operator precedence order.)
C = A-B|A&B-A
D = A|B
(a) C is a proper subset of D
(b) C is a subset of D
(c) C is a proper superset of D
(d) C is a superset of D
(e) C and D are disjoint

The code shown below implements a function to check if a number is a prime for numbers
from 1 to 250,000. To test if a number is a prime, we divide it by all the primes up to the
square root of that number and if it is not divisible by any of the primes, then we declare it to
be a prime. Answer the next two (2) questions based on the code.

Page 21 of 31
CS1033-2021 Intake S1 (Dec 2022)

import math

set_of_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
449, 457, 461, 463, 467, 479, 487, 491, 499]
def isprime(n):
limit = int(math.sqrt(n))
for i in range(_____(P)_____):
if _____(Q)_____:
return False
if set_of_primes [i] > limit:
return True

61. Select the appropriate code to fill the blank (P).


(a) n
(b) limit
(c) len(set_of_primes)
(d) 500
(e) 250000

62. Select the appropriate code to fill the blank (Q).


(a) (n/set_of_primes [i]) == 0
(b) (n%set_of_primes [i]) == 0
(c) (n/set_of_primes [i]) != 0
(d) (n%set_of_primes [i]) != 0
(e) (n%set_of_primes [i]) == 0 and limit != 0

63. The code shown below implements a recursive function to sequentially search for an item
in a list. Select the appropriate code to fill the blank (P).
def search(alist, item):
if len(alist) == 0:
return False
elif alist[0] == item:
return True
else:
return _____(P)_____
(a) search(alist[1:], item)
(b) search(alist[:-1], item)
(c) search(alist[1:-1], item)

Page 22 of 31
CS1033-2021 Intake S1 (Dec 2022)

(d) search(alist[:int(len(alist)/2)], item)


(e) search(alist[int(len(alist)/2):], item)

64. When sorting a moderately sized collection of data items that are randomly arranged,
what is the sorting algorithm that is likely to have the worst performance?
(a) Bubble sort
(b) Insertion sort
(c) Shell sort
(d) Merge sort
(e) Heap sort

The code shown below implements an expression parser for simple mathematical expressions
(for example, "1 + 2 ") to extract individual terms (for example, 1, ‘+’, 2).

def expressionParser(expr):
operators = {'+','-','*','/','^'}
termlist = []
term = ''

for c in expr:
if (c != ' '):
term = term+c
else:
if(_____(P)_____):
termlist.append(term)
elif('.' in term):
termlist.append(float(term))
else:
termlist.append(int(term))
term = ''

return _____(Q)_____

Answer the next two (2) questions, based on this code.

65. Select the appropriate code to fill the blank (P).


(a) term in expr
(b) c in operators
(c) c in expr
(d) term in operators
(e) c in term

66. Select the appropriate code to fill the blank (Q).


(a) termlist[1:]
(b) termlist[:-1]

Page 23 of 31
CS1033-2021 Intake S1 (Dec 2022)

(c) termlist[1:-1]
(d) termlist.append(c)
(e) termlist[:]

The code shown below implements the abstract data type Stack using the abstract data type
Linked List. This stack is designed to assign a sequence number to each data item pushed on
to the stack so that when a data item is popped from the stack it is possible to determine the
sequence number at which the data item has been pushed to the stack.

class Node:
def __init__(self,data):
self.data = data
self.next = None

def show(self):
print(self.data)

class Stack:
def __init__(self):
self.head = None
self.size = 0
self.counter = 0

def isEmpty(self):
return _____(P)_____

def push(self,data):
node = Node((self.counter,data))
self.counter += 1
if self.isEmpty():
_____(Q)_____
else:
node.next = self.head
_____(R)_____
self.size += 1

def pop(self):
if self.isEmpty():
raise Exception("Cannot pop from an empty stack")
else:
node = self.head
_____(S)_____
self.size -= 1
return node

def getSize(self):
return self.size

def getCounter(self):
return self.counter

Answer the next four (4) questions, based on this code.


67. Select the appropriate code to fill the blank (P).
(a) self.counter == 0

Page 24 of 31
CS1033-2021 Intake S1 (Dec 2022)

(b) self.counter == self.size


(c) self.size == 0
(d) self.counter == 0 and self.size == 0
(e) self.counter-self.size == 1

68. Select the appropriate code to fill the blank (Q).


(a) self.head = None
(b) self.next = node
(c) self.next = None
(d) self.head = self.next
(e) self.head = node

69. Select the appropriate code to fill the blank (R).


(a) self.head = None
(b) self.head = node
(c) self.next = node
(d) self.next = None
(e) self.head = self.next

70. Select the appropriate code to fill the blank (S).


(a) self.head = self.head.next
(b) self.next = self.head.next
(c) self.head = self.next.head
(d) self.next = self.next.head
(e) self.head = self.next

The code shown below implements a Reverse Polish Notation (RPN) calculator for simple
mathematical expressions given in RPN (for example, "1 2 + "). The function RPNCalculator
calls the function evaluate to do computations. The supported operators are addition,
subtraction, multiplication, division, and exponentiation.

An expression can be evaluated by calling the functions as below.

RPNCalculator(expressionParser("990 1 2 + * "))

This expression would evaluate to the value 2970 in the following manner.
Read 990
Read 1
Read 2
Read +
evaluate 2 + 1 and replace with 3

Page 25 of 31
CS1033-2021 Intake S1 (Dec 2022)

Read *
Evaluate 3 * 990 and replace with 2970

def evaluate(_____(P)_____):
result = 0
if(opr == '+'):
result = op1 + op2
elif(opr == '-'):
result = op1 - op2
elif(opr == '*'):
result = op1 * op2
elif(opr == '/'):
result = op1 / op2
elif(opr == '^'):
result = op1 ** op2
else:
print("illegal operator")
return result

def RPNCalculator(expr):
operators = {'+','-','*','/','^'}
i=0
while len(expr)>1:
for term in expr:
if term in operators:
result = evaluate(_____(Q)_____)
expr = expr[:i-2] + [result] + expr[i+1:]
i = 0
break
i = i+1
return result

Answer the next two (2) questions, based on this code.

71. Select the appropriate code to fill the blank (P).


(a) op1, op2, opr
(b) opr, op1, op2
(c) op1, opr, op2
(d) op2, op1, opr
(e) opr, op2, op1

72. Select the appropriate code to fill the blank (Q).


(a) expr[i], expr[i-1], expr[i-2]
(b) expr[i-2], expr[i-1], expr[i]
(c) expr[i-1], expr[i], expr[i-2]
(d) expr[i-2], expr[i], expr[i-1]
(e) expr[i-1], expr[i-2], expr[i]

Page 26 of 31
CS1033-2021 Intake S1 (Dec 2022)

The function combinations is designed to generate all the combinations of a given list of
items. For example, for input [1, 2, 3], it should output [[], [1], [2], [2, 1], [3], [3, 1], [3, 2],
[3, 2, 1]].

def combinations(alist):
if len(alist) == 0:
return [[]]
sublist = []
for c in _____(P)_____:
sublist = _____(Q)_____
return sublist

Answer the next two (2) questions, based on this code.

73. Select the appropriate code to fill the blank (P).


(a) combinations(alist[:])
(b) combinations(alist[:-1])
(c) combinations(alist[1:-1])
(d) combinations(alist[1:])
(e) combinations(alist[1:1])

74. Select the appropriate code to fill the blank (Q).


(a) sublist + [c + [alist[0]]]
(b) sublist + [c, [alist[0]]]
(c) sublist + [alist[0]]
(d) sublist + [c, c + [alist[0]]]
(e) sublist + [c]

75. Which of the following CPU operation is likely to be completed within the shortest
possible time?
(a) NOP instruction
(b) ADD instruction
(c) MOV instruction
(d) JUMP instruction
(e) SUB instruction

76. The term MIPS is used to measure:


(a) How many instructions could the CPU support
(b) How fast can the CPU execute instructions
(c) The speed (frequency) of the CPU clock signal
(d) The voltage at which the CPU would operate

Page 27 of 31
CS1033-2021 Intake S1 (Dec 2022)

(e) None of the above

77. The clock signal of a CPU would determine:


(a) The speed at which the internal operations of the CPU are carried out
(b) The speed at which the external operations of the CPU are carried out
(c) The speed at which both internal and external operations are carried out
(d) How many instructions are there in the CPU instruction set
(e) None of the above

78. The “volatile memory” is a type of memory:


(a) That would lose its content when the power is interrupted
(b) That is used to store the initial startup software of a computer
(c) That would retain its content even if the power supply is interrupted
(d) That is used to store usernames and passwords
(e) Of which the contents are written at the time of manufacture

79. Which of the following is NOT an internal component of the Central Processing Unit?
(a) The control unit
(b) The Arithmetic and logic unit
(c) The Flag register
(d) Program Status Word register
(e) The power supply unit

80. The memory sub-system in Processor A has a 16-bit address bus and 16-bit data bus. The
memory sub-system of Processor B has a 16-bit address bus and an 8-bit data bus. Which
of the following statement is NOT correct about the two processors?
(a) The maximum memory capacity of Processor A will be twice as that of Processor
B
(b) The largest memory address in both processors will be the same
(c) The Processor A is likely to be able to read the memory faster than Processor B
(d) Internal registers of Processor A are likely to be 16-bit wide
(e) The clock speed of Processor A will be twice as fast as the clock speed of
Processor B

81. Which of the following is not an intended function of the general-purpose registers in a
CPU?
(a) Store the address of the next instruction to be executed in the program
(b) To store intermediate outputs computed by the ALU

Page 28 of 31
CS1033-2021 Intake S1 (Dec 2022)

(c) To keep user data


(d) To store inputs to be used for ALU operations
(e) To function as operands for CPU instructions

82. Which of the following is NOT an activity carried by the Bus Mater in a computer
system?
(a) Drive the address bus of the system bus during a memory operation
(b) Drive the data bus of the system when reading from memory
(c) Drive the data bus of the system bus during a memory write
(d) Drive the control bus of the system during a memory operation
(e) Sample the data bus during a memory read operation

83. Immediately after switching on power to a computer, its RAM will contain:
(a) The “Power On Self Test (POST)” software
(b) The “Basic Input Output Services (BIOS)” software
(c) The Operating system software
(d) System initialization software
(e) Random values

84. Running a Processor at a clock frequency higher than its rated value:
(a) Would make the processor to complete some of its tasks faster
(b) Would make the processor to consume more power
(c) Would make the processor to dissipate more heat
(d) Would result more wait-states in reading or writing to memory
(e) May result all the above

85. The OPCODE part of a CPU instruction would define:


(a) The nature of the operation carried by the instruction
(b) The type of operands needed for the instruction
(c) The length of the instruction
(d) Time (clock cycles) required to execute the instruction
(e) All of the above

86. Two different processors, Processor A and Processor B have 16-bit ALUs. Processor A
has a 16-bit data bus, but on Processor B, the data bus is only 8-bit. Suppose these
processors are executing CPU instructions that add two integer values ranging between
-32000 and +32000. Which of the following statement is correct?
(a) Processor B will require more memory access cycles to complete the task

Page 29 of 31
CS1033-2021 Intake S1 (Dec 2022)

(b) Processor B will require more internal ALU operations to complete the task
(c) Processor B will not be able to add the two numbers in a single instruction
(d) All of the above statements are correct
(e) None of the above statements are correct

87. Consider the following activities that occur when transferring data through the system
bus.
A. Placing the address on the Address Bus
B. Setting the READ signal on the Control Bus
C. Reading the value on the Data Bus
What would be the correct order of above activities in a memory read cycle?
(a) A, B, C
(b) A, C, B
(c) B, A, C
(d) C, B, A
(e) All happens at the same time

88. Which of the following is not a CPU internal operation common to ALL CPU
instructions?
(a) Incrementing the program counter
(b) Fetching the instruction
(c) Decoding the instruction
(d) Executing the instruction
(e) Fetching operands

89. Which of the following is NOT a task of the bus master in a System bus?
(a) Driving the Address Bus content
(b) Controlling signals on the Control-Bus
(c) Sending the reset signal during a system startup
(d) Reading or writing to the Data bus
(e) Distributing power to all bus-connected devices

90. The CPU A is a RISC processor that runs at 1 GHz clock speed. CPU B is a CISC
processor that runs at 2 GHz clock speed. Which of the following statements is NOT
correct regarding the two CPUs?
(a) CPU B is likely to have more instructions in its instruction set compared to CPU
A
(b) Instructions in CPU A will be optimized for more common operations

Page 30 of 31
CS1033-2021 Intake S1 (Dec 2022)

(c) CPU B will have several instructions performing similar operations


(d) CPU A may require more instructions to complete certain tasks compared to CPU
B
(e) CPU B will always be faster in performing a task due to its higher clock speed

-----------------------------

Page 31 of 31

You might also like