20 Batch (2022)
20 Batch (2022)
Faculty of Engineering
B.Sc. Engineering
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.
• This paper consists of 20 pages, including this page.
• This paper consists of 90 multiple-choice, Yes/No and short answer questions; each
question is worth 1 mark.
o For multiple choice questions, 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 for multiple choice questions.
o For Yes/No questions, clearly write one choice – Yes or No. There is a -1 mark
penalty for wrong answers. If you do not know the answer, leave it blank, do not
guess the answer.
o For short answer questions, write your answer in the space provided in the answer
sheet. There is no penalty for wrong answers for short answer questions.
-----------------------------
CS1033-2020 Intake S1 (Jan 2022) Registration
Number
Answer Sheet
Write your answer clearly in the space provided for each question. For multiple-choice
questions, write your choice, (a), (b),… and for Yes-No questions, write either Yes or No.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
33 34 35 36
37 38 39 40
41 42 43 44
45 46 47 48
49 50 51 52
53 54 55 56
57 58 59 60
61 62 63 64
65 66 67 68
69 70 71 72
73 74 75 76
77 78 79 80
81 82 83 84
85 86 87 88
89 90
-----------------------------
Page 2 of 20
CS1033-2020 Intake S1 (Jan 2022)
min ← L[x]
No
1. For the algorithm to work
as expected, what should be
in blank (A) in Fig. 1?
Yes
Is max < L[x]?
2. For the algorithm to work
…. (B) ….
as expected, what should be No
in blank (B) in Fig. 1?
Stop Fig. 1
Page 3 of 20
CS1033-2020 Intake S1 (Jan 2022)
For each of the next three questions, find the most suitable word or words to fill the blank.
4. When we use flowcharts to express algorithms, the decision () symbol is used to
implement the selection control structure and the ________________ control structure.
5. When a program has bugs (run-time or logic errors) that are difficult to find, using a
software tool such as a __________ is generally the next step towards fixing the bugs.
7. Suppose there are two Python programs A and B to solve a problem. If program A is
much longer (has many more lines of code) than program B, then program A will always
take more time to execute than program B.
[Yes/No]
The algorithm is expected to take as input two positive integers 𝑥 and 𝑛 and output 𝑥 𝑛 , that is
the 𝑛-th power of 𝑥. Note that the algorithm uses the following two properties:
(1). If 𝑛 is odd: 𝑥 𝑛 = 𝑥 ∙ (𝑥 𝑛⁄2 ) ∙ (𝑥 𝑛⁄2 )
(2). If 𝑛 is even: 𝑥 𝑛 = (𝑥 𝑛⁄2 ) ∙ (𝑥 𝑛⁄2 )
Two blanks (D) and (E) are to be filled in. Note that “*” is the multiplication operator.
1. Start
2. Input x and n
3. P ← 1
4. if n = 0 then go to Step 9
5. if ....(D).... then P ← P * x
6. x = x * x
7. .... (E) ....
8. Go to Step 4
9. Output P
10. Stop
8. In the above algorithm, what should be in the blank (D) for the algorithm to work as
expected?
9. In the above algorithm, what should be in the blank (E) for the algorithm to work as
expected?
Page 4 of 20
CS1033-2020 Intake S1 (Jan 2022)
10. Consider the following statements about the problem of computing 𝑥 𝑛 and the algorithm
given above.
I. A recursive algorithm can be developed based on the same two properties (1) and
(2) corresponding to the cases where 𝑛 is odd and even.
II. A simpler alternative algorithm can be developed for computing 𝑥 𝑛 using the
property 𝑥 𝑛 = 𝑥 ∙ (𝑥 𝑛−1 ).
III. The given algorithm will not work correctly if 𝑛 = 0.
11. What will be the result when the following Python code is executed?
2 ** (True * 5)
(a) 1
(b) 32
(c) 10
(d) An error message
(a) I only.
(b) II only.
(c) III only.
(d) I and II only.
(e) I, II and III – all are correct.
Page 5 of 20
CS1033-2020 Intake S1 (Jan 2022)
“In Python, comparison operators have a lower precedence than logical operators.”
[Yes/No]
Page 6 of 20
CS1033-2020 Intake S1 (Jan 2022)
20. What will be the output of the following Python code, if the input is “a b c d”?
instring = input('Enter your input: ')
s = instring.split()
print(s)
21. The objective of the following Python code is to read a file and display its contents.
with open('foo.txt', 'r') as fo:
s = fo.read()
print( "file contents:", s)
Which of the above statements is/are correct about the given Python code?
(a) I only
(b) II only
(c) I and II only
(d) III only
(e) I and III only
22. What will be the output of the following Python code, if the input is ‘LPGas’ ?
x = len(input('Enter a word: '))
if (x >= 2):
k = x ** 2
if (x >= 4):
k = k + 100
if (x == 4):
k = k + 200
else:
k = k + 300
else:
k = k + 500
else:
k = x + 600
print(k)
(a) 410
(b) 316
(c) 425
(d) 525
23. What is the minimum length of the register (number of bits) that can be used to represent
-25310 in two’s complement?
Page 7 of 20
CS1033-2020 Intake S1 (Jan 2022)
24. An integer is represented in 8-bit two’s complement notation as 110110112. What is the
correct decimal value of this integer?
(a) -3710
(b) 21910
(c) 21810
(d) -3810
The IEEE single-precision format for floating-point representation uses 32 bits, which is
divided as follows:
sign → 1 bit
exponent → 8 bits
mantissa → 23 bits
Answer the next two (2) questions based on the IEEE-754 Single Precision format.
26. If the decimal number 17.875 is represented in this format, what is the exponent?
27. How many insignificant zero digits (trailing zeros) are there in the mantissa?
28. Which of the following statements is false regarding representation of non-numeric data?
(a) An ASCII code can be represented by a 7-bit binary number.
(b) Unicode provides a unique code for every character irrespective of the platform,
program, or the writing system.
(c) ASCII code can represent characters in any language or writing system on a given
platform.
(d) Unicode can use up to 32 bits to represent a given character.
Page 8 of 20
CS1033-2020 Intake S1 (Jan 2022)
(a) Will print the sum of all even numbers between 0 and 100.
(b) Will print the sum of all odd numbers between 0 and 100.
(c) Will print the sum of all the even numbers between 0 and 102.
(d) None of the other answers are correct.
35. How should we replace the line of CODE in the Code segment 2 to also produce the same
output as the Code segment 1?
Page 9 of 20
CS1033-2020 Intake S1 (Jan 2022)
# Code segment 1
number = 1
while number < 10 :
if number % 2 == 0:
print("The number ",number," is even")
number+=1
# Code segment 2
number = 1
while number < 10 :
while number % 2 == 0:
print("The number ", number," is even")
CODE # code to be replaced
number+=1
(a) exit
(b) pass
(c) break
(d) continue
Page 10 of 20
CS1033-2020 Intake S1 (Jan 2022)
(a) 10
(b) 100
(c) 110
(d) [10,100]
45. What will be printed as the output of the following Python code?
print("x%6.2fx"%(15))
(a) x 15.00x
(b) x15.00x
(c) x15x
(d) Code will not execute due to syntax error.
Page 11 of 20
CS1033-2020 Intake S1 (Jan 2022)
Consider the following abstract data type Deque implemented in Python to provide the
behavior of a queue and stack simultaneously to answer the next three (3) questions.
Fill the three blanks (P), (Q), and (R) in the following Python code and write them as answers
to the next three (3) questions.
buffer = []
size = 0
buffer.append(data)
size += 1
Page 12 of 20
CS1033-2020 Intake S1 (Jan 2022)
Consider the following abstract data type Linked List implemented in Python to provide the
behavior of a dynamically growing list to answer the next three (3) questions.
Fill the three blanks (P), (Q) and (R) in the following Python code and write them as answers
to the next three (3) questions.
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
Page 13 of 20
CS1033-2020 Intake S1 (Jan 2022)
Consider the following recursive Python function for finding the maximum value in an array
to answer the next three (3) questions. As an example, the function call func([13, 19,
11, 17],4) will return the value 19.
Fill the three blanks (P), (Q), and (R) in the following Python code and write them as answers
to the next three (3) questions.
def func(a,n):
# base case
if(n == _____(P)_____):
return a[0]
# recursive case
else:
x = _____(Q)_____
if(x > a[n - 1]):
return x
else:
return _____(R)_____
Consider the following recursive Python function for computing the exponentiation ab to
answer the next three (3) questions. As an example, the function call func(2,10) will return
the value 1024.
Fill the three blanks (P), (Q), and (R) in the following Python code and write them as answers
to the next three (3) questions.
# recursive case
if (b % 2 == 0):
return _____(Q)_____
return _____(R)_____
Page 14 of 20
CS1033-2020 Intake S1 (Jan 2022)
Consider the following recursive Python function for converting a string to a number to
answer the next three (3) questions. As an example, the function call func("2021",0) will
return the integer value 2021.
Fill the three blanks (P), (Q), and (R) in the following Python code and write them as answers
to the next three (3) questions.
def func(s,n):
# base case
if len(s) == 1:
return _____(P)_____
# recursive case
return _____(R)_____
To answer the next four (4) questions, consider the following divide-and-conquer paradigm
based Python function for finding the total value of a binary tree in which each node stores a
value. As an example, for the binary tree shown in figure below, it will return the value 99.
Fill the four blanks (P), (Q), (R) and (S) in the following Python code and write them as
answers to the next four (4) questions.
class Node():
Page 15 of 20
CS1033-2020 Intake S1 (Jan 2022)
def getNodeValueTotal(root):
if (root == None):
return 0
total = root.value
# divide and conquer
if (_____(P)_____):
_____(Q)_____
if(_____(R)_____):
_____(S)_____
return total
Consider the following hash table data structure implemented in Python that handles hash
collisions by linear probing to answer the next four (4) questions.
Fill the four blanks (P), (Q), (R) and (S) in the following Python code and write them as
answers to the next four (4) questions.
hash_table = [None] * 10
if(not inserted):
print(value,'could not be inserted')
Page 16 of 20
CS1033-2020 Intake S1 (Jan 2022)
74. Which of the following is not a module in the logical organization of a computer system?
(a) CPU
(b) Input devices
(c) System bus
(d) Cache memory
76. What would be the size of RAM installed in a desktop or notebook computer sold at
present?
(a) About 4 GB
(b) About 1 GB
(c) About 4 KB
(d) About 4 MB
77. Which of the following is not a type of operation normally handled by the ALU of a
Central Processing Unit?
(a) Addition and subtraction of numbers
(b) Converting between character values and their ASCII codes
(c) Comparing two numerical values
(d) Performing logical operations on binary-coded values
Page 17 of 20
CS1033-2020 Intake S1 (Jan 2022)
78. Which of the following is not a function of the Control Unit in a CPU?
(a) Decoding an instruction
(b) Decoding addresses in the Address bus
(c) Fetching instruction opcodes
(d) Activating ALU operations
79. Consider the following operations carried by the CPU when working with the main
memory of a computer
A. Send the address of the memory location through the address bus
B. Read data from the data bus
C. Activate the memory read control in the control bus
What will be the correct sequence of operation when the CPU is reading from memory?
(a) A, B, C
(b) A, C, B
(c) A, B only
(d) None of the above
80. Which of the following statements are false about the CPU's Program Counter
(Instruction Pointer) register?
(a) It maintains the address of the next instruction to be executed
(b) It is not used to store data
(c) It is directly connected ALU of the CPU
(d) Each time an instruction is fetched, the register is incremented
82. Most CPU instructions would need one or more data values for the instruction to be
executed. Which part of the instruction cycle would load the data into the CPU?
(a) The Fetch sub-cycle
(b) The Decode sub-cycle
(c) The Operand fetch sub-cycle
(d) The Execute sub-cycle
Page 18 of 20
CS1033-2020 Intake S1 (Jan 2022)
83. Which of the following instruction opcodes would not require any data for execution?
(a) LOAD
(b) STORE
(c) NOP
(d) JUMP
Consider the following description to answer the next four (4) questions.
The illustration in the Figure below shows part of the CPU internal structure containing the
ALU, a few registers and interconnections between them for data transfer. Note that arrows
indicate the possible direction of data transfer through these connections. Based on the
diagram, indicate which of the following CPU operations would be possible or not possible.
85. Subtracting register B from Register C and storing the result in Register A.
86. Subtracting Register D from Register C and storing the result in Register A.
Consider the following description to answer the next three (3) questions.
Table 1 below shows the number of clock cycles required by two CPUs to carry out its
internal operations (assume that 0 clock cycles are used for any operation not included in the
table).
Page 19 of 20
CS1033-2020 Intake S1 (Jan 2022)
Percentage in the
Instruction type
program
Loading data to a register from a memory location following
40%
the instruction opcode
Storing data in memory location whose address is present
20%
immediately following the instruction opcode
Arithmetical and logical operations 10%
Copying data from one register to another 20%
No operations 10%
88. If CPU Alpha runs at 2.0 MHz and CPU Beta runs at 1.0 MHz clock speeds, then CPU
Alpha will be faster than CPU Beta in executing the program.
[Yes/No]
89. If both CPUs run at the same clock speed, then CPU Beta will be faster than CPU Alpha
in executing the program.
[Yes/No]
90. If CPU Beta runs at 1.0 MHz clock speed, what percentage of time will it spend on “No
Operation” instructions?
Page 20 of 20