Data Structures and Algorithms - B.Tech 3rd Semester Exam., 2020 (New Course)

2020Semester 3Civil-CAEnd Semester
Bihar Engineering University, Patna
B.Tech 3rd Semester Exam., 2020 (New Course)

Data Structures and Algorithms

Time: 03 HoursCode: 100304Full Marks: 70

Instructions:

  1. The marks are indicated in the right-hand margin.
  2. There are NINE questions in this paper.
  3. Attempt FIVE questions in all.
  4. Question No. 1 is compulsory.
Q.1 Choose the correct answer of the following (any seven):[14]
  1. Which of the following is time complexity of the given code?
    \( int\ a=0; \)
    \( for(i=0; i< N; i++) \{ \)
    \( \quad for(j=N; j>i; j--) \{ \)
    \( \quad \quad a = a + i + j; \)
    \( \quad \} \)
    \( \} \)

    1. \( O(N) \)
    2. \( O(N * \log(N)) \)
    3. \( O(N * \sqrt{N}) \)
    4. \( O(N * N) \)
  2. Which of the following is time complexity of the given code?
    \( int\ i,\ j,\ k=0; \)
    \( for(i=n/2; i<=n; i++) \{ \)
    \( \quad for(j=2; j<=n; j=j*2) \{ \)
    \( \quad \quad k = k + n/2; \)
    \( \quad \} \)
    \( \} \)

    1. \( O(N) \)
    2. \( O(N * \log(N)) \)
    3. \( O(N * \sqrt{N}) \)
    4. \( O(N * N) \)
  3. Which of the following cases does not exist in complexity theory?

    1. Best case
    2. Worst case
    3. Average case
    4. Null case
  4. The operation of processing each element in the list is known as

    1. sorting
    2. merging
    3. inserting
    4. traversal
  5. Arrays are best data structures

    1. for relatively permanent collections of data
    2. for the size of the structure and the data in the structure are constantly changing
    3. Both (i) and (ii)
    4. None of the above
  6. Each array declaration needs not give, implicitly or explicitly the information about

    1. the name of array
    2. the data type of array
    3. the first data from the set to be stored
    4. the index set of the array
  7. In general, the binary search method needs not more than

    1. \( [\log_2 n] - 1 \)
    2. \( [\log n] + 1 \)
    3. \( [\log_2 n] \)
    4. \( [\log_2 n] + 1 \) comparisons.
  8. State True or False:
    A. Binary search is used for searching in a sorted array.
    B. The time complexity of binary search is O(logn).

    1. True, False
    2. False, True
    3. False, False
    4. True, True
  9. Which of the following is non-linear data structure?

    1. Stack
    2. Linked list
    3. String
    4. Tree
  10. Which is the correct output for the following sequence of operations? push(5), push(8), pop, push(2), push(5), pop, pop, pop, push(1), pop

    1. 85251
    2. 85521
    3. 82551
    4. 81255
Q.2 Solve this question :[14]
  1. Analyse the time complexity of the given function and also write the recurrence relation of the function:
    \( int\ DoSomething(int\ n) \{ \)
    \( \quad if(n<=2)\ return\ 1; \)
    \( \quad else\ return\ (DoSomething(floor(sqrt(n))) + n); \)
    \( \} \)

Q.3 Solve this question :[14]
  1. Consider the following postfix expression : 873-/6254+*+-
    The above expression is evaluated using stack. Show the content of stack after each step.

Q.4 Solve this question :[14]
  1. What are the different notations for comparing the time complexity of an algorithm? Explain each of them with neat figures.

Q.5 Solve this question :[14]
  1. Explain the queue and circular queue with examples. Also, write the differences between the two.

Q.6 Solve this question :[14]
  1. Let a and b be positive integers. Suppose a function F is defined recursively as follows:
    \( F(a,b) = \begin{cases} 0 & \text{if } a < b \\ F(a-b,b) + 1 & \text{if } b \le a \end{cases} \)
    Find the values of the following: (a) \( F(2,3) \) (b) \( F(14,3) \)

Q.7 Solve both questions :[14]
  1. Write the algorithm of prefix evaluation with example.

  2. Write prefix notation of the following infix notation: \( A+B*C+D \)

Q.8 Solve this question :[14]
  1. What do you mean by ADT? Explain the ADT stack with test cases for both pop and push.

Q.9 Write short notes on the following:[14]
  1. Hashing

  2. Circular linked list

  3. Adjacency list

  4. AVL tree