Dsa 2020
Dsa 2020
Group – A
(Multiple Choice Type Questions)
CSEN 2101 1
B.TECH/CSE/3RD SEM/CSEN 2101/2020
(iv) What would be the Postfix notation for the given equation?
a+(b*c(d/e^f)*g)*h)
(a) ab*cdef/^*g-h+ (b) abcdef^/*g*h*+
(c) abcd*^ed/g*-h*+ (d) abc*de^fg/*-*h+
(v) A variant of the linked list in which none of the node contains NULL pointer is?
(a) Singly Linked List (b) Doubly Linked List
(c) Circular Linked List (d) Reversed Linked List.
(vi) The searching technique that takes O (1) time to find a data is
(a) Linear Search (b) Binary Search (c) Hashing (d) Tree Search.
(vii) Given a 5 × 3 matrix where 10 elements are zeroes, the order of its
corresponding triplet array is
(a) 3 × 5 (b) 6 × 3 (c) 3 × 10 (d) 11 × 3
(viii) Which of the following are true for a B-tree of order 5?
(a) The root can have a maximum of 5 child nodes
(b) Each leaf node has at least 2 key stored in it
(c) The heights of leaf nodes may differ
(d) None of the above is true.
(ix) Complete the following recursive implementation to find the sum of digits of
number:
int recursive_sum_of_digits(int n)
{
if(n==0)
return 0;
else
return _________________;
}
int main()
{
int n = 123;
int ans = recursive_sum_of_digits(n);
printf(“Result = %d”, ans);
return 0;
}
(a) (n / 10) + recursive_sum_of_digits(n % 10)
(b) (n % 10) + recursive_sum_of_digits(n / 10)
(c) (n) + recursive_sum_of_digits(n % 10)
(d) (n % 10) + recursive_sum_of_digits(n % 10).
(x) In the given graph identify the cut vertices A B F
D E
CSEN 2101 2
B.TECH/CSE/3RD SEM/CSEN 2101/2020
Group – B
2. (a) The running time of an algorithm, T(n), where ‘n’ is the input size, is given by
T(n) = 1, for n = 1 and T(n) = T(n/3) + c, for n > 1. Find the order of the
algorithm.
(b) Write a function to remove duplicates from an ordered array, without using any
second array.
For example, if the original content of the array is: a, a, c, d, q, q, r, s, u, w, w, w,
w; then the final content of the array should be a, c, d, q, r, s, u, w.
(c) Write one difference between linear and non-linear data structure.
4 + 7 + 1 = 12
Group – C
4. (a) Evaluate the result of the given infix expression using proper data structure:
2*(5*(3+6))/15 - 2.
Show every step clearly.
(b) Discuss the key features of tail recursion. Explain with suitable example how it
is different from a normal recursive function.
5. (a) Write a small C function (no need for main, header files etc.) to print the moves of
the well-known Tower of Hanoi problem using recursion. Assume that the smallest
disc is numbered as ‘disc 1’ and the largest is ‘disc n’. Each of the three pegs is
represented by a char (datatype) – source (‘S’), destination (‘D’) and temporary
(‘T’). Given below are some examples of the moves that you will print –
Move the disc # 12 from T to D
CSEN 2101 3
B.TECH/CSE/3RD SEM/CSEN 2101/2020
Move the disc # 4 from S to T
(b) Now just write the output of your function if it is called with n = 4, where n is the
number of discs.
(c) What will the following function return if it is called from the main as XXXX(5, 0,
1)? Can you identify what the following function is calculating? It is something
well-known.
int XXXX(int n, int a, int b)
{
if (n == 0)
return a;
if (n == 1)
return b;
return XXXX(n - 1, b, a + b);
}
5 + 2 + (4 + 1) = 12
Group – D
6. (a) Reconstruct a binary tree from its traversal sequences given below:
Inorder : J E N K O P B F A C L G M D H I
Postorder : J N O P K E F B C L M G H I D A
What will be the preorder traversal sequence of the tree?
(b) Draw the different stages of an initially-empty AVL tree by inserting nodes in
the following sequence: 7, 10, 12, 37, 32, 22, 25, 27, 35, 45, 52. Also show the
balance factors of each node.
(5 + 2) + 5 = 12
7. (a) What are the two main ways to represent a graph? Write the space required to
store each of those. When do you choose which representation?
(b) Robin has drawn the BFS tree of a graph G with 100 nodes. It contains 90 edges.
Is this possible? Did he draw it correctly? Justify your answer.
(c) Suppose you are performing a depth-first traversal on the graph given, with s as the
starting node. Write just the discovery time and finishing time of each vertex and
draw the depth-first tree. Assume that in each of the adjacency lists the vertices are
in alphabetical order, and so understand that now the answers will be unique.
(2 + 2 + 1) + 2 + 5 = 12
CSEN 2101 4
B.TECH/CSE/3RD SEM/CSEN 2101/2020
Group – E
8. (a) Construct a max-heap using the given sequence of elements, 2, 8, 6, 1, 10, 15, 3,
12, 11.
(b) Derive the worst-case time complexity of a binary search.
(c) Using linear probing method to insert the following elements in a table of size 7:
76, 93, 40, 47, 10, 55
Use the hash function (h(k) + i) mod 7, h(k) = k mod 7, i = 0.6.
3 + 4 + 5 = 12
9. (a) Fill up the following table with the appropriate asymptotic complexities:-
Type of Sorting Best Case Average Case Worst Case
Naïve Bubble Sort O(n2)
Improved Bubble Sort O(n2)
Insertion Sort
Selection Sort
Counting Sort O(n+k)
(b) Write an algorithm to implement the Interpolation Search. Under what
condition does the Interpolation Search behave like sequential search?
(c) What is the time complexity of the worst case of linear search?
6 + (4 + 1) + 1 = 12
Department &
Submission Link
Section
https://classroom.google.com/c/MjYzNzg3MDAw/a/Mjg4NDMzNzM3
CSE A
MjA5/details
https://classroom.google.com/c/MTE4NzY4MjM4NjM4/a/Mjg4NDI0O
CSE B
DA2NzY5/details
https://classroom.google.com/u/0/w/MTMwMDU2NDk2NDI1/tc/Mjk
CSE C
0MzczNjYwMTc4
https://classroom.google.com/c/MjUzMzUzMDg1MzI1/a/Mjg4NDI3Mz
LATERAL
gwNTQy/details
CSEN 2101 5
O(n2)