0% found this document useful (0 votes)
44 views

Data Structure and Algorithm

This document is a final examination for a Data Structures and Algorithms course. It consists of 17 questions testing various concepts related to data structures and algorithms. The exam has two parts - multiple choice questions worth 20 marks, and longer answer questions worth varying marks totaling 80 marks. Students are required to answer all questions, show their work, and return the question paper with their answer booklet.

Uploaded by

jia jun soong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Data Structure and Algorithm

This document is a final examination for a Data Structures and Algorithms course. It consists of 17 questions testing various concepts related to data structures and algorithms. The exam has two parts - multiple choice questions worth 20 marks, and longer answer questions worth varying marks totaling 80 marks. Students are required to answer all questions, show their work, and return the question paper with their answer booklet.

Uploaded by

jia jun soong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Final Examination

Semester 1 / Year 2014

COURSE : DATA STRUCTURE AND ALGORITHM


COURSE CODE : PROG2103
TIME : 2 1/2 HOURS
DEPARTMENT : COMPUTER SCIENCE
LECTURER : SO YONG QUAY

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

Part A: Multiple Choice Questions (10 X 2 marks = 20 marks)

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

2. The selection sort algorithm alternates between

a) swapping and copying.


b) comparing and swapping.
c) moving and comparing.
d) copying and comparing.

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)

4. The unordered array offers low ________ and fast _____________ .

a) deletion and inserting, searching


b) deletion and searching, inserting
c) searching and inserting, deletion
d) none of above

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

6. The breadth-first search is implemented by _________________ .

a) stack
b) queue
c) priority queue
d) priority stack

7. Insert an item in a heap require _________ time.

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

10. Which of the following sorting algorithm uses divide-and-conquer strategy?

a) Merge sort
b) Shell sort
c) Heap sort
d) Selection sort

2/6
DATA STRUCTURE AND ALGORITHM

Part B: Answer all Questions

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)

b) Use Binary Tree to arrange the following number series. (5 marks)

18, 20, 9, 11, 33, 44, 18, 10, 18, 9

c) Use the following binary tree to delete note 24, which node as the replacement
node? Redraw the new binary search tree. (5 marks)

12. a) Describe the Mergesort algorithm. (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

(Use the following table format for your answer.)

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

13. a) Explain the Heaps and its characteristics. (5 marks)

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

15. a) Explain the dynamic programming. (5 marks)

b) Discuss any two problems when use recursive divide-and-conquer algorithm to


calculate the binomial coefficient. (4 marks)

c) Try to use dynamic programming algorithm (for example, Pascal’s Triangle) to


calculate the binomial coefficient 5C3. (5 marks)

16. Analyze the following program and use the Big O notation to show its complexity
time.

a) Assume that there are n elements stored in the array. (6 marks)

public void medianSort(int left, int right)


{
int size = right-left+1;
if(size <= 3)
InsertSort(left, right);
else
{
long median = medianOf3(left, right);
int partition = partitionIt(left, right, median);
medianSort(left, partition-1);
medianSort(partition+1, right);
}
}
public int partitionIt(int left, int right, long pivot)
{
int leftPtr = left-1;
int rightPtr = right;
while(true)
{
while( theArray[++leftPtr] < pivot );

while(rightPtr > 0 && theArray[--rightPtr] > pivot);

if(leftPtr >= rightPtr)


break;
else
swap(leftPtr, rightPtr);
}
swap(leftPtr, right);
return leftPtr;
}

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);

public static int plusMethod(int n)


{
int subtotal = 0;
for (int j = 1; j <= n; j++)
subtotal ++;

for(int i = 1; i < n; i++)


subtotal ++;

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

(Use the following table format for your answer.)

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

You might also like