Data Structures
Data Structures
'
REGULAR
INSTRUCTIONS:
ANSWER QUESTION ONE AND ANY OTHER TWO QUESTIONS
Question 1 (30marks)
a) Define the term algorithm (2 Marks)
V f;,-.'l-+P"i 1
b) Outline four characteristics of a good algorithm. v "' ~ ~r i.... ~ 4 Marks) P~.I'\ ?~1'
v ~~ ·t... t tl""'i 1
c~ ·~
c) Explain the function of the following ADT primitives. Write the re levant syntax. ~ d~-:J
i) Enqueue ( ) (2 Marks)
ii) Push0 (2 Marks)
iii) IndexOf () (2 ~v1arks)
e) A queue is implemented using ADT list to presents its items. Discuss the efficiency
of the queue insertion and deletion operations when the ADT list Implementation
IS:
i) Array based.
ii) Pointer based. (6 Marks)
Question 2 (20marlcs)
a) Using examples differentiate between a binary tree and general tree. (4 Marks)
I
b) Write a two dimensional array to explain the concept of row major order.
- I
(6 Marks)
Question 3 (20marks)
a) Give three reasons why you woul d choose~ list over array. (3 Marks)
b) Name and explain th ree inpu t cases and the effect on running time of an
algorithm. (3 Marks)
vr
c) D 'b
escn e th e concept and motivation of circular QUEUE. Use illustration.
(S Marks)
11
d) '. terms of computational complexity, using big o, Explain the cost of:
.') lnserting element at the end of array list. (3 Marks)
II) Inserting element at end linked list (3 Marks)
e) Write down the algorithms for inserting a new element into stack. (3 Marks)
~ -Question 4 (20marks)
a) Define the term "Algorithm analysis'. Explain two important quantitative metrics
of interest in algorithm analysis. (4 Marks)
b) Sort the array given below using INSERTION sort algorithm. (6 Marks)
1 1 1 I
d) Using illustrative diagram, show how a new element is added in-between other
elements in linked list (4 Marks)
Question 5 (20marks)
a) Explain two data types used to Implement ADTs. (4 Marks)
,v 8 ~
v ~~
b) Perform Pre-Order, In-order and Post-Ordertraversal on the following tree.
(6 Marks)
Paper One
l
-p ( f ~~J
,._ {''1 f
~~' ~~ ~~~