0% found this document useful (0 votes)
32 views14 pages

Computer Science Final Exam (2012)

The document is an exam for an introduction to computer science course consisting of 9 exercises worth a total of 90 marks. The exam tests students on algorithms, data structures, binary arithmetic, Boolean algebra, and basic circuit design. It provides instructions, problems, and space for students to write out and show their work for solving each problem.

Uploaded by

Chantal Ramez
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)
32 views14 pages

Computer Science Final Exam (2012)

The document is an exam for an introduction to computer science course consisting of 9 exercises worth a total of 90 marks. The exam tests students on algorithms, data structures, binary arithmetic, Boolean algebra, and basic circuit design. It provides instructions, problems, and space for students to write out and show their work for solving each problem.

Uploaded by

Chantal Ramez
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/ 14

Page 0

German University in Cairo January 24, 2012


Fa ulty of Media Engineering and Te hnology
Prof. Dr. Slim Abdennadher
Dr. Fatma Meawad

Introdu tion to Computer S ien e, Winter Term


2011-2012
Final Exam

Bar Code

Instru tions: Read arefully before pro eeding.

1) Duration of the exam: 3 hours (180 minutes).


2) (Non-programmable) Cal ulators are allowed.
3) No books or other aids are permitted for this test.
4) This exam booklet ontains 14 pages, in luding this one. Three extra sheets of s rat h paper are
atta hed and have to be kept atta hed. Note that if one or more pages are missing, you will
lose their points. Thus, you must he k that your exam booklet is omplete.

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!

Don't write anything below ;-)


P
Exer ise 1 2 3 4 5 6 7 8 9
Possible Marks 10 15 14 6 8 6 14 10 7 90
Final Marks
Introdu tion to Computer S ien e, Final Exam, January 24, 2012 Page 1

Exer ise 1 (10 Marks)


Write an algorithm that plays a guessing game with numbers. The goal is for the user to guess a randomly
sele ted number between 1 and 100 as qui kly as possible. The algorithm will inform the user whether
the hidden number is higher or lower than the urrent guess. You an assume that the user will always
enter integers, but you must verify that the integers entered are between 1 and 100.
The following is a sample run of the program:

I'm thinking of a number between 1 and 100.


Enter guess: 50
Number is higher than 50
Enter guess: 588
Invalid, try again: 75
Number is lower than 75
Enter guess: 62
Number is lower than 62
Enter guess: 56
You guessed it in 4 tries!

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

Exer ise 2 (15 Marks)


In this question you are asked to reate a sorting algorithm for lists of integers with a very parti ular
property.
Suppose we know that the list to be sorted ontains at most two distin t integer values, ea h repeated
many times. For example the list might be

[12, 12, 933, 933, 12, 933, 12℄

This list ontains four 12's and three 933's. The sorted form of this list is

[12, 12, 12, 12, 933, 933, 933℄

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

Exer ise 3 (5+3+5+1=14 Marks)


Given the following algorithm

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

a) What is the output of the algorithm for the following list:

1 1 1 2 3 4 4 5 6

Use a tra ing table to tra e the rst while loop.

Output of the algorithm:

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

Total number of operations:

d) Determine the order of magnitude of the algorithm.


Introdu tion to Computer S ien e, Final Exam, January 24, 2012 Page 5

Exer ise 4 (2+2+2=6 Marks)

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

Exer ise 5 (3+2+3=8 Marks)


We would like to store the oating-point number −19.55 in a omputer that uses 16 bits to represent real
numbers. (10 for the mantissa and 6 for the exponent, both in luding the sign bit). Show your work as
indi ated below.

a) Show the binary representation of the de imal number −19.55.

b) Show the binary number in normalized s ienti notation.

) Show how the binary number will be stored in the 16 bits below.

Sign of Mantissa Sign of Exponent


mantissa exponent
1 bit 9 bits 1 bit 5 bits
Introdu tion to Computer S ien e, Final Exam, January 24, 2012 Page 7

Exer ise 6 (6 Marks)


Assume that our omputer stores de imal numbers using 6 bits. Perform the subtra tion

(−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

Exer ise 7 (5+4+5=14 Marks)


Given the following truth table, where A, B are the input variables and X, Y, and Z are the output
variables.

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.

b) What is the fun tionality of the ir uit?

) 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

Exer ise 8 (6+4=10 Marks)

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

Exer ise 9 (7 Marks)


Given the following Boolean expression

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

You might also like