Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

AIDM313 · DATA MODELS AND ALGORITHMS

FINAL EXAMINATION

Faculty : Information and Communications Technology

Date/Day : 20th December 2018


Duration : 3 hours

INFORMATION FOR CANDIDATE

1. This examination is worth 40% of the overall semester assessment.


2. The total number of marks available for this examination is 80.
3. This examination paper contains THREE (3) sections in FIVE (5)
printed pages including the cover page.

INSTRUCTIONS TO CANDIDATE
1. Answer ALL questions in Section A, B and C
2. Write all your answers in the answer booklet provided.
3. If you make a mistake please put a single diagonal line through the
section you wish to be ignored by the examiner.
4. Return all examination papers and scripts upon completion of the
examination including any workings.
AIDM313 · DATA MODELS & ALGORITHMS
AUG – DEC 2018 FINAL EXAMINATION

SECTION A: [Answer all questions] [Total: 16 Marks]

1. Define the following terms (10)


(i) Binary Search Tree
(ii) Algorithm
(iii) Heap Sort
(iv) Time complexity
(v) Harsh Table

2. If you look up at a contact on your phone: A data structure is used to


look up a phone number in your contact list based on partial
information even before you finish dialling/typing. This isn’t easy; your
phone may contain information about a lot of people everyone you
have ever contacted via phone or email and your phone doesn’t have a
very fast processor or a lot of memory. Give and explain two situations
in which you can apply a tree to store information in real life situation.(6

Limkokwing University of Creative Technology Page 5 of 5


Faculty of Information and Communications Technology
AIDM313 · DATA MODELS & ALGORITHMS
AUG – DEC 2018 FINAL EXAMINATION

SECTION B: [Answer all questions] [Total: 40 Marks]

1.
Based on the array-based implementation of class Stack discussed in the
class with the following data members:
Class Stack{
// public function declarations here
private:
static const int Size = 10;
int Array[Size];
int top; /* array index of top element of the stack; is -1 when stack is empty */
};
Write a member function void Stack::push(int newItem)
throw(StackException) which pushes newItem onto the stack and
throws an exception if the stack is full. (5)

Write a member function template bool Stack::operator== (const


Stack & theStack)const

which checks to see if two stacks are equal that is to say they have
the same number of items, and all these items, from the top to the
bottom, are equal. (8)

A stack of integers aStack has the following private data:

top: 4
items: 8 0 0 4 7 10 -34323 0 67823 -78999

What is the output of the following code? (2)


int x;
while (!aStack.isEmpty()){
aStack.pop(x);
cout << x << " ";
}

Limkokwing University of Creative Technology Page 5 of 5


Faculty of Information and Communications Technology
AIDM313 · DATA MODELS & ALGORITHMS
AUG – DEC 2018 FINAL EXAMINATION

2 . A stack bStack contains the following items


7
8
3
14
5
What is the output to the screen of the following code? (2)
int x;

while (!bStack.isEmpty()){
bStack.pop(x);
if (x>0 && !bStack.isEmpty())
bStack.pop();
cout << x << endl;
}

3 . a. Consider a stack of integers cStack. Using only the stack


methods isEmpty(), pop(), pop(int x), and push(int y), write code (in
C++ or pseudocode) which pops all the elements of cStack and
returns the sum of all these elements. (5)

b. How would the code above have to be modified if the stack


cStack is to be left unchanged after the sum is found? (In your
solution, still only use the stack public methods listed above.) (8)

3. The diagram below shows a binary tree.


(a) Show how the results in the max heap can be represented using array
(4)

Limkokwing University of Creative Technology Page 5 of 5


Faculty of Information and Communications Technology
AIDM313 · DATA MODELS & ALGORITHMS
AUG – DEC 2018 FINAL EXAMINATION

4. Describe in your own words the idea of the Insertion sort algorithm for
arrays with an example. (6)

Limkokwing University of Creative Technology Page 5 of 5


Faculty of Information and Communications Technology
AIDM313 · DATA MODELS & ALGORITHMS
AUG – DEC 2018 FINAL EXAMINATION

SECTION C: [Answer all questions] [Total: 24 Marks]

Question 1 to 3 worth 15 marks

4. Insert the data below into a binary search tree


26 20 25 24 36 15 13 9 8 10 23 14 (4)
(a) Delete the node with key 15 and draw the resulting Binary Search
Tree (2)
(b) From the resulting Tree print the data using post tree traversal (3)

Limkokwing University of Creative Technology Page 5 of 5


Faculty of Information and Communications Technology

You might also like