UNIVERSITY EXAMINATIONS: 2013/2014
ORDINARY EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY & BUSINESS INFORMATION
TECHNOLOGY
BIT 2102 BIT 3101A BBIT 106 DATA STRUCTURES AND
ALGORITHMS
DATE: AUGUST, 2014 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO
QUESTION ONE [30 MARKS]
a) An algorithm is defined as sequence of instructions for solving a given problem. A
good algorithm must meet a number of properties. Discuss four of those properties.
[6 Marks]
b) A stack is an ordered collection of data elements in which access is possible only at
one end called top of the stack. In this regard explain the output of the following
sequence of operations.
1. [Link](10);
2. [Link](4);
3. [Link](8);
4. [Link]();
5. [Link](6);
6. [Link](5);
7. [Link]();
8. [Link](13);
[5 Marks]
c) Design an algorithm to calculate sum of two by two matrices A and B. [8 Marks]
d) Design an algorithm to add a new node at the mid position of a linked list. [5 Marks]
e) A heap is a binary tree which is complete and satisfies the heap order property. In this
regard, differentiate between completeness and order property of a heap. [6 Marks]
1
QUESTION TWO [20 MARKS]
i). A graph data structure is a collection of nodes called vertices, and the connections
between them, called edges. Graphs can be represented using adjacency matrix and/or
adjacency lists. Use the adjacency matrix below to construct a graph.
A B C D E
A 0 1 1 1 0
B 1 0 1 1 0
C 1 0 0 1 1
D 1 1 0 0 0
E 0 0 1 1 0
[8 Marks]
ii). Discuss the following algorithms for traversing a graph:
i). Breadth first search [6 Marks]
ii). Depth first search [6 Marks]
QUESTION THREE [20 MARKS]
i). You are given the following elements stored in an array. Discuss how you can use
bubble sort to arrange these elements in an ascending order.
12 6 18 33 1 3 14 13 32 9
[6 Marks]
ii). Design an algorithm that locates the integer in index 6 in the array below.
Index 0 1 2 3 4 5 6 7 8
Element 12 18 9 11 32 14 13 19 7
[8 Marks]
iii). Design an algorithm that calculates and displays the factorial of an integer value.
[6 Marks]
QUESTION FOUR [20 MARKS]
i). A linked list is a linear data structure which consists of collection of nodes with each
node in the list consisting of two basic components. Describe these two components.
[4 Marks]
ii). With help of a code snippet, describe the following types of linked lists:
i). Singly linked list. [4 Marks]
ii). Doubly linked list [4 Marks]
iii). Describe the procedure for constructing a binary search tree (BST).
[8 Marks]
2
QUESTION FIVE [20 MARKS]
a) Algorithms can be classified into various categories based on the design techniques.
Algorithms that use similar problem–solving approach can be grouped into the same
category. In view of this, discuss the following algorithms.
i). Greedy algorithms [3 Marks]
ii). Backtracking algorithms [3 Marks]
iii). Branch and bound algorithms [3 Marks]
iv). Genetic algorithms [3 Marks]
b) Construct a hash table to store the integers 13, 2, 34, 56, 77, 21, 33, 82 using a
suitable hash function that adequately resolves any conflict and ensures that all
values are stored in the hash table. [8 Marks]