ANNA UNIVERSITY · REGULATION 2021
Important Questions
CS 3301 — DATA STRUCTURES
Third Semester · Computer Science and Engineering
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 1Lists
Most asked topics: Doubly-linked lists (3/5) · Singly linked lists (2/5) · Polynomial ADT (2/5) · List ADT (1/5) · Radix Sort (1/5) · Multilists (1/5)
Part A · 2 marks
- 1.Define polynomial ADT.(2)
Asked in Nov/Dec 2024
- 2.Identify how multidimensional array can be represented in memory.(2)
Asked in Nov/Dec 2024
- 3.State the advantages of modularity in programming.(2)
Asked in Apr/May 2024
- 4.What are ADT? Give an example.(2)
Asked in Apr/May 2024
- 5.Define abstract data type.(2)
Asked in Nov/Dec 2023
- 6.Infer the usage of multilists.(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Explain how polynomial expression can be represented using linked list.(13)
Asked 2 times: Apr/May 2023, Nov/Dec 2022
Free sample · model answer from the exam kit
A polynomial such as 5x^3 + 4x^2 + 2 has many terms with different exponents. An array indexed by exponent wastes space when the polynomial is sparse (for example x^1000 + 1 needs 1001 cells). A linked list stores only the non-zero terms, so it is the preferred representation.
Node structure
Each node stores one term: the coefficient, the exponent and a pointer to the next term. Terms are kept in decreasing order of exponent.
struct Term { int coef; int exp; struct Term *next; }; typedef struct Term *Poly;Draw: Two linked lists. List A: head -> [5 | 3 | *] -> [4 | 2 | *] -> [2 | 0 | NULL]. List B: head -> [3 | 3 | *] -> [2 | 1 | *] -> [1 | 0 | NULL]. Label the three fields of a node as coef, exp, next.
Addition of two polynomials
Algorithm: walk through both lists with pointers a and b.
- If a->exp > b->exp, copy term a to the result and advance a.
- If a->exp < b->exp, copy term b to the result and advance b.
- If the exponents are equal, add the coefficients; if the sum is non-zero, append (sum, exp) to the result; advance both a and b.
- When one list ends, copy the remaining terms of the other list.
Poly attach(int c, int e, Poly tail) { Poly p = malloc(sizeof(struct Term)); p->coef = c; p->exp = e; p->next = NULL; tail->next = p; return p; /* new tail */ } Poly addPoly(Poly a, Poly b) { struct Term head; /* dummy header node */ Poly tail = &head; int s; head.next = NULL; while (a != NULL && b != NULL) { if (a->exp > b->exp) { tail = attach(a->coef, a->exp, tail); a = a->next; } else if (a->exp < b->exp) { tail = attach(b->coef, b->exp, tail); b = b->next; } else { s = a->coef + b->coef; if (s != 0) tail = attach(s, a->exp, tail); a = a->next; b = b->next; } } for (; a != NULL; a = a->next) tail = attach(a->coef, a->exp, tail); for (; b != NULL; b = b->next) tail = attach(b->coef, b->exp, tail); return head.next; }Worked example
A = 5x^3 + 4x^2 + 2, B = 3x^3 + 2x + 1.
- a = (5,3), b = (3,3): exponents equal, 5 + 3 = 8, result: 8x^3.
- a = (4,2), b = (2,1): 2 > 1, copy a, result: 8x^3 + 4x^2.
- a = (2,0), b = (2,1): 0 < 1, copy b, result: 8x^3 + 4x^2 + 2x.
- a = (2,0), b = (1,0): equal, 2 + 1 = 3, result: 8x^3 + 4x^2 + 2x + 3.
- Both lists end.
Result list: [8|3] -> [4|2] -> [2|1] -> [3|0] -> NULL.
Other operations
- Subtraction: same as addition, but the coefficients of B are negated.
- Multiplication: multiply every term of A with every term of B (multiply coefficients, add exponents) and insert each product into the result, combining terms with equal exponents.
- Evaluation: traverse the list and add coef * x^exp for each node.
Complexity
If A has m terms and B has n terms, addition takes O(m + n) time and multiplication O(m * n) terms to generate. Space used is proportional to the number of non-zero terms only.
The CS3301 exam kit has model answers like this for 32 of these questions.
- 2.Explain the operation of traversing linked list. Write the algorithm and give an example.(13)
Asked in Nov/Dec 2024
- 3.Elaborate the steps to implement following operations of singly linked list. (i) Traverse (ii) Insert at front (iii) Insert at any (iv) Insert at end(13)
Asked in Nov/Dec 2024
- 4.(i) What are the different ways the list can be implemented? State and explain list ADT. (ii) Write the function to add two polynomial given as a linked list. Input: p1 = 13x^8 + 7x^5 + 32x^2 + 54, p2 = 3x^12 + 17x^5 + 3x^3 + 98(13)
Asked in Apr/May 2024
UNIT 2Stacks and Queues
Most asked topics: Operations (5/5) · Operations (5/5) · Circular Queue (3/5) · Applications (2/5) · Infix to Postfix conversion (1/5) · DeQueue (1/5)
Part A · 2 marks
- 1.Recall when an overflow and underflow condition occur during stack operations.(2)
Asked 2 times: Nov/Dec 2023, Apr/May 2023
- 2.Distinguish between static data structure and dynamic data structures.(2)
Asked in Nov/Dec 2024
- 3.List the operations of the stack.(2)
Asked in Nov/Dec 2024
- 4.A circular queue has a size of 5 and has 3 elements 11, 30, 41 where F=1 and R=3. After inserting 50 and 60, what is the value of F and R. Trying to insert 33 at this stage what happens. Delete 2 elements from the queue and insert 71, 98. Show the sequence of steps for the above operations.(2)
Asked in Apr/May 2024
- 5.A letter means push and an asterisk means pop in the following sequence. Give the sequence of values returned by the pop operations, when this sequence of operations is performed on an initially empty LIFO stack. U S G * O * O L D * * * E V * * * Y * O * *(2)
Asked in Apr/May 2024
- 6.List some applications of queues.(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Define stack? Explain the steps to implement (i) Stack using arrays (ii) Stack using linked list.(13)
Asked in Nov/Dec 2024
- 2.(i) Write an algorithm to insert and delete an element from a simple queue. (ii) Explain FIFO approach.(13)
Asked in Nov/Dec 2024
- 3.(i) What is circular queue? Explain with suitable example. (ii) State the application of Queue and explain any one application with an example.(13)
Asked in Apr/May 2024
- 4.Write a C function for the following conversions. (i) Infix to postfix expression (ii) Evaluate the postfix expression(6+7)
Asked in Apr/May 2024
UNIT 3Trees
Most asked topics: Binary Search Tree ADT (5/5) · Tree Traversals (4/5) · AVL Trees (2/5) · Tree ADT (1/5) · Priority Queue (Heaps) (1/5) · Binary Heap (1/5)
Part A · 2 marks
- 1.Indicate the properties of binary tree.(2)
Asked 2 times: Nov/Dec 2023, Apr/May 2023
- 2.Define binary heap.(2)
Asked in Nov/Dec 2024
- 3.Define threaded binary tree.(2)
Asked in Nov/Dec 2024
- 4.What are the properties of AVL trees?(2)
Asked in Apr/May 2024
- 5.A binary tree T has 9 nodes. The inorder and postorder traversals of T yield the following: Inorder traversal (I): E A C K F H D B G Postorder traversal (Po): E C K A H B G D F Draw the binary tree.(2)
Asked in Apr/May 2024
- 6.Distinguish binary search tree and AVL tree.(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Write an algorithm for preorder, inorder and postorder traversal of a binary tree.(13)
Asked 2 times: Nov/Dec 2024, Nov/Dec 2022
- 2.How to Insert and delete an element into a binary search tree and write down the pseudo code with an example.(13)
Asked in Nov/Dec 2024
- 3.(i) Distinguish between Binary tree, general tree and binary search tree and also give an example. (ii) Given the AVL Tree in Figure 2. Draw the resulting balanced tree step by step after 5 is removed. Label each node with balance factor. [Figure 2: AVL tree with root 5; 5 has children 3 and 10; 3 has children 2 and 4; 2 has left child 1; 10 has children 7 and 11; 7 has children 6 and 9; 9 has left child 8; 11 has right child 12](13)
Asked in Apr/May 2024
- 4.Write a C function for the following in the Binary search tree: (i) To find the height of a tree. (ii) To Find minimum and maximum (iii) Pre order traversals.(5+5+3)
Asked in Apr/May 2024
UNIT 4Multiway Search Trees and Graphs
Most asked topics: B-Tree (4/5) · B+ Tree (4/5) · Dijkstra's algorithm (3/5) · Topological Sort (2/5) · Prim's algorithm (2/5) · Representation of Graphs (1/5)
Part A · 2 marks
- 1.List out the commonly used graph representations.(2)
Asked in Nov/Dec 2024
- 2.Define Euler's cycle in a graph.(2)
Asked in Nov/Dec 2024
- 3.Define Euler's circuits.(2)
Asked in Apr/May 2024
- 4.Give the topological order for the DAG in Figure 1. [Figure 1: DAG with vertices 1 to 7 and edges 1->3, 1->4, 2->4, 2->5, 4->3, 5->4, 3->6, 4->6, 4->7, 5->7](2)
Asked in Apr/May 2024
- 5.Define B+ Tree with an example.(2)
Asked in Nov/Dec 2023
- 6.Express how a graph differs from a spanning tree with an example.(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Formulate an algorithm to find the shortest path using Dijkstra's algorithm and explain with example.(13)
Asked 2 times: Nov/Dec 2024, Nov/Dec 2022
- 2.(i) List the principles of B-trees and explain how a node can be inserted into a B-Tree with an example. (ii) Outline an algorithm for traversing a graph using breadth -first method with an example.(13)
Asked 2 times: Nov/Dec 2023, Apr/May 2023
- 3.Explain weighted and unweighted shortest path algorithms.(13)
Asked in Nov/Dec 2024
- 4.Distinguish between Prims and Kruskal's? Using Prims algorithm starting with vertex "A", list the vertices of the graph given in Figure 3. in the order they are added to maximum spanning tree. [Figure 3: undirected weighted graph with vertices A to J and edges A-B = 2, B-C = 3, A-D = 15, B-D = 5, B-E = 17, C-E = 12, C-F = 18, D-E = 4, E-F = 13, A-I = 9, D-G = 6, E-G = 11, E-H = 7, F-H = 14, G-H = 19, G-I = 8, G-J = 10, H-J = 16, I-J = 1](13)
Asked in Apr/May 2024
UNIT 5Searching, Sorting and Hashing Techniques
Most asked topics: Hashing (5/5) · Searching (4/5) · Sorting (4/5) · Hash Functions (4/5) · Linear Search (3/5) · Binary Search (2/5)
Part A · 2 marks
- 1.What are the different hash functions?(2)
Asked 3 times: Apr/May 2024, Nov/Dec 2023, Nov/Dec 2022
- 2.Mention the types of searching.(2)
Asked in Nov/Dec 2024
- 3.What is Rehashing?(2)
Asked in Nov/Dec 2024
- 4.The keys 22, 28, 23, 12, 13, 3, 25 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k mod 10 and apply linear probing for resolving the collision. What is the resultant hash table?(2)
Asked in Apr/May 2024
- 5.Distinguish internal and external sorting.(2)
Asked in Nov/Dec 2023
- 6.Outline perfect minimal hashing function.(2)
Asked in Apr/May 2023
Part B · 13 marks
- 1.Write an algorithm to implement selection sort with suitable example.(13)
Asked 2 times: Nov/Dec 2024, Apr/May 2023
- 2.Explain Extendible hashing in detail.(13)
Asked in Nov/Dec 2024
- 3.(i) Distinguish between linear search and binary search. (ii) What is extendible hashing? State and explain with example.(13)
Asked in Apr/May 2024
- 4.Sort the sequence 4, 6, 8, 2, 9, 5, 1, 7 and 3 using the following (i) Merge sort (ii) Quicksort (picking the first element as the pivot).(6+7)
Asked in Apr/May 2024
PART CAny unit
Part C · 15 marks
- 1.Explain the implementation of circular queue using array. How an "empty queue" is distinguished from a "full queue"? Write necessary functions to perform all valid operations on circular queue.(15)
Asked in Nov/Dec 2024
- 2.Construct the minimum spanning tree (MST) for the given graph (Fig. 16 (b)) using Kruskal's Algorithm. Find the minimum cost. [Fig. 16 (b): undirected weighted graph with vertices 1 to 7 and edges 1-2 = 28, 1-6 = 10, 2-7 = 14, 2-3 = 16, 3-4 = 12, 7-4 = 18, 7-5 = 24, 6-5 = 25, 5-4 = 22](15)
Asked in Nov/Dec 2024
- 3.What are the basic heap operations? Show how heap sort processes the input 142, 543, 123, 65, 453, 879, 572, 434, 111, 242, 811, 102.(15)
Asked in Apr/May 2024
- 4.Write the functions for the following operations on doubly linked list. - Sum up the values stored in the nodes of a list. - Count the even numbers in the list. - Delete the node with an element X.(15)
Asked in Apr/May 2024
- 5.(i) Demonstrate how minimum cost spanning tree can be obtained by Prim's method with an algorithm. (ii) Trace the above algorithm for the following graph and analyze the time and space complexity. [Figure: undirected weighted graph with vertices 1 to 6 and edges 1-2 = 10, 1-4 = 30, 1-5 = 45, 2-3 = 50, 2-5 = 40, 2-6 = 25, 3-5 = 35, 3-6 = 15, 4-6 = 20, 5-6 = 55](15)
Asked in Nov/Dec 2023
- 6.(i) Convert the following infix expression to postfix expression with a neat sketch using stacks. ((A - (B + C) * D)$(E + F)). (A/(B - C + D)) * (E - A) * C (ii) Devise an algorithm for evaluating the above postfix expression using stacks and analyze the complexity.(15)
Asked in Nov/Dec 2023