Computer Science Final Exam (2012)
Computer Science Final Exam (2012)
Bar Code
5) Write your solutions in the spa
e provided. If you need more spa
e, write on the ba
k of the sheet
ontaining the problem or on the three extra sheets and make an arrow indi
ating that. S
rat
h
sheets will not be graded unless an arrow on the problem page indi
ates that the
solution extends to the s
rat
h sheets.
6) When you are told that time is up, stop working on the test.
Good Lu k!
Complete the following algorithm and make sure that the algorithm must return the output a
ording
to the above sample.
set hiddenNumber to 56
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 2
This list ontains four 12's and three 933's. The sorted form of this list is
Write an algorithm that will take a list of this form and returns a list
ontaining the same set of values
in sorted order.
The algorithm should run in linear time; O(n) where n is the number of elements in the list.
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 3
get n
get A1, ..., An
set k to 1
set i to 2
while (i <= n )
{ if (Ak <> Ai)
then
print Ak
endif
set i to i + 1
set k to k + 1
}
set i to i - 2
if (Ak <> Ai)
then print Ak
endif
1 1 1 2 3 4 4 5 6
b) What is the output of the algorithm for any sorted list of the form A1, ..., An?
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 4
) Find the total number of exe
uted operations in worse
ase. State expli
itly the worse
ase. Show
your workout.
get n
get A1, ..., An
set k to 1 -------> 1 opeatione exe
uted on
e
set i to 2 ------->
while (i <= n) ------->
{ if (Ak <> Ai)------->
then
print Ak ------->
endif
set i to i + 1 ----->
set k to k + 1 ----->
}
set i to i - 2 -------->
if (Ak <> Ai) -------->
then print Ak -------->
endif
a) Convert the binary number 1011012 whi
h is in two's
omplement to a de
imal number (base 10).
Show your workout.
b) Convert the de imal number 23610 to a number in base 8. Show your workout.
) Convert the o
tal number 654328 to a hexade
imal number. Show your workout.
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 6
) Show how the binary number will be stored in the 16 bits below.
(−19)10 − (18)10
using 2's
omplement notation. Give the result of the subtra
tion in de
imal. Show your workout, i.e. all
steps performed.
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 8
A B X Y Z
0 0 0 0 0
0 1 0 0 1
1 0 0 1 1
1 1 1 1 1
a) Use the sum-of-produ
ts algorithm to nd the Boolean expressions that des
ribe the output of the
truth table.
) Draw the Boolean
ir
uit. Note that ea
h gate
an have only two inputs.
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 9
a) Using fulladder ir uits, design a ir uit that adds two 4-bit numbers A and B .
b) Design a
ir
uit that will subtra
t two 4-bit numbers A and B from ea
h other (A − B ) where the
numbers are in 1's
omplement. You are only allowed to use the
ir
uit you designed in part a) and
negation gates.
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 10
A′ (A + B) + (B + AA)(A + B ′ )
Simplify the Boolean expressions using the Boolean algebra. Please mention the applied rules.
x+0=x x∗1=x
x+1=1 x∗0=0
x+x=x x∗x=x
x + x′ = 1 x ∗ x′ = 0
(x′ )′ = x
x+y =y+x xy = yx Commutativity
x + (y + z) = (x + y) + z x(yz) = (xy)z Asso
iativity
x(y + z) = xy + xz x + yz = (x + y)(x + z) Distributivity
(x + y)′ = x′ y ′ (xy)′ = x′ + y ′ DeMorgan's Law
Hint: The
ir
uit of the simplied expression
onsists of only one gate.
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 11
Extra Page
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 12
Extra Page
Introdu
tion to Computer S
ien
e, Final Exam, January 24, 2012 Page 13
Extra Page