DCIT204 Past Questions
DCIT204 Past Questions
B.
UNIVERSITY OF GHANA
(A \I I'i ghts reserved)
INSTRUCTION: .
ANSWER ALL QUESTIONS FROM SECTIONS A AND B.
SECTION A
. ANSWER ALL QUESTIONS IN THIS SECTION.
1. Given the following structure definitions and declarations in Figure 1, find error(s), if
any, in statements a to d, and correct them.
struct Xxx
{
int aa; double *bb; char *cc[30]
};
struct Yyy
{
int *dd; double ee;
}; struct Xxx mm. nn; struct Yyy pp, qq;
Figure I
a. mm =pp; [2 marks]
h. strcpy(nn.cc, "Trial "); [2 marks]
c. Xxx.aa = ]3; [2 marks]
d. Yyy.ee = 76.9 ;' [2 marks]
2. Indicate the results of the following operations when performed on a dynamic set D.
Assume that a key value k is an element of 0 and a pointer x points to an element in D.
a) SEARCH (D, k) [2 marks]
b) INSERT (D, x) [2 .marks]
3. Figure 1 shows a queue of at most 12 elements implemented using array Q [1. .. 13} with
head [QJ =7.
1 2 3 4 5 6 7 8 9 10 11 12 13
Q
Figure 1 I
a. lIIustrate the c,~nfiguration of the queue after each of the 'following .0perations has '
been performed successively on it: ENQUEUE (Q, 3); ENQUEUE (Q, 1),
ENQUEUE (Q, 4), D EQUEUE (Q), ENQUEUE (Q, 8), and DEQUEUE (Q) .
[6 marks]
b. Find the va lue,of tail [Q] after each of the operations in 3.61) has b~en performed.
[3 marks]
I
c. Using diagrams, show how a doubly linked list L can be used to represent the
dynamic set {I, 4, 9, 16 }. [5 marks]
d . Show the configuration of L after performing the following operation:
,
LIST-INSERT (1-, x); where key[x} =25. [2 marks]
e . . Using diagrams describe a sentinel and show how this sentinel can ,turn the
doubly linked list L in question 3.c) into a circular, doubly linked list with a
I
sentinel. [4 marks]
; ,
..
; ,
.' .
SECTIONB
ANSWER ALL QUESTIONS IN THIS SECTION.
" .... '.' • a .. Explain the concept of computational complexity of algorithms. [3 marks]
.. :~ :!. : ; "I'·, ~ , • " . " . ,
:.:::~: ;!t ~~.: ;'r ··l ~:~:b ..::S~,?~ ~?r f;~g-O notation can be used to estimate the follo,:"in g: ',; [~2 m?~! ;1 /::; '.' :"'; I
~;<.l ::~ ~" ~'. '. ; " ".......... :/ '.', A 'c6nstant jimction .. , 1 I . '. '.. ::', :.' .: . ::- ,:,:.!; •.,. ,',
• : ~~ ", ,, ~ :r~' .:J..~:.(; \' ~..__ ;:. . _ .' . : ~,,:.J \ ....;."
";: i.,' ~ :/' "j, ii. · ApQlynomialj (x) = Q ,,,xn + an- ix n- \ + . . +a\x + QO, '•
.,
,. ., u· ;t' where,a o, 0\, . .. , an- I, a" are real numbers.
iii. F(N)=1 + 2 + 3 + .. .... ,.. ...... N where N is a positive integer.
. '.' iv. F(N) = N! where N! is the jactorial oj a positive.integer and F(O) = 1.
. :~ y. '. . Ji'(tIJ,~, log(N!) where N is a positive integer: . , ., :.: ~ ,'. '. ).~I~:;:'· " ': I
.... _; '~i. '/ ~ The :godes shown below: '·!' ; . ! . j.o' • • •." '" ~.<.', ')':-.,:
t ~ i '} •
\
"I.,
. ~. ~; ~ .' I. • i~t i,i,m,n;
,~~ ., ,I'" Jl!.r(i=:~;i<m;i++)
Jorlj=O;j<l1;j++)
printf("%d""%d",&i,&j);
I
t
I:::
.
.: :' r ,' .. f'1! ,", I', ...., '
t
.' r " .. ~ .... '" >- " • I. ,t ~ ~,'
ifn>~OO
# •
~ '} ::.... ~ I I' •
~'~: 6: .." 'McCarthy"91 'function' is defined using the rule r ... " ..
I '.~
.", '.' .;$ "', :. _: j .r- if n:S 100
. i .. I .. ' ,
" " for all positive integers'n. Write an interactive c++ program to implement a recursive
. algorithm 't hat determines M(n}. In your program use at least a recursive function
mcCprthy that accepts <;ls input at least one parameter (representing the value of n) and
~aJue of M(n). e~timate the time,
•
" , I
t .. ~.
. retuhls the -compu'teq
.. ' . ' ,., .. , ,: •. :
"
;. ;
Your program should •
'.
•
• •
in - .
'
..
" ' • • I .: ,I 4 .. _
• • I
'" .":, mill.iseeonds, that it takes the CPU to compute the value ofM(n}.: [20 marks]
., .r, ' ..' . .... ' •
.' . "
,4 '.
"1
. I., \ .
..
, ,
. ~ .
" ,
.. ' .,.
-. '