Escolar Documentos
Profissional Documentos
Cultura Documentos
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]
Multiple Choice Questions
4. The worst case time required to search a given element in a sorted linked list of length n
is
a. 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 is
a. 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
is
a. 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 by
a. (n + 1) / 2 b. n(n+1) / 2 c. n2 d. log2n
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