0% found this document useful (0 votes)
25 views3 pages

DCIT204 Past Questions

Uploaded by

Schoolboy LT
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)
25 views3 pages

DCIT204 Past Questions

Uploaded by

Schoolboy LT
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/ 3

1m

B.
UNIVERSITY OF GHANA
(A \I I'i ghts reserved)

BACHELOR OF SCIENCE IN ENGINEERING


RESIT EXAMINATIONS: JANUARY 2017
DEPARTMENT OF COMPUTER ENGINEERING
CPEN 204: DATA STRUCTURES AND ALGORITHMS (3 Credits)

INSTRUCTION: .
ANSWER ALL QUESTIONS FROM SECTIONS A AND B.

TIME ALLOWED: THREE (3) HOURS

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]

. c) DELETE (D,x) [2 marks]


d) MINIMUM (D) [2 '!"ark5j

E X A MIN E R: W I A F E 0 W U S U - II A N A HEN E (PHD) Page 1 of3


e) SUCCESSOR (D,x) .... '" 12 marksj
f) PREDECESSOR (D,x) {2 marksj

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]
; ,

..

E X A 1\1 I N E R: W I A F E 0 W U S U - BAN A HEN E (PHD) Page 2 of3

; ,

.' .
SECTIONB
ANSWER ALL QUESTIONS IN THIS SECTION.

4. Briefly describe each of the following:


a. Linear searc/1 that searches for the position of an element in the list
{I ,2,3,4,5,6,7,8,9, 10, 11,12,13,14,15,16, 17, 18, 19} . [10 marks]
b. Binary search, given list A = [1,3 ,5,7, 11,13, 17, 21,23, 31 ,33,37], show how the
algorithms will locate the element 19 in the list. [10 marks]
,- "~ I '

, '. c,Divide-and-conquer strategy as a problem solving technique. [5 marks]


5. I ':I "

" .... '.' • 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 '.

E X A MI N E R:, 'W J AF E 0 W U S U - BAN A HE N E (PHD) Page 3, of3 I.'


-,
I '

"1
. I., \ .
..
, ,
. ~ .
" ,
.. ' .,.
-. '

You might also like