Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

A Name, SURNAME ⇒

Middle East Technical University


Department of Computer Engineering
CENG 111
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000

Instructor: 11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000

Sinan Kalkan, Göktürk Üçoluk


Assistants: Fall 2010-2011
Erdal Sivri, Hande Çelikkanat, Gökdeniz Karadağ, Sefa Kiliç,
Sinem Demirci, Okan Tarhan Tursun, Mustafa Levent Eksert
Midterm

• Duration: 80 minutes.
• Question:
– There are 48 TRUE-FALSE and 19 Multiple choices questions.
– If a question is in the context of an Operating System, it is Unix.
– If a question is in the context of programming, unless it is stated otherwise, it is
Python. In case of contradictions: questions have to be answered primarily accord-

A
ing to the lectures, secondarily according to the book and lastly according to other
material.
• Grading:
– Each TRUE-FALSE question is worth 1.2 points.
– Multiple choices are worth 2.2 points each.
– For all questions (including TRUE-FALSE questions) 4 wrong points cancel 1 correct.
– Everybody receives a teacher’s bonus of 0.6 point.
• Asking questions: Absolutely forbidden! If you decide that a question is wrong:
– In no way express openly your opinion, DOING so WILL BE considered
as CHEATING!, you will be removed from the exam place.
– DO NOT ask the proctor about a clarification.
• Turn in your question booklet (this booklet). Otherwise your answer sheet will not be
evaluated, and you will receive a zero from this exam.
• GOOD LUCK !

1
We start with TRUE-FALSE questions, mark A box for TRUE, B box for
FALSE on your answer sheet

1 There is more than one way to build a logical circuit of m inputs and n outputs that has
its action defined as a given truth table.

2 After 1996, a server located at www.atomicclock.org is contacted by the operating system


(both Windows, Mac OS and Linux) and the frequency of the microprocessors clock input
is measured by the aid of this standard clock, then it is fine tuned by the operating system.

3 Computers in these days use byte representations. A byte can take 256 different values. At
hardware level these 256 different values correspond to 256 different voltages in the range
[0-5] Volts.

4 An interpreter is a peripheral of a digital computer. It is the common term for devices that
serve as interface bridges for different data communication protocols/systems.

5 It is possible to assign any natural number as the address of a given memory cell provided
that no overlapping occurs. This is called the memory-bootstrapping and is performed
prior to the loading of the Operating System.

6 Suppose that we have a file named ceng111 with the permissions rwxr-x--x. After exe-
cuting

A
chmod g-x,o+rw ceng111
the file permissions become r-xrwx--x.

7 By means of the Memory manager and the DMA chip it is possible to execute a program
that exceeds the size of the physical memory on the computer. This mechanism is called
virtual memory.

8 Language translators allow users to write in a user-oriented language rather than machine
language.

9 Assembly languages allow programmers to name machine instructions and to refer them
by these programmer given names.

10 To avoid wasting time of a processor in polling loops, hardware interrupts are used. So, a
hardware unit can gain the attention of the CPU only when it needs to.

11 An interpreter is a program that converts the commands expressed in a certain language


to an internal structure and executes them immediately. An interpreter goes in a read-
execute-print result loop for ever until it is quitted.

12 BIOS stands for Build In Open System.

13 It is possible to assign any natural number as the address of a given memory cell provided
that no overlapping (repetition) occurs.

14 An instruction is fetched from the memory using the ”instruction bus” instead of the ”data
bus” as the content of the fetching operation is an instruction.

15 If the memory address register is 10 bits wide, the last possible address that the computer
could have is 1024.

2
16 DMA stands for Decentralized Multiprocessing Architecture the new trend in computing
which is also known as multi-treading.

17 We have a computer that works with 220 volts. If we plug this computer into a 110 volt
power line, it will work at half speed provided that the power supply is of voltage-controlled-
frequency type. This is indicated by the manufacturer on a back-label of the computer as:

VCF
80−240V

18 Assembly languages are the first developed languages after programming directly with the
machine code.

19 The internal representation of a floating point 555.00 does not coincide (become the same)
with the representation of the integer 555 . This property is called constant folding in
Computer Science.

20 An OR gate can be constructed by a combination of some AND and some NOT gates.

21 Consider the following Unix commands


chmod 753 change.out

A
chmod o-r change.out
chmod 4 same.out
The 4 in the command sequence should be 753 in order to make the permissions of the
file same.out the same with the permissions of the file change.out .

22 The two’s complement representation of a positive number is the same with its ordinary
binary representation using the same number of bits.

23 The program counter holds the instruction that is executed by ALU in each instruction
cycle.

24 Instruction Sets may differ on different processor architectures.

25 A piece of code with 5 instructions always finishes earlier than a code with 7 instructions.

26 If the electronics of the digital computer would admit 3 levels of voltages (in contrary to
today’s computers) then we would have a number representation based on ternary (base-3)
numbers.

27 You are given that the output of the UNIX command: find hws/ -name ’*.c’
is:
hws/hw1.c
hws/hw2.c
Now, assuming hws/oldhws/ exists and has proper write permissions set, after executing
the command:
mv hws/hw1.c hws/oldhws/
the output of the same command (find hws/ -name ’*.c’) becomes:
hws/hw2.c

28 There are three modes in the Von-Neumann machine memory/CPU correspondence:

3
1. Load Memory-to-register data transfer. Here CPU sets the address bus, memory
answers by sending the data of this address over the data bus.
2. Query Memory-to-register address transfer. Here CPU sets the data bus, memory
answers by sending the address that holds that data over the address bus.
3. Store Register-to-memory data transfer. Here CPU sets the address bus, and the
data bus, memory receives both of this information and stores the data (that is sent),
into the location pointed by the address (that is sent).

The CPU will set both the address and the data bus only in case it is going to write
something to the memory.

29 A machine code is universal and is expected to run on any microprocessor (This property
is called PMC standing for Portability of Machine Code).

30 De facto a Von-Neumann architecture of degree II has arbitrary precision integer arithmetic


present. In addition to this, if it also has arbitrary precision floating-point arithmetic, that
architecture is ranked degree III.

31 The expression "Hello"[2] == "Hello"[-2] evalutes to True.

32 The only way to do iteration in Python is by iterating over a list, possibly created by the

A
range() function.

33 The following expression evalutes to True if A and B have the same truth values and False
otherwise:
True if (not A or B) and (A or not B) else False

34 1. a = [1, 2, 3, 4, 5]
2. b = a
3. c = a[:]
Since Python assumes default values for omitted subfields [start:end] in line 3, the as-
signments in lines 2 and 3 have exactly the same effects.

35 In Python, var1 = var2 = "hello" is perfectly legal because it is interpreted as


var1 = (var2 = "hello"), and the return value of the inner assignment, which is the
"hello" string in this case, is assigned to variable var1 afterwards.

36 type(’12’) == type(12).

37 Given three numbers a, b and c, the following is always true: (a+b)+c == a+(b+c).

38 In most of the programming languages, expression evaluation does not have the Church-
Rosser property; however, Python ensures the Church-Rosser property by providing arbi-
trary precision floating point representation.

39 Any recursive algorithm can be converted into an iterative version that makes use of a stack
data structure.

40 According to the Turing Equivalence, all programming languages and all CPUs are equiv-
alent.

41 In Python, only data of mutable data types undergo ”called by sharing”.

4
42 The result of [1, 2] * [3, 4] is [3, 8].

43 The result of [1, 3, 5, 7, 9][:2][-1] is 9.

44 The following function has a side-effect:

def min(L):
m = L[0]
for i in range(len(L))
c = L.pop()
if c < m:
m = c
return m

45 The Church-Rosser property states that it is beneficial to have side-effects.

46 "while" statement is a functional-paradigm tool of Python.

47 In Python, working with immutable data types guarantees that Python does not have
side-effects.

A
48 A function can include only one return statement in its body.

The followings are multiple choice questions.

49 The two’s complement notation in 8-bit for -12 is


A) 244 B) 140 C) 245 D) 116 E) none of these

50 How many logic gates (only AND, OR, NOT) should be used in the optimal circuit (the
circuit with minimum count of gates) for the boolean expression (x means not(x)):

(a · b · c) + (a · b · c) + (a · b · c) + (a · b · c)

A) 1 B) 10 C) 12 D) 14 E) 19

51 Turing machine is
A) a historical machine designed by Charles Babbage
B) a Lisp machine which is designed but never constructed
C) a synonym for the Von Neumann computer
D) a fourth generation programming language
E) none of these

52 What is the mantissa stored in the IEEE-754 representation of floating point 11.25?
(The 0’s after the last 1 in the mantissa is not printed)
A) 1011 D) 1101
B) 01101 E) 11101
C) 101101

5
53 The rotation time for a disk drive is 6000 RPM where there are 600 tracks in one surface
and 100 sectors in one track. The head moves in 0.02 msec from one track to the adjacent
one. Count of bytes in one sector is 128. What is the seek time and latency both in the
worst case?
A) 11.98 msec - 10 msec
B) 12 msec - 10 msec
C) 11.98 msec - 5 msec
D) 12 msec - 5 msec
E) 12 msec - 0.1 msec

54 a.txt and b.txt are two text files. Which one of the below Unix commands results in an
error:
A) cat a.txt >> cat b.txt D) cat a.txt | b.txt
B) cat a.txt | cat b.txt E) cat a.txt < b.txt
C) cat a.txt b.txt

55 Consider the sequences of Unix commands (marked with $) and Operating System responses
(marked with >):
$ pwd
> /home/freshman
$ ls

A
> f1 f2
$ ls f1
> f3
$ cd f2
> bash: cd: f2: Not a directory
What would the proceeding command, given below, result in?
mv ../freshman/f2 f1/f4
A) The folder f2 is moved into the subdirectory f1 and will be renamed as f4
B) Since f2 is a folder, bash will prompt an error message.
C) Since there is no directory named as f4 under directory of f1, bash will prompt
an error message.
D) A directory named as f4 is created under the directory /home/freshman/f1 and
the file f2 will be moved into directory f4.
E) The file f2 is moved into directory having the absolute path /home/freshman/f1
and will be renamed as f4

56 Assume a computer uses 10 bits to represent integers with sign-magnitude notation. Which
integer values X could not be represented on this system?
A) All X such that X < 0 or X > 1024
B) All X such that X < −1024 or X > 1024
C) All X such that X < −512 or X > 512
D) All X such that X < −511 or X > 511
E) All X such that X < −1023 or X > 1023

57 Which programming paradigm is based on making declarations of rules and/or truth as-
sertions about various facts.
A) Imperative D) Object oriented
B) Functional E) Concurrent
C) Logical

6
58 The sign ⊕ represent the logical XOR operation. XOR evaluates to 0 if its operants are
equal and 1 if they are different. Find the truth table of the following digital circuit.

C = (p ⊕ q) + pq

A) p q C D) p q C
0 0 1 0 0 0
0 1 1 0 1 1
1 0 1 1 0 1
1 1 1 1 1 1

B) p q C E) p q C
0 0 1 0 0 0
0 1 0 0 1 0
1 0 0 1 0 0
1 1 1 1 1 0

C) p q C
0 0 1
0 1 1
1 0 1

A
1 1 0

59 What does the following Python code print on screen?

a = [3, 5, ’ceng’]
b = a
c = a[1:3]
a[1] = 7.5
b[1] = 8
c[1] = ’ceng111’
print a, b, c

A) [7.5, 5, ’ceng’] [8, 5, ’ceng’] [’ceng111’, ’ceng’]


B) [3, 7.5, ’ceng’] [3, 8, ’ceng’] [5, ’ceng’]
C) [3, 8, ’ceng’] [3, 8, ’ceng’] [5, ’ceng111’]
D) [3, 7.5, ’ceng’] [3, 8, ’ceng’] [’ceng111’, 5, ’ceng’]
E) [3, 7.5, ’ceng’] [3, 8, ’ceng’] [3, ’ceng111’, ’ceng’]

60 What does the following Python code print on screen?

def f(x):
x[:] = x[::-1]
def g(x):
x = x[::-1]
def h(x):
return x[::-1]
lst1 = [1, 2, 3]
lst2 = [1, 2, 3]
lst3 = [1, 2, 3]
f(lst1)

7
g(lst2)
h(lst3)
print lst1, lst2, lst3

A) [3, 2, 1] [1, 2, 3] [1, 2, 3]


B) [1, 2, 3] [1, 2, 3] [1, 2, 3]
C) [3, 2, 1] [3, 2, 1] [3, 2, 1]
D) [3, 2, 1] [3, 2, 1] [1, 2, 3]
E) [1, 2, 3] [1, 2, 3] [3, 2, 1]

61 def f(L, m):


i=0
j=len(L)-1
k = (i+j)/2
while not (L[k] == m or i>j):
if m>L[k]:
i=k+1
else:
j=k-1
k = i +(j-i)/ 2
return k

A
What is the return value of the following function call?
f([14, 21, 12, 38, 7, 8, 10, -2, 16, 32, 42, 0, 23], 21)
A) 1
B) 12
C) 6
D) 7
E) none of these

62 def f(n):
return g(n)+g(n+2)

def g(n):
if n<=1:
return n
else:
return g(n-1)+g(n-2)
When we call f(3), function g is called n times and f returns m. What will be the values
of n and m respectively?
A) 1
B) 12
C) 6
D) 7
E) none of these

63 print int (int( 4 / 2.1 ) / 5 + float(4/5) + 7 + (3.6 + 5/8))


prints the following:
A) 10 B) 11 C) 12 D) 13 E) 14

64 What is the output of the following code?

8
def f():
def g():
print "fg",
print "f",
g()

def g():
def f():
print "gf",
print "g",
f()

g()
f()

A) Syntax error
B) Error about the re-definition of functions
C) g gf f fg
D) gf gf fg
E) none of these

65 What is the output of the following code?

A
def min(L):
m = L[0]
for i in range(len(L)):
c = L.pop()
if c < m:
m = c

return m

def max(L):
m = L[0]
for i in range(len(L)):
c = L.pop()
if c > m:
m = c

return m

L = [3, 2, -10, 5]
minimum = min(L)
maximum = max(L)
print minimum, maximum

A) -10, 5
B) Syntax error
C) ”List index out of range” error
D) 2, 5
E) none of these

66 What would you say about the following two functions?

9
def min1(L):
m = L[0]
length = len(L)
i = 0
while i < length:
if L[i] < m:
m = L[i]
return m
def min2(L):
m = L[0]
i = 0
while i < len(L):
if L[i] < m:
m = L[i]
return m

A) The length of the list is accessed only once, which makes min1 faster.
B) Storing the length of the list in a variable is beneficial because it makes it explicit.
C) There is no difference between these functions; Python interpreter evaluates
len(L) in function min2 only once
D) There is a syntax error in these functions.
E) none of these

A
67 What does the following function do?

def f(N):
return N if N == 0 or N == 1 else (True if not f(N-1) else False)

A) There is a syntax error.


B) It computes whether N is prime.
C) It computes whether N is even.
D) It computes whether N is odd
E) none of these

10

You might also like