5
Problem Solving Technique For 10 Marks Assignments 1. Please consider the following algorithm [3 Marks] s = 0; for (i=0; i < 2*n; i++) for (j=0; j < i; j++) s = s + i; i) What does this algorithm compute? ii) What is its basic operation? iii) How many times this basic operation executed? iv) What is the efficiency class of the above algorithm? 2. Design a recursive algorithm for computing 2 n for any non- negative integer n which is based on the formula 2 n = 2 n-1 + 2 n-1 Set up a recurrence relation for the number of additions made by the algorithm and solve it. [5 Marks] 3. Using stack write a C program to determine if a given string is palindrome and print suitable message as output? [2 Marks]

Problem+Solving+Technique FP1

Embed Size (px)

Citation preview

Page 1: Problem+Solving+Technique FP1

Problem Solving Technique

For 10 Marks Assignments

1. Please consider the following algorithm [3 Marks]

s = 0;for (i=0; i < 2*n; i++) for (j=0; j < i; j++)

s = s + i;i) What does this algorithm compute?ii) What is its basic operation? iii) How many times this basic operation executed?iv) What is the efficiency class of the above algorithm?

2. Design a recursive algorithm for computing 2n for any non-negative integer n which is based on the formula 2n = 2n-1 + 2n-1 Set up a recurrence relation for the number of additions made by the algorithm and solve it. [5 Marks]

3. Using stack write a C program to determine if a given string is palindrome and print suitable message as output? [2 Marks]

Page 2: Problem+Solving+Technique FP1

Multiple Choice Questions

1. Growth of mathematical function in the increasing order is one of the following a. x, x2 , log x, x log xb. log x, x log x, x, x2

c. log x, x , x log x, x2

d. x , log x, x log x, x2

2. Time complexity of Linear search algorithm over an array of n element is

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

3. The time required to search an element in a linked list of length n is

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

4. The worst case time required to search a given element in a sorted linked list of length n isa. O(1) b. O (log2n) c. O (n) d. O (log2n)

5. Consider a linked list of n elements. What is the time taken to insert an element an after element pointed by some pointer?a. O(1) b. O (log2n) c. O (n) d. O (log2n)

6. The time required to insert an element in a stack with linked list implementation isa. O(1) b. O (log2n) c. O (n) d. O (log2n)

7. Consider that n elements are to be sorted. The worst case time complexity of Bubble sort isa. O(1) b. O (log2n) c. O (n) d. O (n2)

8. The average time required to perform a successful sequential search for an element in an array A(1:n) is given bya. (n + 1) / 2 b. n(n+1) / 2 c. n2 d. log2n

9. Quicksort has the worst case time complexity.

a. O(nlogn) b. O(n2) c. O(n) d. None of these

Page 3: Problem+Solving+Technique FP1

9. Bubblesort is faster than the merge sort depending on the input.True /False

10. Traveling sales person problem is to find a tour ofa. Maximum cost b. Minimum cost c. Both d. None

11. TSP deals with

a. Euler circuit b. Hamiltonian circuit c. Both a & b d. None

11. Mystry (n)

S <- 0

for i <- 1 to n do

S <- S + i * i;

return S

What does this algorithm compute?

a. Sum of n numbers b. Sum of n2 c. None of these d. Sum of n-1 terms

12. What does the algorithm Compute? Secret (A[0..n-1]// Input: An array A[0..n-1] of n real numbers

minval <- A[0]; maxval <- A[0];

for i <- 1 to n-1 do

if A[i] < minval minval <- A[i];

if A[i] > maxval maxval <- A[i];

return maxval – minval

a. Finding the maximum difference between the elements in an array

13. Time complexity of Tower of Hanoi problema. 2n

b. 2n- 1c. None of thesed. n

Page 4: Problem+Solving+Technique FP1

14. x(n) = 3x (n- 1) Initial conditions x(1) = 4a. 5n-5 b. 3n-3 c. None of these d. 5n

15. Best case complexity of Linear Search

a. 1 b.n2 c. n d. None of these