Skip to content
SmartFigureEduExam kits ₹19

CD3291 · 5 papers compared

CD 3291 Data Structures and Algorithms important questions

CD3291 exam kitModel answers + all papers, 1 PDF

Exam kit

Needed by the payment gateway. Not shared or used for marketing.

Secure payment by Cashfree Payments (UPI, cards, net banking). One-time payment, no subscription. The payment page may show StrangerYaar, the business that processes payments for SmartFigure.Terms · Refunds

ANNA UNIVERSITY · REGULATION 2021

Important Questions

CD 3291 — DATA STRUCTURES AND ALGORITHMS

Third Semester · Computer Science and Design

Prepared from 5 previous year question papers (Nov/Dec 2024, Apr/May 2024, Nov/Dec 2023, Apr/May 2023, Nov/Dec 2022). Every question was compared with the others of its unit; the ones asked more than once come first. "Most asked topics" shows in how many different exams a syllabus topic had a question.

UNIT 1Abstract Data Types

Most asked topics: shallow and deep copying (2/5) · asymptotic notations (2/5) · divide & conquer (2/5) · Abstract Data Types (ADTs) (1/5) · classes in Python (1/5) · recursion (1/5)

Part A · 2 marks

  1. 1.
    Differentiate between shallow copying and deep copying.

    Asked in Nov/Dec 2024

    (2)
  2. 2.
    Find the time complexity of the following recurrence relation : T(n)=1+T(n-1) if n>1 T(1)=0.

    Asked in Nov/Dec 2024

    (2)
  3. 3.
    What are commonly used built in classes for python?

    Asked in Apr/May 2024

    (2)
  4. 4.
    State the properties of the Big-Oh notation.

    Asked in Apr/May 2024

    (2)
  5. 5.
    Identify how you will measure input size of an algorithm.

    Asked in Nov/Dec 2023

    (2)
  6. 6.
    Define Accessors method in python.

    Asked in Nov/Dec 2023

    (2)

Part B · 13 marks

  1. 1.
    (i) What is operator overloading? Write a program to overload '+' operator to concatenate two strings. (ii) ALGORITHM Q(n) //Input: A positive integer n if n = 1 return 1 else return Q(n - 1) + 2 * n - 1 Identify the basic operation in the algorithm. Set up the recurrence relation for the number of times the algorithm's basic operation is executed and solve it using back substitution.

    Asked 2 times: Nov/Dec 2024, Nov/Dec 2022

    Free sample · model answer from the exam kit

    (i) Operator overloading

    Operator overloading means giving an existing operator (+, -, *, ==, <, ...) a new meaning for objects of a user-defined class. In Python every operator is mapped to a special method; when the interpreter evaluates a + b it actually calls a.__add__(b). By defining that method inside our class, we decide what + does for our objects. The same operator therefore behaves differently for different types (polymorphism): 2 + 3 gives 5, while 'ab' + 'cd' gives 'abcd'.

    Common special methods:

    • + → __add__(self, other)
    • - → __sub__(self, other)
    • * → __mul__(self, other)
    • == → __eq__(self, other)
    • < → __lt__(self, other)
    • len(x) → __len__(self)
    • str(x) / print(x) → __str__(self)

    Program: overload + to concatenate two string objects.

    class MyString:
        def __init__(self, text):
            self.text = text
    
        def __add__(self, other):          # called for  self + other
            return MyString(self.text + other.text)
    
        def __str__(self):
            return self.text
    
    s1 = MyString("Data ")
    s2 = MyString("Structures")
    s3 = s1 + s2                           # same as s1.__add__(s2)
    print(s3)                              # Data Structures

    Working: s1 + s2 calls s1.__add__(s2), which joins s1.text and s2.text and returns a new MyString object holding "Data Structures". __str__ lets print() show the text.

    (ii) Analysis of ALGORITHM Q(n)

    ALGORITHM Q(n)
    if n = 1 return 1
    else return Q(n - 1) + 2 * n - 1

    Basic operation: the multiplication 2 * n (it is executed exactly once in every call with n > 1; the additions and subtractions are executed the same number of times, so any of them gives the same order).

    Recurrence: let M(n) be the number of multiplications for input n.

    • M(n) = M(n - 1) + 1, for n > 1 (one multiplication plus those in Q(n - 1))
    • M(1) = 0 (the base case does no multiplication)

    Back substitution:

    1. M(n) = M(n - 1) + 1
    2. = [M(n - 2) + 1] + 1 = M(n - 2) + 2
    3. = [M(n - 3) + 1] + 2 = M(n - 3) + 3
    4. In general, after k substitutions: M(n) = M(n - k) + k
    5. Put k = n - 1 so that we reach the base case: M(n) = M(1) + (n - 1) = 0 + n - 1

    M(n) = n - 1, so the algorithm is Θ(n) (linear time). Check: Q(3) calls Q(2) and Q(1); multiplications are done only in Q(3) and Q(2), that is 2 = 3 - 1.

    What Q computes: Q(1) = 1, Q(2) = 1 + 3 = 4, Q(3) = 4 + 5 = 9, so Q(n) = 1 + 3 + 5 + ... + (2n - 1) = n², the sum of the first n odd numbers.

    The CD3291 exam kit has model answers like this for 32 of these questions.

    (13)
  2. 2.
    Write an algorithm to perform binary search and analyse its time complexity.

    Asked in Nov/Dec 2024

    (13)
  3. 3.
    (i) Distinguish between shallow and deep copying. (ii) Write a short Python function that takes a positive integer n and returns the sum of the squares of all the positive integers smaller than n.

    Asked in Apr/May 2024

    (13)
  4. 4.
    (i) What is objects? Explain the procedure of creating and using objects with example. (ii) Write a Python function that finds the minimum and maximum values in a sequence without using any loops.

    Asked in Apr/May 2024

    (13)

UNIT 2Linear Structures

Most asked topics: singly linked lists (3/5) · applications (3/5) · Stack ADT (2/5) · List ADT (1/5) · array-based implementations (1/5) · linked list implementations (1/5)

Part A · 2 marks

  1. 1.
    What is the disadvantage of a circular linked list?

    Asked 2 times: Nov/Dec 2024, Nov/Dec 2022

    (2)
  2. 2.
    List any two applications of a queue.

    Asked in Nov/Dec 2024

    (2)
  3. 3.
    What are referential arrays? Give example.

    Asked in Apr/May 2024

    (2)
  4. 4.
    State the application of the double ended queues.

    Asked in Apr/May 2024

    (2)
  5. 5.
    Name any two applications where dequeue can be used.

    Asked in Nov/Dec 2023

    (2)
  6. 6.
    Specify the time complexity of Insertion operation in circular linked list, how it is arrived.

    Asked in Nov/Dec 2023

    (2)

Part B · 13 marks

  1. 1.
    (i) Define Stack ADT and list the five operations that can be performed on it. (ii) There are two stacks in a single array, one grows from position 1 of the array, and the other grows from the last position. Write a procedure PUSH(x, S) that pushes element x onto stack S, where S is one or the other of these two stacks. (iii) Write an algorithm to insert a node before a given node in a linked list.

    Asked 2 times: Nov/Dec 2023, Apr/May 2023

    (13)
  2. 2.
    Write procedures for performing the following operations on a singly linked list. (i) Delete a node at any arbitrary location. (ii) Insert a node at the end.

    Asked in Nov/Dec 2024

    (13)
  3. 3.
    Write an algorithm to convert an infix expression to a postfix expression. Trace the algorithm for the infix expression A+(B*C-(D/E^F)*G)*H. Evaluate the obtained postfix expression with A=1, B= -1, C=3, D=8, E=2, F=2, G= -5, H=4. Use stack for both operations.

    Asked in Nov/Dec 2024

    (13)
  4. 4.
    (i) Distinguish between compact arrays and dynamic array. (ii) Describe how the built-in sum function can be combined with Python's comprehension syntax to compute the sum of all numbers in an n x n data set, represented as a list of lists.

    Asked in Apr/May 2024

    (13)

UNIT 3Sorting and Searching

Most asked topics: hashing (5/5) · merge sort (3/5) · hash functions (3/5) · Bubble sort (2/5) · insertion sort (2/5) · quick sort (2/5)

Part A · 2 marks

  1. 1.
    What is the computational complexity of bubble sort in the best and worst case?

    Asked in Nov/Dec 2024

    (2)
  2. 2.
    What is the purpose of hashing?

    Asked in Nov/Dec 2024

    (2)
  3. 3.
    Why study sorting algorithm?

    Asked in Apr/May 2024

    (2)
  4. 4.
    What is goal of hash function?

    Asked in Apr/May 2024

    (2)
  5. 5.
    Define collision in hashing.

    Asked in Nov/Dec 2023

    (2)
  6. 6.
    State the algorithmic technique used in merge sort.

    Asked in Nov/Dec 2023

    (2)

Part B · 13 marks

  1. 1.
    Write an algorithm to perform merge sort and analyse its worst-case time complexity. Apply it to sort 12, 34 ,5, 67, 24, 10.

    Asked in Nov/Dec 2024

    (13)
  2. 2.
    Define Hashing. Insert the following data into a hash table using hash function h(X) = X mod 9. {17, 9, 34, 56, 11, 71, 86, 55, 22, 10, 4, 39, 49, 52, 82, 13, 40, 31, 35, 28, 44} for each of the following scenarios. • Collisions are handled by linear probing (slots = 3) • Collisions are handled by separate chaining.

    Asked in Nov/Dec 2024

    (13)
  3. 3.
    (i) State and explain the array-based implementation of Merge-sort with example. (ii) Show that the best-case running time of quick-sort on a sequence of size n with distinct elements is Omega (n log n).

    Asked in Apr/May 2024

    (13)
  4. 4.
    State and explain different collision-handling schemes with example.

    Asked in Apr/May 2024

    (13)

UNIT 4Tree Structures

Most asked topics: tree traversals (3/5) · heaps (3/5) · binary search trees (1/5) · AVL trees (1/5)

Part A · 2 marks

  1. 1.
    Construct a max heap from the following data: 12, 4, 32, 45, 6.

    Asked in Nov/Dec 2024

    (2)
  2. 2.
    A binary tree T has 9 nodes. From the inorder and preorder traversals of T given below, construct the binary tree. Inorder traversal : E A C K F H D B G Preorder traversal : F A E K C D H G B

    Asked in Nov/Dec 2024

    (2)
  3. 3.
    State the properties of binary trees.

    Asked in Apr/May 2024

    (2)
  4. 4.
    Define multiway search trees.

    Asked in Apr/May 2024

    (2)
  5. 5.
    Difference between Binary Tree and Binary search Tree.

    Asked in Nov/Dec 2023

    (2)
  6. 6.
    Give the worst, best average case complexities of Linear Search.

    Asked in Nov/Dec 2023

    (2)

Part B · 13 marks

  1. 1.
    Insert the following keys into an initially empty binary search tree (insert the items in the given order) : 30, 40, 23, 58, 48, 26, 11, 13. From the resultant tree, delete the following keys in sequence : 40, 58, 30, 23. Show the tree after each operation.

    Asked in Nov/Dec 2024

    (13)
  2. 2.
    Explain the significance of AVL trees over binary search trees and give the generic representations of LL, and RL operations. Insert the elements 8, 9, 12 and 10 in the AVL tree given in Fig. 14(b). Delete the following elements 8, 2, and 7 from the tree in sequence. Show the tree after each operation and mention the type of rotation in each case. [Fig. 14(b): AVL tree with root 4; 4 has children 2 and 7; 2 has children 1 and 3; 7 has children 6 and 17; 6 has left child 5; 17 has children 14 and 18]

    Asked in Nov/Dec 2024

    (13)
  3. 3.
    (i) Explain the various tree traversal with example. (ii) Draw the binary tree representation of the following arithmetic expression : "(((5 + 2) * (2 - 1))/((2 + 9) + ((7 - 2) - 1)) *8)".

    Asked in Apr/May 2024

    (13)
  4. 4.
    (i) Discuss about the operation on AVL tree with example. (ii) Implement the in-place heap-sort algorithm. Experimentally compare its running time with that of the standard heap-sort that is not in-place.

    Asked in Apr/May 2024

    (13)

UNIT 5Graph Structures

Most asked topics: topological ordering (4/5) · greedy algorithms (3/5) · representations of graph (2/5) · graph traversals (2/5) · shortest paths (2/5) · dynamic programming (1/5)

Part A · 2 marks

  1. 1.
    Find the topological ordering of the following graph (Fig. 9) [Fig. 9: directed graph with vertices 0 to 5 and edges 0->1, 1->2, 0->3, 1->3, 2->3, 2->4, 2->5, 3->4, 3->5, 4->5]

    Asked 2 times: Nov/Dec 2024, Nov/Dec 2022

    (2)
  2. 2.
    Distinguish tractable and intractable algorithms.

    Asked in Nov/Dec 2024

    (2)
  3. 3.
    What are the different ways to represent a graph?

    Asked in Apr/May 2024

    (2)
  4. 4.
    State the components of a dynamic programming solution.

    Asked in Apr/May 2024

    (2)
  5. 5.
    State Greedy algorithm.

    Asked in Nov/Dec 2023

    (2)
  6. 6.
    List the three operations that can be performed on a graph.

    Asked in Nov/Dec 2023

    (2)

Part B · 13 marks

  1. 1.
    Write Prim's algorithm to find the minimum spanning tree. Apply the algorithm to find the minimum spanning tree of the graph given in Fig. 15(b). [Fig. 15(b): weighted undirected graph with edges a-b 2, a-c 8, a-d 6, a-e 8, a-f 7, b-d 5, b-e 6, b-g 5, c-d 9, c-f 9, c-g 7, d-e 3, d-f 7, d-g 4, e-g 3, f-g 6]

    Asked 2 times: Nov/Dec 2024, Nov/Dec 2022

    (13)
  2. 2.
    For the following graph Fig. 15(a) [Fig. 15(a): undirected graph with vertices A to J and edges A-B, A-D, A-I, B-C, B-D, B-E, C-E, C-F, D-E, D-G, E-F, E-G, E-H, F-H, G-H, G-I, G-J, H-J, I-J] (i) Report the order of the vertices encountered on a breadth-first search starting from vertex A. (ii) Report the order of the vertices encountered on a depth-first search starting from vertex A. Break all ties by picking the vertices in alphabetical order.

    Asked in Nov/Dec 2024

    (13)
  3. 3.
    (i) State and explain the different graph traversals with suitable example. (ii) Explain topological ordering with example.

    Asked in Apr/May 2024

    (13)
  4. 4.
    Draw a simple undirected graph G that has 12 vertices, 18 edges and 3 connected components. Draw an adjacency matrix representation of the undirected graph. Draw an adjacency list representation of the undirected graph.

    Asked in Apr/May 2024

    (13)

PART CAny unit

Part C · 15 marks

  1. 1.
    List the properties of m-way search tree. Explain the procedure for insertion and deletion of a key in a m-way search tree. Starting with an empty 4-way tree, perform the following operations in sequence : Insert 40, 80, 20, 60, 70, 45, 88, 120, 37, 21, 22 and Delete 45, 60, 22, 40, 88.

    Asked in Nov/Dec 2024

    (15)
  2. 2.
    Write the pseudocode for Dijkstra's algorithm to solve the single-source shortest-path problem on a weighted, directed graph assuming all edge weights are nonnegative. Analyze the algorithm to find the time complexity. Trace the algorithm on the following graph in Fig. 16(b) by showing each execution step of the algorithm. Assume the source vertex as 'A' [Fig. …

    Asked in Nov/Dec 2024

    (15)
  3. 3.
    (i) What values are returned during the following sequence of queue operations, if executed on an initially empty queue? enqueue(5), enqueue(3), dequeue( ), enqueue(2), enqueue(8), dequeue( ), dequeue( ), enqueue(9), enqueue(1), dequeue( ), enqueue(7), enqueue(6), dequeue( ), dequeue( ), enqueue(4), dequeue( ), dequeue( ). (ii) Implement a function that reverses a list of elements by pushing them onto a stack in one order and writing them back to the list in reversed order.

    Asked in Apr/May 2024

    (15)
  4. 4.
    (i) Consider the sequence of keys (5, 16, 22, 45, 2, 10, 18, 30, 50, 12, 1). Draw the result of inserting entries with these keys (in the given order) into an initially empty red-black tree. (ii) Design an efficient algorithm for the matrix chain multiplication problem that outputs a fully parenthesized expression for how to multiply the matrices in the chain using the minimum number of operations.

    Asked in Apr/May 2024

    (15)
  5. 5.
    (i) Define Selection sort and give its time and space complexity of the same for sorting the following elements 64, 25, 12, 22, 11. (ii) Create a binary search tree for the following numbers start from an empty binary search tree. 45, 26, 10, 60, 70, 30, 40 Delete keys 10, 60 and 45 one after the other and show the trees at each stage.

    Asked in Nov/Dec 2023

    (15)
  6. 6.
    Given Input {4371, 1323, 6173, 4199, 4344, 9679, 1989}, and a hash function h(x)=x mod 10. Do the following (i) Open hash table (ii) Linear probing (iii) Quadratic probing (iv) Double hasing with h2(x) = 7 - (x mod 7)

    Asked in Nov/Dec 2023

    (15)

A question asked once is no guarantee for the next exam; cover the full CD3291 syllabus. Read the papers themselves:Nov/Dec 2024, Apr/May 2024, Nov/Dec 2023, Apr/May 2023, Nov/Dec 2022.