You are on page 1of 6

FACULTY OF ENGINEERING AND INFORMATION TECHNOLOGY

DIPLOMA IN INFORMATION TECHNOLOGY


MAY

2011
FINAL EXAMINATION

IT111
DATA STRUCTURES AND ALGORITHMS
DURATION:

3 HOURS

DATE:

TIME: 12.00PM 3.00PM

ADDITIONAL REQUIREMENT: NIL


INSTRUCTIONS TO CANDIDATE:
Answer ALL Questions.

DO NOT REMOVE THIS EXAMINATION QUESTION PAPER FROM THE


EXAMINATION HALL

Answer ALL questions.

IT111
Question 1

May 2011

Given below a list integers: 34, 125, 5, 19, 77, 263, 19, -2, 38
(a)

Sort the list of integers using Insertion Sort approach. Assume the numbers
are stored in a one-dimensional array. Show the contents of the array after
each loop of execution. Sort in ascending order.
(6 marks)

(b)

Sort the list of integers using the Quick sort approach. Use the first number
in the list as the pivot key. Show the sorting process as a simple recursive
tree. Sort in ascending order.
(6 marks)
(Total: 12 marks)

Question 2
You are given a general tree T as follows:
A
B

E
(a)

Convert the general tree T into a binary tree B(T).


(6 marks)

(b)
(c)

Represent the B (T) as a double-linked list.


(6 marks)
A binary tree can be traversed using an in-order, pre-order or post-order
methods. Each of the traversal method traverses the Root, Left and Right of
tree following a certain order. List the order of traversal for each of the
approaches.
(6 marks)
(Total: 18 marks)

IT111

May 2011

Question 3
You are given the following recursive function.
Function NICE (P)
Int A, B, C, P
BEGIN
IF P <= 0 THEN A 0
ELSE
BEGIN
B P MOD 10
C P DIV 10
A B * NICE( C)
END
Return (A)
END
Diagram 1.1
Note: The operator MOD returns the integer remainder of a division
The operator DIV returns the integer part of a division
(a)

Draw a recursive tree to show the tracing of the function above for P =5693.
(10 marks)

(b)

Determine the purpose of the function NICE.


(2 marks)

(c)

Re-write an iterative (non-recursive) version of the function NICE.


(8 marks)
(Total: 20 marks)

IT111

May 2011

Question 4
The adjacency set list for a graph is given as below
Vertex
1
2
3
4
5

Set
{2, 3, 4, 5}
{6}
{7}
{8}
{}
Diagram 1.2

(i)

Draw the graph using the list above.


(3 marks)

(ii)

Is the graph a connected graph? Explain your answer.


(3 marks)
(Total: 6 marks)

Question 5
Write a complete algorithm of a binary search algorithm. You may write using a
psuedocode version or choose any programming language that you know. Trace the
working of your algorithm for the following list of items:
2, 5, 8, 9, 12, 34, 59, 65
The target key is: 59
(Total : 14 marks)
Question 6
A circular queue of characters is stored in memory location 200 to 209 inclusive. At
the start, the queue is empty and both the pointers of the queue are set at location 200.
(a)

How many characters can be stored in the queue?

(b)

Explain how we know the queue is full?

(c)

Briefly explain why the queue is CIRCULAR?

(2 marks)
(6 marks)
(2 marks)
(Total: 10 marks)

IT111

May 2011

Question 7
A stack is stored in memory location 500 to 510 inclusive. Three pointers are used to
track the size and data positions in the stack. The description of the pointers are given
below:
Base Pointer (BP): Point to the base (first) location of the stack
Top Pointer (TP): Point to the last available location in the stack
Stack Pointer (SP): Point to the next available location in the stack
(i)

Using a simple diagram, show the positions of the three positions of


the stack when the stack is Empty and Full.
(4 marks)

(ii)

Show the contents of the stack after the execution of the following
program segment. Assume the stack is empty in the beginning. Show
the contents at each loop for the second FOR loop.
FOR count = 1 to 10
BEGIN
PUSH (count)
END
FOR count = 1 to 5
BEGIN
If count MOD 5 = 0 THEN
PUSH (count)
ELSE x POP()
END
Diagram 1.3
(6 marks)
(Total: 10 marks)

IT111

May 2011

Question 8
Assume you are given a linked list where each node in the list has .info and .next
fields. The .info field consist of a single character (Eg; A, B, G ,.). The .next
field is pointing to the next node. A head pointer is pointing to the front of the linked
list. A procedure REDUCE is written to carry out some work on the linked list. A
recursive version of the procedure is given below.
Line
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Statement
PROCEDURE REDUCE (head: pointer)
second: pointer
BEGIN
IF (head <> NULL) THEN
second = head*.next
IF (second <> NULL) THEN
IF (head*.info = second*.info)
head*.next = second*.next
REDUCE (head)
ELSE REDUCE (Head*.next)
END
END
END
END
Diagram 1.4

(i)

Explain briefly the statements in line 5, 7 and 8


(6 marks)
(ii)

If the linked list stores the characters listed below, what will be the
final result after executing the procedure above?
A, A, B, B, B, A, B, C, C, C, D, ,D, B
(4 marks)
(Total: 10 Marks)

END OF EXAMINATION QUESTION PAPER

You might also like