0 ratings0% found this document useful (0 votes) 143 views16 pagesComputer Science Final Exam (2008)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Page 0
German University in Cairo 1d, Feb 2008
Computer Science and Engineering Department
Prof. Dr. Slim Abdennadher
Introduction to Computer Science, WS 2007-2008
FinalTerm Exam
Bar Code
Instructions: Read carefully before proceeding.
1) Duration of the exam: 3 hours (180 minutes).
2) (Non-programmable) Calculators are allowed.
3) No books or other aids are permitted for this test
4) This exam booklet contains 14 pages, including this one, Three extra sheets of scratch paper are
attached and have to be kept attached, Note that if one or more pages are missing, you will
lose their points. Thus, you must check that your exam booklet is complete.
5) Write your solutions in the space provided. If you need more space, write on the back of the sheet
containing the problem or on the three extra sheets and make an arrow indicating that. Seratch
sheets will not be graded unless an arrow on the problem page indicates that the
solution extends to the scratch sheets,
6) When you are told that time is up, stop working on the test
Good Luck!
Don't write anything below ;-)
Exercise TT273]4 7 ]
PosbleMarks [6 [6 | 6 [ 6 [wl o6 | 5 | [wm
Final Marks
o
-|
odIntroduetion to Computer Science, FinalTerm Exam, 14. Feb 2008 Paget
Exercise 1 (6 Marks)
a) Convert the binary number 11010112 to a decimal number (base 10). Show your workout.
Solution:
242484214 "= 64432484241 = 1070
'b) Convert the decimal number 122; to a number in base 7, Show your workout,
Solution:
Division Quotient Remainder
22/77 3
uy? 2 3
270 2
12210 = 2331
c) Convert the hexadecimal number AF 10Byg toa binary number. Show your workout,
Solution:
A F 1 0 8B
1010 1111 0001 0000 1011
‘Thus AF1OBs = 10101111000100001011,Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 2
Exercise 2 (6 Marks)
Show how the decimal number 6.969 is stored in a computer that uses 16 bits to represent real numbers
(10 for the mantissa and 6 for the exponent, both including the sign bit). Show your work as indicated
below.
a) Show the binary representation of the decimal number 6.969.
Solution:
6.96919 = 110.111110.
0.969%2 = 1938
0.93842 = L876
087642 = L752
0.75242 = 1504
0.50442 = 1.008
0.008 + 2 1016
'b) Show the binary number in normalized scientific notation.
Solution:
6.9699 = 110.111110) = 110111110 x 2%
¢) Show how the binary number will be stored in the 16 bits below.
Sign oF Mantissa Sign of Exponent
mantissa exponent
Lit Obits Lit Sits
Solution:
0 0111110. 0 ooo
Sign of Mantissa Sign of Exponent
mantissa exponent
Lit Obits Lit ShitsIntroduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 3
Exercise 3 (6 Marks)
a) How many bits at least will be needed to store the unsigned number 31, Justify your answer.
Solution:
S bits since $119 = 11111,
'b) How many bits at least to store the number —31 in sign-magnitude notation? Justify your answer.
Solution:
Gits since the range for signed mumbers in sign-magnitude notation: [~
=31=-(2°=1).
) How many bits at least to store the number ~32 in two's complement notation? Justify your answer.
11), 2°11] and
Solution:
6 bits since the range for signed numbers in two's complement notation: [-2"~
=32=-(2°)
1-4] andIntroduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 4
Exercise 4 (6 Marks)
Assume that our computer stores decimal numbers using 8 bit
Perform the subtraction
(-28)10-()o
using 2's complement notation. Give the result of thesubtraction in decimal. Show your workout, i.e. all
steps performed.
Solution:
© Convert 28 and 5 to binary:
2810 = 000111002
51g = 000001013,
* Two's complement representation of -28
289 = 11100100
# Two's complement representation of —5,
Sig = 11111011
‘© Perform the addition (—28)q — (5)io in binary:
11100100 + 11111011 = 111011111
# Remove the overflow:
oni
# The binary number 11000011 represents the negativedecimal value ~33.
The corresponding positive number of 11011111 is 00100001 which corresponds to 38.Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Pages
Exercise 5 (10 Marks)
Given the following the following truth table, where A, B and C are the input variables and X is the
output variable
PPeeeeces|
=)-Fele|-lTeleye}
—elle|-fe)1eI4)
=)=)=]=Jeheh ele] x4
a) Use the sum-of-products algorithm to find the Boolean expression that describes the output of the
truth table.
Solution:
= AB'C' + AB'C + ABC! + ABC
'b) What is the functionality of the circuit? You should express it in form of an arithmetic operation.
Solution:
Assuming that the input variables correspond to a decimal number V from 0 until 7, the circuit
will perform the following operation, where the division is an integer division:
N
7
Another possible solution could be: The circuit checks whether
a4
) Draw the Boolean circuit. Note that each gate can have only two inputs.Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 6
Exercise 6 (10 Marks)
A circuit should be designed to decrement a decimal number having a range from 0 until 7. The result of
‘the subtraction should be represented in sign-magnitude.
a) How many input and output variables are needed?
Solution:
We need 3 input variables and 4 output variables,
If the input will be also represented in sign-magnitude, then 4 input variables will be needed.
b) Construct the truth table for this cireuit
Solution:
+l--feJofee
=l-lefe)==JeJehed
+[=}-J4]-F>)-J 4-19]
=lelel=|-IeJeJelo]
al-l>]-J>)-)4/1¢]
) Use the sum-of products algorithm to find the Boolean expressions that correspond to the the truth
table.
Solution:
S = ABC
Ol = AB'C + ABC'+ ABC
02 = A'BC + AB'C'+ ABC
O3 = A'BIC' + A'BC'+ ABIC' + ABC!Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008
Exercise 7
Simplify the Boolean expressions using the Boolean algebra,
Please mention the applied rules.
T+0=2 Te
r+l=1
r+(yta)=(e+y)+2
aly +2)Say +02
(x+y) =a'y'
Distributivity
DeMorgan’s Law
a) The simplified expression consists of two gates.
(A+ B)*(A+C)
Solution:
(A+ B)*(A+C)= — Distributivity
A+BC
b) The simplified expression consists of three gates.
A+ Ale B+ Ale Ble C+ Ale BIeC'e D
Solution:
A+AMHB+ A's BAC + Ale Be C'4D
(AFA) *(A4 B)4 Ale Ble C+ A's Be Cle D =
1(A+ B)+ A's Ble C+ Als Be Cl
PagoT
(6 Marks)
let+ye=(@+y)e+2)]
fete"
1
(A+ B)xl+ A's B'eC + Ae B'eC'sD= — [Commutativity]
ALB+A'B'eC+AeB'eCl'sD= [evl=a]
A+B+BIAC +A Bis Cle [Commutativity]
A+(B+B')*(B+A'C)+ A's Be C's [e+ yz=(e+ ye +2)]
At14(B+A'C)+ A's Bia Cl [e+a'=1]
A+(BH+AIC) #1444 B'xC'+D= — [Commutativity]
AF B+ACHA SB aC [re1=a]
A+AC+B+AlB'eC'+D= — [Commutativity]
(AFA)*(AF+C)4B+ ABC [et yz=(@+We+2)]
1s(A+C)4B+A'eB'sC'eD= [x +2'=1]
(AF C)*14 BHA BI aCe [Commutativity]
ALC+B+A'eB'eC'eD= — [2¥l=al
A+C+B+BsC! [Commutativity]
ALC+(B+B)4(B+ACD)= [et yz=(e+y)e+2)]
A+C414(B+A'C'D) [e+a'=1]
A+C+(B+A'C'D)*1= — [Commutativity]
A+C4+B4A4C [rxt=a]
CHB+A+AC'D= — [Commutativity]
CHB+(A+ A) *(AFC'D)
CHB+14(A+C'D)
(e+ yet]Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008
C+B+(A+CD)x1=
C+B+A4C!
B+A+C+CD=
B+At(C+C)a(C4+D
B+Atie(C+D)=
B+A+(C+D)*
B+A+C4D
Page 8
[Commutativity]
[e+1=2]
[Commutativity]
[e+yz=(e+u)(@+2)]
[e+a'=1]
[Commutativity]
[rv1=a]Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 9
Exercise 8 (5 Marks)
Prove the following
(Ax(B'sC'+ B+0))
'+(B+C)*(B'+C')
Hint: There are different. ways to prove that two Boolean expressions are equivalent. In this case, it
‘would be easier to use the Boolean algebra rules given in Exercise 7.
Solution:
(Ax(B'eC'+ Be C))!'=
A'+ (Bix C!4 BC)
A'+((B'C!)'* (BC)!
Al +((B" +0") *(B'+C"
A'+((B+C)*(B'+C')
A'4(B+C)*(BI+C")Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 10
Exercise 9 (10 Marks)
Write an algorithm that takes as a parameter a list containing a sequence of integers and outputs a list
with its mirror image. The mirror image of a sequence contains the original sequence in reversed order
followed by the original sequence. For example, if the original sequence is:
1,8, 15, 7,2
then the algorithm should create a list of the form
2,7, 15, 8, 1, 1, 8, 15, 7, 2
Solution:
get n
get AL,A2,.06 An
set iton
set jtol
while (i>=1)
{
set Bj to Ai
set Bj+n to An-itt
set itoi-t
set j to jtt
+
set jtol
while (j<-2n)
{
print Bj
set j to j+t
+Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 1
Exercise 10 (10 Marks)
‘The following algorithm calculates the binary representation of given number x and represent it in n bits,
get x
get n
setiton-1
while (i >= 0) do
{
if (2) <0
‘then
set Bi to 0
else
set Bi to
set x to x-27i
endif
set ito i-t
+
setitoitd
while(i = 0) do
\- 1 operation --> executed once
= 1 operation --> executed(n+1) times
{
if (24) <0 ~ 4 operation ---> executed n times
‘then
set Bi to 0
else
set Bi to1 - 1 operation --> executed n times
set x to x27 1 operation --> executed n times
endif
set itoi-t - 4 operation --> executed n times
}
setitoitd
1 operation --> executed once
while(i executed (n+1) times
print Bi
setitoitd -.
1 operation --> executed n times
.- 1 operation --> executed n times
+
‘Total number of executed operations: = 81 +4
b) Give the value of «50 that the algorithm will execute the least number of operations. Justify your
answer,
Solution:
Forx = 0, the algorithm will execute the least number of operations, because in each execution of
the loop the then part of the if-statement consisting of only one statement will be executed.Introduetion to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 12
) Determine the order of magnitude of the algorithm.
Solution:
O(n)Introduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 13
Extra PageIntroduetion to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 14
Extra PageIntroduction to Computer Science, FinalTerm Exam, 14. Feb 2008 Page 15
Extra Page