BIT201 · TU past paper
Data Structures and Algorithms 2078 question paper
The complete TU 2078 exam paper for Data Structures and Algorithms (BIT201), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- Q1.10 marksNumericalInfix to postfix conversion using stackHideAnswer
Explain algorithm to convert an infix expression to postfix using stack? Use this algorithm to convert (A+B)*C-D to postfix.[10]
- Q2.10 marksNumericalDijkstra's algorithm for shortest pathHideAnswer
What is shortest path algorithm? Use Dijkstra's algorithm to find shortest path between the vertices of a and z in the graph given below.[10]
- Q3.10 marksNumericalMerge sort algorithm and tracingHideAnswer
Explain merge sort along with its time complexity. Use this algorithm to sort array of numbers given below: 25, 37, 48, 25, 23, 17, 31, 45, 7, 21, 15, 8, 11[10]
- Q4.5 marksArray as an ADTHideAnswer
What is data Structure? Explain an array as an abstract data type. [5]
- Q5.5 marksBig O notation with examplesHideAnswer
Explain big oh(O) notation with suitable example. [5]
- Q6.5 marksPriority queue definition and implementatiHideAnswer
Define priority queue. How do you implement priority queue? Explain. [5]
- Q7.5 marksTower of Hanoi algorithm and tracingHideAnswer
Define recursion. Explain Tower of Hanoi algorithm in detail. [5]
- Q8.5 marksQueue implementation using linked listHideAnswer
How can you implement queue using linked list? Explain. [5]
- Q9.5 marksBinary tree definition and applicationsHideAnswer
What is binary tree? Explain different application of binary tree. [5]
- Q10.5 marksComparison between sequential and binary sHideAnswer
Explain sequential search. How is it different from binary search? [5]
- Q11.5 marksQuadratic probing collision resolutionHideAnswer
Define hashing. Explain quadratic probing with example. [5]
Hashing and Quadratic Probing
Definition of Hashing
Hashing is a technique used to map a key to a specific location (index) in a hash table using a hash function. The hash function computes an index from the key, allowing for O(1) average-case time complexity for insertion, deletion, and search operations.
Hash Function: $$h(k) = k \mod m$$ where
kis the key andmis the size of the hash table.A collision occurs when two different keys map to the same index. Various collision resolution techniques are used to handle this.
Quadratic Probing
Quadratic Probing is an open addressing collision resolution technique. When a collision occurs at index
h(k), instead of checking the next sequential slot (as in linear probing), it probes slots at quadratic intervals.Probe Sequence Formula:
$$h_i(k) = (h(k) + i^2) \mod m$$
where:
h(k)= initial hash valuei= probe number (i = 0, 1, 2, 3, ...)m= size of the hash table
Advantage over Linear Probing: Quadratic probing reduces primary clustering (long chains of consecutive filled slots).
Example
Insert the keys: 18, 26, 35, 9, 64 into a hash table of size m = 7
Hash function:
h(k) = k mod 7Key h(k) = k mod 7 Probe Final Index 18 18 mod 7 = 4 i=0, slot 4 is empty 4 26 26 mod 7 = 5 i=0, slot 5 is empty 5 35 35 mod 7 = 0 i=0, slot 0 is empty 0 9 9 mod 7 = 2 i=0, slot 2 is empty 2 64 64 mod 7 = 1 i=0, slot 1 is empty 1 Now insert key = 26 again (to show collision), suppose we insert key = 19:
h(19) = 19 mod 7 = 5→ slot 5 is occupied (collision!)- Probe i=1:
(5 + 1²) mod 7 = 6→ slot 6 is empty → insert at 6
Final Hash Table:
Index Key 0 35 1 64 2 9 3 -- 4 18 5 26 6 19
Summary
Feature Detail Probe formula h(k, i) = (h(k) + i²) mod mCollision handling Quadratic jumps Avoids Primary clustering Drawback May cause secondary clustering; may not probe all slots if mis not prime - Q12.5 marksGraph traversal definitionHideAnswer
What is graph traversal? Explain breadth first search. [5]