0% found this document useful (0 votes)
5 views2 pages

QN 5

qn5

Uploaded by

parajuliaayush
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)
5 views2 pages

QN 5

qn5

Uploaded by

parajuliaayush
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/ 2

POKHARA UNIVERSITY

Level: Bachelor Semester: Fall Year : 2015


Programme: BE Full Marks: 100
Course: Analysis and Design of Algorithm Pass Marks: 45
Time : 3hrs.

Candidates are required to give their answers in their own words as far
as practicable.
The figures in the margin indicate full marks.
Attempt all the questions.

1. a) Define asymptotic notations Big O, Big Ω and Big Θ. 8


b) Use the step table method to determine the time complexity of the 7
following program segment. Also show that the complexity thus
obtained can be written as O(n).
float Sum(float a[], int n){
float s = 0.0;
for(int i = 1;i< = n;i++)
s+ = a[i];
return s;
}
2. a) Devise an algorithm to delete an element x from a binary search tree 7
T. What is the time complexity of your algorithm?
b) Write the algorithm for Quick Sort and compute the time complexity. 8
Point out the scenario when Quick Sort the worst case performance.
3. a) Explain complete binary tree with examples. Prove that the height of 7
the Binary tree with n number of nodes is log2 (n+1).
b) Find a minimum cost editing sequence that transforms string A into 8
string B using dynamic approach.
𝐴 = 𝑥, 𝑦, 𝑧, 𝑥, 𝑥
𝐵 = 𝑥, 𝑦, 𝑦, 𝑧, 𝑥
𝐶 = 𝑥, 𝑦, 𝑧, 𝑥, 𝑦
Next, compare the cost with the cost for transforming string A to C.

1
4. a) Apply dynamic programming approach to find the shortest path in 8
the following multistage graph.

Also show that greedy method is not suitable for this kind of
problems.
b) What is optional binary search tree? Provide the algorithm for finding 7
optimal tree with a suitable example.
5. a) Design an algorithm which finds the second largest element in an 7
array of n integers. Determine the number of comparisons the
algorithm makes in the worst case.
b) Describe the single source shortest path problem having negative 8
weight graph. Write the algorithm to compute shortest path with
negative edge cost. Calculate its complexity.
6. a) Explain backtracking algorithm and write down the backtracking 7
algorithm for N-queen problem.
b) Let 𝑊 = {5, 7, 10, 12, 15, 18, 20} and 𝑚 = 35. Find all possible 8
subsets of 𝑤 that sum to 𝑚 using backtracking. Also draw the portion
of the state space tree that is generated.
7. Write short notes on: (Any two) 2×5
a) 0/1 Knapsack Problem.
b) Bi-connected Components.
c) Hamilotinian Cycle.

You might also like