DIPLOMA IN INFORMATION TECHNOLOGY
DECEMBER 2014 EXAMINATION
DATA STRUCTURE AND ALGORITHM
SUBJECT CODE : TIME ALLOWED: THREE (3) HOURS
TOTAL NUMBER OF PAGES: 4
INSTRUCTIONS TO CANDIDATE:
1. Answer FIVE (5) questions out of SIX (6) questions.
2. All questions carry equal marks.
3. ALL answer should be written in the answer sheets provided.
4. Submit both the question and answer papers.
Page 1 of 4
QUESTION 1
a) Stack data structure is one of the most common data structures used in all aspects of
computing. Define and explain in detail stack data structure. Use diagrams and proper
examples to illustrate your points.
(10 marks)
b)
Assume the stack can only support a maximum of 10 elements. Given the following
operations, draw the stack after each operation complete with its associated variables:
i) Perform PUSH operations on 1, 2 and 3.
ii) Two POP operations are performed.
iii) Perform PUSH operations on 9, 8, and 7.
iv) Three POP operations are performed.
(10 marks)
(Total: 20 marks)
QUESTION 2
a) Write the string for the following type of traversals based on the given tree:
i) Pre-order
ii) In-order
iii) Post-order
(12 marks)
b) Construct a binary search tree based on the following:
AC, CD, DA, AC, BA, CB, BD, DC
(8 marks)
Page 2 of 4
(Total : 20 marks)
QUESTION 3
Sort the following countries into ascending order:
Australia, England, Malaysia, Argentina, Portugal, Brazil, Kenya, Canada,
Austria
a) Selection sort
b) Quick sort
c) Insertion sort
d) Merge sort
(Total : 20 marks)
QUESTION 4
a) Write the pseudo code to traverse a list of array and determine the count for numbers
that are multiples of 3.
(10 marks)
b) Write the pseudo code to traverse a list of array and determine the count for numbers
that can be wholly divided by ten and the count for numbers that cannot be wholly
divided by ten.
(10 marks)
(Total: 20 marks)
QUESTION 5
Write pseudo code for both recursive and iterative versions of summation function for
number in the range of 1 to a given positive integer.
(Total : 20 marks)
Page 3 of 4
QUESTION 6
Link list is an ordered collection of data in which each element contains the location of the
next element. Each element is referred to as a node.
(a) Briefly describe TWO (2) fields that are contained in a node. (4 marks)
(b) Draw a tracing diagram based on the algorithm and sample data below.
(i)
void List::addNode ( ListElementType newItem )
{
Link p;
p = new Node;
p->item = newItem;
p ->next = current->next;
current ->next = p;
current = p;
}
Initial data : 2,4,6,5,9,12,10
Data need to be inserted at the end of the list : 15
(8 marks)
(ii)
void List :: deleteNode(ListElementType oldItem)
{
Link temp;
bool found = false;
if ( isEmpty() ) cout << "Not exist!!\n";
current = head;
while (current->next != NULL) {
temp = current->next;
if (temp->item == oldItem) {
current->next = temp->next;
delete temp;
found = true;
break;
}
else Advance();
}
if ( !found ) cout << This item not exist.\n;
}
Data : 2,4,6,5,9,12,10,15
Delete 15 from the list (8 marks)
(Total: 20 marks)
Page 4 of 4
- END OF PAPER -
Page 5 of 4