Você está na página 1de 10

FINAL EXAMINATION NOV 2010 SEMESTER EXAMINATION 2/2010/2011 ACADEMIC SESSION

SUBJECT SUBJECT CODE DURATION FACULTY PROGRAMME LECTURER GROUP

: : : : : : :

ANALYSIS AND DESIGN OF ALGORITHM ICS 2213 3 HOURS INDUSTRIAL INFORMATION TECHNOLOGY BACHELOR OF COMPUTER SCIENCE (HONS) MR MOHAMMAD ASHRI ABU HASSAN MR MOHAMMAD ASHRI ABU HASSAN

INSTRUCTIONS TO CANDIDATES

This paper consists of (4) sections: Section A 10 questions(multi choice questions) Section B 10 questions (true/false questions) Section C 6 questions (answer any FIVE(5) questions only) Section D 2 questions Answer all questions. All answers of: Section A, B, C and D must be written in answer booklet provided. The answer for each question must start on a new page. Candidates are NOT ALLOWED to bring any unauthorized items into the exam hall except with the permission of your invigilator.

Do Not Open the Question Paper Until Instructed This Question Paper Consists of Ten (10) Printed Pages

CONFIDENTIAL

FIIT/ICS2213/NOV10 SECTION A (10 Marks) Answer ALL questions. For each question choose the best answer. 1. Which one is true about the relationship between algorithm and data structure? A. B. C. D. 2. AVL + array. recursion + queue. binary search + tree. stack + queue.

better for measuring and comparing the performance of processors than for measuring and comparing the performance of algorithms Which one is describe the best for the above sentence? A. B. C. D. Algorithm Code. Algorithm Efficiency. Reinventing the Algorithm. Understanding Algorithm.

3.

By referring the figure below, which one is TRUE to describe the code?
double Pow (double X, int N) { if (N == 0) return 1; else return X * Pow (X, N 1); }

A. B. C. D. 4.

Recursive function Iterative function By Ref function No passing parameter function

What is the height of an empty tree? A. B. C. D. 1 0 -1 No value

5.

Below are TRUE about Binary Tree EXCEPT: A. B. C. D. A binary tree is a tree in which no node can have more than two subtrees. It can have zero, one or two subtrees. Contain either leftsubtree or rightsubtree. A Null tree is a tree that has 1 leaf.

CONFIDENTIAL /2

FIIT/ICS2213/NOV10 6. Below are the type of Depth First Traversal EXCEPT: A. B. C. D. 7. Breadth-first traversal. Inorder traversal. Postorder traversal. Preorder traversal.

Below are the requirements for a good hash function EXCEPT: A. B. C. D. The hash value is fully determined by the data being hashed. The hash function uses only a few of input data. The hash function "uniformly" distributes the data across the entire set of possible hash values. The hash function can generate different hash values for similar strings.

8.

_____________ is itself a binary search tree. A. B. C. D. Each node Each subtree Each leaf Each subnode

9.

An AVL tree is a binary search tree in which for every node in the tree, the height of the left and right subtrees differ by at most ____. A. B. C. D. -1 0 1 2

10.

The deleteNode operation (if the item to be deleted is in the doubly linked list) requires the adjustment of _____________ pointer(s) in certain nodes. A. B. C. D. one two three four

CONFIDENTIAL /3

FIIT/ICS2213/NOV10 SECTION B (10 Marks) For each of the following statements, answer T for TRUE or F for FALSE. 1. Dynamic programming solves each subproblem again and again and stores the solution in a table. You can then look up the solution when needed again. Two approach of Dynamic Programming are bottom up iterative approach and top down iterative approach. A vector is a one-dimensional array of numbers. A problem is called Nondeterministic Polynomial if its solution (if one exists) can be guessed and verified in polynomial time; Spanning tree of a graph is a subset of edges that forms a tree and reaches few node only. A greedy algorithm is a procedure that makes a minimal choice at each of its steps. Dijkstras work best when there are negative edges. A sparse graph is a graph with relatively few edges. A graph is a pair of a set of nodes and edges. We can use an array to implement a list because an array is dynamic.

2.

3. 4.

5.

6.

7. 8. 9. 10.

CONFIDENTIAL /4

FIIT/ICS2213/NOV10 SECTION C (50 Marks) Answer any FIVE (5) questions only. Question 1 a) Give the two factors in measuring of the amount of resources consumed in solving a problem of size n. (2 marks) Briefly explain the definition of growth rate. (2 marks) c) Discuss the criteria below in considering to choose a good algorithm. i) Optimality. ii) Simplicity and clarity. iii) Correctness. (6 marks)

b)

Question 2 a) Design a diagram that shows the relationships between little omega, omega, theta, big oh and little oh. (4 marks) Below is the code for iterative power function.
double IterPow (double X, int N) { double Result=1; while (N > 0) { Result *= X; N --; } return Result; } Cost 1 n+1 n n 1

b)

From the code above, identify the total instruction count and the big Oh value for the function. (4 marks) c) The big Oh value for linear equation is O(N). Identify the big oh value for: i. Constant ii. Quadratic (2 marks)

CONFIDENTIAL /5

FIIT/ICS2213/NOV10 Question 3 a) Based on Figure 1, what is the value for internal and external path length? (2 marks)

Figure 1. b) Briefly explain any TWO (2) red-black properties. (4 marks) c) Draw a red-black tree base on the list given. Use single circle to represent black node and double circle to represent red node. {18, 7, 3, 11, 8, 26, 22, 10} (4 marks)

CONFIDENTIAL /6

FIIT/ICS2213/NOV10 Question 4 a) Sometimes the height of the search tree n, is no better than a linked list. Discuss the solution for BST in order to make it more balanced. (2 marks) By referring to figure 2, fill in the black with the Black-Height values. 1 3 2 5 4 6 7

b)

8 Figure 2. (4 marks) c) By referring to figure 3, show the balance factor (BF) for each node.
40

20

50

10

30

45

70

22

32

Figure 3. (4 marks)

CONFIDENTIAL /7

FIIT/ICS2213/NOV10 Question 5 a) Distinguish the major difference between Prim's and Kruskals algorithm. (2 marks) Consider graph in Figure 4. Construct a minimum spanning tree from Tokushima using Prims algorithm.
70 31 61 110

b)

70 88 65 100 59 65 26 12 19 140 85 126 67

30

74 105 30 39

Figure 4. (8 marks)

CONFIDENTIAL /8

FIIT/ICS2213/NOV10 Question 6 a) b) Create an algorithms to find max and min simultaneously. (4 marks) Study and analyze the C++ code below:
void main() { stack S , T; int number=0,temp; while(number!=-1) { cout<<"\nEnter a number (-1 sentinel value):"; cin>>number; if (number!=-1) S.push(number); } while(S.stacktop()!= NULL) { temp = S.pop(); if (temp % 2 == 0) T.push(temp); } }//end main

i) Identify the values for stack T if the value inserted for stack S is {2, 100, 19, 3, 18, 23, 57, 46, 76, 10, 38, 93} ii) What happen to the program if the user dont enter the sentinel value? (4 marks) c) Discuss the process needed if a new is be added at the last node in a Linked List. (2 marks)

CONFIDENTIAL /9

FIIT/ICS2213/NOV10 SECTION D (30 Marks) Answer ALL questions. Question 1 a) Create a graph based on the adjacency list below:

(8 marks) b) The following are the inorder and postorder traversal of a mathematic expression. inorder: 3 * 7 + 1 / 4 + 17 - 5 postorder: 3 7 1 + 4 / * 17 5 - + Design a corresponding tree T with the nodes labeled and calculate the equation. (7 marks) Question 2 By using the given list below, show the steps for sorting the numbers using: [85 , 24 , 63 , 45 , 17 , 31 , 96 , 50] a) Heap sort algorithm. (8 marks) b) MergeSort algorithm. (7 marks)

END OF QUESTION PAPER

CONFIDENTIAL /10

Você também pode gostar