0% found this document useful (0 votes)
35 views

Dsa 2020

The document discusses data structures and algorithms. It contains multiple choice questions about concepts like heaps, linked lists, stacks, trees, graphs, and time complexity. It also includes questions asking to implement functions for operations on arrays, linked lists, and recursion.

Uploaded by

Uddipto Jana
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)
35 views

Dsa 2020

The document discusses data structures and algorithms. It contains multiple choice questions about concepts like heaps, linked lists, stacks, trees, graphs, and time complexity. It also includes questions asking to implement functions for operations on arrays, linked lists, and recursion.

Uploaded by

Uddipto Jana
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/ 17

B.

TECH/CSE/3RD SEM/CSEN 2101/2020


B.TECH/CSE/3RD SEM/CSEN 2101/2020

DATA STRUCTURES AND ALGORITHMS


(CSEN 2101)
Time Allotted : 3 hrs Full Marks : 70
Figures out of the right margin indicate full marks.
Candidates are required to answer Group A and
any 5 (five) from Group B to E, taking at least one from each group.
Candidates are required to give answer in their own words as far as practicable.

Group – A
(Multiple Choice Type Questions)

1. Choose the correct alternative for the following: 10 × 1 = 10


(i) Consider a max heap, represented by the array. Now consider that a value 35 is
inserted into this heap.

After insertion, the new heap is


(a) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35 (b) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
(c) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15 (d) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
(ii) What is the output of following function for start pointing to first node of following?
linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
(a) 1 4 6 6 4 1 (b) 1 3 5 1 3 5 (c) 1 2 3 5 (d) 1 3 5 5 3 1
(iii) A stack S has the entries a,b,c with ‘a’ on the top. Another stack T is empty. An
entry popped out of the Stack S can be printed immediately or pushed in to the
stack T, finally popped out of the Stack T and printed. Then which sequence can
never be printed
(a) b a c (b) b c a (c) c a b (d) a b c

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

(a) A and D (b) D and E


(c) C and B (d) F and C. C

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

3. (a) Say we a have 4x4 matrix with the following values,


0200
1003
0050
0400
What will be the triplet format of the above mentioned matrix? Check whether
transferring the above mentioned matrix to triplet format is at all beneficial or not?
(b) Write a function which will take any number n as its argument. The function will
break this number into its individual digits and then store every single digit in a
separate node thereby forming a linked list. The function must return the head node
address of the created linked list at the end. (for example, if the number is 13579,
then there will be 5 nodes in the list containing nodes with values 1, 3, 5, 7, 9).
(c) Find the Big-Oh for T(n) = 48n100 + 2n+2 + 3n2 + 100.
(3 + 2) + 5 + 2 = 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.

(c) Is deque a FIFO data structure? Explain.


5 + 4 + 3 = 12

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)

You might also like