COMP 314_2016

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Marks Scored:

KATHMANDU UNIVERSITY
End Semester Examination
August/September, 2016
Level: B.E./B.Sc. Course : COMP 314
Year : III Semester: II
Exam Roll No. : Time: 30 mins. F. M. : 10

Registration No.: Date :


SECTION “A”
[20 Q.  0.5 = 10 marks]
Circle the most appropriate answer.
1. Which of the given represents the correct notation of the expression 10n2 + 1000n +
10000?
a. O(n2) b. O(n) c. O(10n3) d. O(10000)

2. What is the worst complexity of Quick Sort algorithm?


a. O(n2) b. O(log n) c. O(n log n) d. O(n)

3. Suppose that we have a data file containing records of famous people, and we need to
build a hash table to find a record from the person's birthday. The size of the hash table is
4096. The following are hash functions which convert a birthday to an integer. Which of
the following function is the best?
a. hash( day/month/year ) = day + month + year
b. hash( day/month/year ) = day + month*31 + year
c. hash( day/month/year ) = (day + month*31 + year*365) mod 4093
d. None of the above

4. Suppose we are sorting an array of ten integers using some quadratic sorting algorithm.
After four iterations of the algorithm's main loop, the array elements are ordered as
shown here:
21, 32, 43, 54, 65, 76, 87, 89, 99
a. The algorithm might be either selection sort or insertion sort.
b. The algorithm might be selection sort, but it is not insertion sort.
c. The algorithm is not selection sort, but it might be insertion sort.
d. The algorithm is neither selection sort nor insertion sort.

5. Consider a sequencing problem where four jobs {J1, J2, J3, J4} have a profit of {30, 30,
40, 60} and corresponding deadlines (2, 3, 1, 3). Which of the following sequences of
jobs is the optimal solution? Each job takes one unit of time.
a. {J1, J2, J3} b. {J3, J1, J4} c. {J2, J1, J4} d. None of the above

6. Suppose we are sorting an array of eight integers using quicksort, and we have just
finished the first partitioning with the array looking like this:
21, 32, 43, 54, 65, 76, 87, 89, 99
a. The pivot could be either 43 or 65 b. The pivot could be 43 but not 65
c. The pivot could be 65 but not 43 d. The pivot could neither be 43 nor 65

7. What is the complexity of matrix chain multiplication (MCM) solution when using
dynamic programming?
a. O(n3) b. O(2n) c. O(n2) d. O(n log n)
8. Suppose you are given a binary string (say 01110001) and you want to sort it (to
00001111). Which algorithm would you use for better performance?
a. Quick b. Radix c. Counting d. Merge Sort

9. Consider an algorithm for solving activity selection problem. Assume that there are 6
activities with following start time (s) and finish time (f), which of the following is
TRUE?
s = {1, 2, 0, 4, 7, 5}
f = {5, 3, 4, 7, 9, 6}
a. 1st activity is not in solution set b. 3rd activity is not in solution set
c. 4th activity is not in solution set d. All of the above

10. Consider a solution of 0-1 knapsack problem using branch and bound. Following
describes 0-1 knapsack problem:
There are 7 items with weight w = {10, 20, 10, 10, 10, 10, 60} and profit p = {40, 60, 10,
10, 30, 20, 60}. The total allowable weight is W = 50.
What is the upper bound value we shall consider to solve this problem?
a. 100 b. 150 c. 120 d. 200

11. What are the main two elements of dynamic programming?


a. Overlapping Subproblems and Optimal Substructure
b. Overloading and Overriding
c. Overlapping Subproblems and Overloading
d. Overloading and Optimal Substructure

12. A networking company uses a compression technique to encode the message before
transmitting over the network. Suppose the message contains the following characters
with their frequency:
a:5 b:9 c:12 d:13 e:16 f:45
If the compression technique used is Huffman Coding, how many bits will be saved in
the message?
a. 576 b. 800 c. 324 d. 224

13. Consider a problem of minimizing a function f(x) of variables (x1,...,xn) over a region of
feasible solutions, S. Which technique is the most appropriate to solve such problem?
a. greedy b. branch and bound c. dynamic d. all of the above

14. Let the sequence of matrices be A1, A2, A3 and A4 whose dimensions are given by a set
p. And p = {3, 5, 4, 1, 5}. If you consider a following combination A1.((A2.A3).A4), what
is the total number of multiplications required?
a. 240 b. 300 c. 100 d. 120

15. Consider the following string sequences:


S1 = “ABCDACCCDBAA”
S2 = “CBBBACCBAAACA”
Which of the following is NOT the common subsequence of S1 and S2?
a. BACAABA b. ACCBACA c. CACCBAA d. None of the above
16. Consider a matrix chain multiplication problem. If a dynamic programming gives a s-
table as follows, what is the Optimal parenthesisation?

a. (((A1A2)A3)(A4(A5A6))) b. ((((A1A2)A3)(A4A5))A6)
c. (A1((A2A3)(A4A5))A6) d. None of the above

17. Consider two strings X= "A,P,P,L,E" and Y="P,A,P,L,E". Generate a table for solving a
longest common subsequence problem. Assume that the table[0,...] = 0 and table[..., 0] =
0, what is the value of table[4, 2]? Put X as column and Y as row.
a. 1 b. 2 c. 3 d. 4

18. What is the worst time complexity of Binary Search algorithm?


a. O(n) b. O(1) c. O(log n) d. O(n2)

19. Which of the following statements is TRUE?


a. Every graph is a tree but very tree may not be a graph.
b. Every tree is a graph but very graph may not be a tree.
c. Every graph must be a weighted graph.
d. Every graph must be a directed graph.

20. What is the running time of BFS?


a. O(|V|+|E|) b. O(|E|+|E|) c. O(|V|+|V|) d. O(|V|*|V|)
KATHMANDU UNIVERSITY
End Semester Examination
August/September, 2016
Level : B.E./B.Sc. Course : COMP 314
Year : III Semester: II
Time : 2 hrs. 30 mins. F. M. : 40
SECTION “B”
[6 Q.  4 = 24 marks]

Attempt ANY SIX questions.

1. Below is pseudocode for some algorithm OPERATION with the input size n.
OPERATION(n)
for i ← 1 to 100 do
for k ← 1 to n do
j ← 1; m ← n
while j < m do
m ← (m+j)/2
end while
end for
end for
Perform a line-by-line analysis of OPERATION and derive a precise expression of the
running time T(n).

2. Describe Binary Search Tree. Describe the operation of deleting a node from Binary
Search Tree. [1 + 3]

3. Explain how backtracking algorithm works? How one can solve 8-queen problem using
backtracking? [1+3]

4. Simulate counting sort algorithm in following set of numbers.


312 423, 568, 161, 914, 429, 381, 635

5. State Activity Selection Problem. Using greedy algorithm, demonstrate how it can be
solved. [1+3]

6. With suitable example, demonstrate how Huffman coding works?

7. Write short notes on: [2+2]


a) Traversing a Graph
b) Branch and Bound
SECTION “C”
[2 Q.  8 = 16 marks]
Attempt ANY TWO questions.
8. Consider the matrices A1, A2, A3, and A4 with following dimensions.
Matrix Dimensions
A1 5x7
A2 7x3
A3 3x3
A4 3x1

Use dynamic programming to fill up m-table and s-table. Find the optimal
parenthesization of above matrices.

9. Describe Longest Common Subsequence Problem. Following are two different strings.
S1 = BDCABA
S2 = ABCBDAB
Use dynamic programming to find the longest common subsequence of S1 and S2.

10. Consider a following graph. Simulate Dijkstra's algorithm step-by-step and find out the
shortest path starting from source node s.

You might also like