Data Structure and Algorithm
Data Structure and Algorithm
Student’s ID:
Batch No:
Notes to candidates:
1) The question paper consists of 6 pages and 17 questions.
2) There are two parts in this paper. Students are required to answer all questions.
3) Return the question paper with your answer booklet.
DATA STRUCTURE AND ALGORITHM
1. Which of the following way is used to judge the performance based on memory
usage?
a) running time
b) system criteria
c) space utilization
d) software criteria
3. What is the best case to find a specified element in a singly linked list?
a) O(1)
b) O(logn)
c) O(n/2)
d) O(n)
5. Suppose you insert 44, 33, 22 and 11 into the stack. Then you delete three items.
Which one is left on the stack?
a) 11
b) 22
c) 33
d) 44
1/6
DATA STRUCTURE AND ALGORITHM
a) stack
b) queue
c) priority queue
d) priority stack
a) O(2n)
b) O(logn)
c) O(n)
d) O(nlogn)
8. Assume that there are 900 elements in an array, what is the maximum comparison
numbers in a linear search?
a) 1
b) 9
c) 10
d) 900
9. How total nodes are in a complete binary tree (the root considered to be at level 0)
that consists of 10 levels?
a) 1023
b) 1024
c) 2047
d) 2048
a) Merge sort
b) Shell sort
c) Heap sort
d) Selection sort
2/6
DATA STRUCTURE AND ALGORITHM
11. a) Discuss the complexity time of the insertion a node in binary tree and use Big-O
notation to show your final answer. (5 marks)
c) Use the following binary tree to delete note 24, which node as the replacement
node? Redraw the new binary search tree. (5 marks)
b) Given the following list of values. Perform a Merge Sort to sort the values in each
pass. (10 marks)
56 23 67 22 98 45 77 33 88 55 99 76 45
Index
Pass No. 0 1 2 3 4 5 6 7 8 9 10 11 12
0 56 23 67 22 98 45 77 33 88 55 99 76 45
1
2
3
4
5
6
7
8
3/6
DATA STRUCTURE AND ALGORITHM
9
10
11
12
13
14
15
16
b) Turn the array with the following data into a heap with N/2 applications of
trickeDown(): (5 marks)
45 78 23 20 11 38 20 65 99 88 93
(A heap is implemented as an array; use the following table format for your
answer.)
Index
Pass No. 0 1 2 3 4 5 6 7 8 9 10
Original data 45 78 23 20 11 38 20 65 99 88 93
N=( )
N=( )
N=( )
N=( )
N=( )
14. Use the following graph to show the order of visiting the vertices by depth-first
search and breadth-first search.(Assume that the vertices are selected in alphabetical
order and the starting vertex is A) (6 marks)
4/6
DATA STRUCTURE AND ALGORITHM
16. Analyze the following program and use the Big O notation to show its complexity
time.
5/6
DATA STRUCTURE AND ALGORITHM
b) (4 marks)
int total = 0;
int n; // n is a very large number
for (int j = 0; j < n; j++)
for (int i = 0; i < n; i++)
total += plusMethod(n);
return subtotal;
}
17. Given the following list of values, perform a Shellsort to sort the values in each pass.
(Using the Using interval sequence h = 3 * h + 1) (10 marks)
48 12 67 11 20 7 88 99 23 67 12 10 8 0
Index
Pass No. 0 1 2 3 4 5 6 7 8 9 10 11 12 13
Original 48 12 67 11 20 7 88 99 23 67 12 10 8 0
h=( )
h=( )
h=( )
h=( )
________000_______
6/6