Anda di halaman 1dari 22
FAKULTI SAINS DAN TEKNOLOGI MAKLUMAT FINAL EXAMINATION SESSION I, ACADEMIC YEAR 2013/2014 BTCD 3123 DATA STUCTURE

FAKULTI SAINS DAN TEKNOLOGI MAKLUMAT

FINAL EXAMINATION SESSION I, ACADEMIC YEAR 2013/2014

BTCD 3123 DATA STUCTURE

INSTRUCTIONS TO CANDIDATES:

  • 1. The time allotted for this paper is 2 HOURS 30 MINUTES.

  • 2. This question paper consists of TWO sections: SECTION A : 5 Structure Questions. SECTION B : 3 Structure Questions.

  • 3. Answer ALL questions in Section A and any TWO questions in Section B in the question paper.

  • 4. This question paper requires:

    • i) The Examination Paper Cover.

ii) An Additional Answer Sheet.

  • 5. Complete the details below:

    • i) Matric Number : ________________________________________ ii) Lecturer : ________________________________________

FAKULTI SAINS DAN TEKNOLOGI MAKLUMAT FINAL EXAMINATION SESSION I, ACADEMIC YEAR 2013/2014 BTCD 3123 DATA STUCTURE

THIS QUESTION PAPER CONSISTS OF 22 PRINTED PAGES. DO NOT OPEN UNTIL YOU ARE TOLD TO DO SO.

SULIT

BTCD 3123

SECTION A

Marks: 60

SEPTEMBER 2013

Answer ALL questions in the spaces provided.

Question 1

Given a recursive function as below :

int Recursive(int n) {

if (n == 0)

return 1;

if (n == 1)

return 2;

else return (Recursive (n-1) * Recursive (n – 2));

}

  • a. What is the output to be produced after the statement Recursive (int 5) implemented? Draw a diagram recursion tree. Answer :

(10 marks)

BTCD 3123

SEPTEMBER 2013

BTCD 3123

SEPTEMBER 2013

Question 2

 

a.

Build

a

heap tree based on array of integer , M

as shown as below.

 

int

M[7] = [14, 2, 19, 1, 5, 15, 30]

 

(4 marks)

Answer:

BTCD 3123

SEPTEMBER 2013

  • b. Based on the answer in question2(a), sort the data elements by showing the following steps. i. Re-Heap. Answer :

(3 marks)

BTCD 3123

SEPTEMBER 2013

ii.

HeapSort.

 

(8 marks)

Answer :

BTCD 3123

SEPTEMBER 2013

BTCD 3123

Question 3

SEPTEMBER 2013

  • a. Change the infix expression below to prefix expression by using the stack diagram. ( ( R - S ) / ( K – L ) + V ) * U – T Answer:

(7 marks)

BTCD 3123

SEPTEMBER 2013

BTCD 3123

SEPTEMBER 2013

  • b. Evaluate the expression, algorithm. Answer :

F =

6 + 70 / 33 + 4 – 5 * 15 / 3

by using stack

(9 marks)

BTCD 3123

SEPTEMBER 2013

BTCD 3123

Question 4

SEPTEMBER 2013

Figure 1 below shows the tree of character node.

BTCD 3123 Question 4 SEPTEMBER 2013 Figure 1 below shows the tree of character node. Figure

Figure 1: Tree

Based on the Figure 1, state

  • a. the root.

 

(0.5 mark)

Answer:

  • b. the height of tree.

 

(1 mark)

Answer:

  • c. the siblings.

 

(1.5 marks)

Answer:

BTCD 3123

  • d. the internal nodes.

SEPTEMBER 2013

 

(1.5 marks)

Answer:

  • e. the ancestors of J.

 

(1.5 marks)

Answer:

  • f. the leaves.

 

(3 marks)

Answer:

BTCD 3123

Question 5

SEPTEMBER 2013

  • a. Draw a hash table for the following unique keys by using the mod-division method, where the size of array is 50.

i.

2000

ii.

2010

iii.

2020

iv.

2030

v.

2040

vi.

2050

vii.

2060

viii.

2070

ix.

2080

x.

2090

xi.

2100

xii.

2110

 

(6.5 marks)

Answer:

BTCD 3123

SEPTEMBER 2013

  • b. Based on the hash table in question 5(a), rewrite the whole hash table by using linear probing method for the collision solution. Answer:

(3.5 marks)

BTCD 3123

SECTION B

Marks: 20

SEPTEMBER 2013

Answer any TWO questions in the spaces provided.

Question 1

Consider the following sequence of stack operations:

push(d), push(h), pop(), push(f), push(s), pop(), pop(), push(m).

  • a. Assume the stack is initially empty, what is the sequence of popped values, and what is the final state of the stack? Illustrate and identify which end is the top of the stack.

Answer :

(5 marks)

BTCD 3123

SEPTEMBER 2013

  • b. Suppose you were to replace the push and pop operations with enqueue and dequeue respectively. What would be the sequence of dequeued values, and what would be the final state of the queue? Illustrate and identify which end is the front of the queue. Answer:

(5 marks)

BTCD 3123

Question 2

SEPTEMBER 2013

  • a. What is the output of the following program?

public class ExFinal {

public static void main(String[] arg) {

int list[] = {5, 10, 15, 20, 25}; StackClass s1 = new StackClass(); StackClass s2 = new StackClass(); for (int i =0; i<5; i++) s1.push(new IntElement(list[i]));

mystery(s1,s2);

while(!s2.isEmptyStack())

{

 

System.out.print(s2.top() + " ");

s2.pop();

}

System.out.print();

}

 

public static void mystery(StackClass s, StackClass t)

{

 

int num; IntElement temp; while (!s.isEmptyStack()) {

temp = (IntElement) s.top():

num = temp.getNum(); t.push(new IntElement(2 * num)); s.pop();

}

}

}

(10 marks)

BTCD 3123

Answer:

SEPTEMBER 2013

BTCD 3123

Question 3

Consider the polynomial:

5y 2

- 3y

+ 2

SEPTEMBER 2013

  • a. Write the polynomial as an expression tree that obeys the usual ordering of operations. Answer:

(4 marks)

BTCD 3123

SEPTEMBER 2013

  • b. Based on expression tree above, write the polynomial as postfix and prefix expressions. Answer:

(6 marks)

BTCD 3123

SEPTEMBER 2013

----------------- END OF QUESTION PAPER ---------------