CSC211 · TU past paper
Data Structures and Algorithms 2079 question paper
The complete TU 2079 exam paper for Data Structures and Algorithms (CSC211), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- 110 marksNumericalAVL tree and Balancing algorithm, ApplicatHideAnswer
Why do we need to balance the binary search tree? Justify with an example. Create an AVL tree from the data 24, 12, 8, 15, 35, 30, 57, 40, 45, 78.[10]
A binary search tree gives $O(\log n)$ search, insertion and deletion only while its height stays close to $\log2 n$. The shape of the tree, however, depends entirely on the order in which the keys arrive, and nothing in the plain insert...
- 210 marksNumericalConversion from infix to postfix/prefix exHideAnswer
How recursive algorithm uses stack to store intermediate results? Illustrate with an example. Convert the infix expression A+B*(C/D+F)-G/H into postfix expression using stack.[10]
- Task 1: Explain how a recursive algorithm uses a stack for intermediate results, with an example. - Task 2 (numeric/symbolic): Infix expression to convert to postfix: $$A + B \times (C / D + F) - G / H$$ - Method required: Stack-based ...
- 310 marksBasic operations in Linked ListHideAnswer
How do you insert and delete a node at kth position of the doubly linked list? Describe the process of implementing stack and queue using linked list.[10]
--- A doubly linked list node has three fields: - prev -- pointer to previous node - info -- data field - next -- pointer to next node Step Action -------------- Step 1 Allocate memory for new node and assign data Step 2 If position is 1...
- 45 marksNumericalComparison Sorting AlgorithmsHideAnswer
Sort the numbers 82, 73, 12, 39, 26, 88, 2, 9, 60, 41 using shell sort. [5]
Array (n = 10), 1-indexed: Index 1 2 3 4 5 6 7 8 9 10 -------------------------------------- Value 82 73 12 39 26 88 2 9 60 41 Increment sequence chosen: $k = 5, 3, 1$ (the standard textbook choice $\lfloor n/2 \rfloor, \dots$; here fixe...
- 55 marksIntroduction to Searching, Search AlgorithHideAnswer
Write a program to implement binary search. [5]
Binary search works on a sorted array by repeatedly dividing the search interval in half. It compares the target key with the middle element and narrows the search to the left or right sub-list accordingly. --- --- --- --- Step l r m a[m...
- 65 marksNumericalDefinition and Representation of Graphs, GHideAnswer
Find the MST of following graph using Prim's algorithm. [5]
The question asks to find the MST of a graph using Prim's algorithm and provides "the following graph." However, no graph image, vertex list, edge list, or weight values are actually included in the text provided to me. Missing data: - T...
- 75 marksNumericalHashingHideAnswer
Assume you have to store the data {0,1,2,4,5,7} into a hash table of size 5, with hash function, $h(x) = x % 5$. Apply linear probing and double hashing as collision resolution techniques. [5]
- Data set (in insertion order): {0, 1, 2, 4, 5, 7} → 6 keys - Hash table size: m = 5 (slots 0 to 4) - Primary hash function: h(x) = x % 5 Observation: 6 keys into a table of size 5 means the table can hold at most 5 keys. The 6th key mu...
- 85 marksNumericalDivide and Conquer SortingHideAnswer
In which case the position of pivot element in quick sort always either in the last or the first position? Create a max heap from the numbers {10,12,53,34,23,77,59,66,5,8}. [5]
- Numbers to build max heap: ${10, 12, 53, 34, 23, 77, 59, 66, 5, 8}$ (10 elements) --- The pivot ends up in the first or last position after partitioning when the array is already sorted (ascending or descending), assuming the pivot i...
- 95 marksNumericalConversion from infix to postfix/prefix exHideAnswer
Evaluate the postfix expression 574-*8/4+ using stack. [5]
Evaluating Postfix Expression:
5 7 4 - * 8 / 4 +Given Data
- Postfix expression:
5 7 4 - * 8 / 4 + - Data structure to use: Stack
Algorithm (Postfix Evaluation)
- Scan the expression left to right.
- If the symbol is an operand, push it onto the stack.
- If the symbol is an operator, pop the top two operands:
op2= first pop (right operand)op1= second pop (left operand)- Compute
op1 <operator> op2and push the result.
- The final remaining stack element is the result.
Step-by-Step Trace
Step Symbol Action Stack (bottom → top) 1 5Push 5 5 2 7Push 7 5, 7 3 4Push 4 5, 7, 4 4 -Pop 4, Pop 7 → $7 - 4 = 3$; Push 3 5, 3 5 *Pop 3, Pop 5 → $5 \times 3 = 15$; Push 15 15 6 8Push 8 15, 8 7 /Pop 8, Pop 15 → $15 / 8$; Push result ... 8 4Push 4 (result), 4 9 +Pop 4, Pop (result) → add; Push final
Handling the Division at Step 7
The value $15 / 8 = 1.875$.
Case A: Integer division (common in textbook/C-style examples): $$15 / 8 = 1$$ Then:
- Step 8: Push 4 → stack:
1, 4 - Step 9: $1 + 4 = 5$
Final result = 5
Case B: Real (floating-point) division: $$15 / 8 = 1.875$$ Then:
- Step 8: Push 4 → stack:
1.875, 4 - Step 9: $1.875 + 4 = 5.875$
Final result = 5.875
Result
Since this is a data structures problem typically evaluated with integer arithmetic, the standard exam answer is:
$$\boxed{5\ 7\ 4\ -\ *\ 8\ /\ 4\ +\ =\ 5}$$
(If real-number division is intended, the result would be $5.875$.)
The trace gives a final value of 5 (using integer division).
- Postfix expression:
- 105 marksAsymptotic notations and common functionsHideAnswer
Why do we need asymptotic notation? Describe about Big oh notation with its curve. [5]
Asymptotic Notation and Big Oh Notation
Why Do We Need Asymptotic Notation? (2 marks)
When we analyze algorithms, we need a way to measure and compare their efficiency (time and space) without depending on machine speed, programming language, or hardware. Asymptotic notation provides a mathematical framework to describe the behavior of an algorithm as the input size grows toward infinity.
Key reasons we need asymptotic notation:
- To compare two algorithms independently of machine or implementation details.
- To describe the growth rate of an algorithm's running time or space requirement.
- To focus on the dominant term of a function and ignore constants and lower-order terms, which become insignificant for large inputs.
- To express best case, worst case, and average case complexity in a standard, concise way.
For example, if an algorithm takes T(n) = 5n² + 3n + 10 steps, asymptotic notation lets us simply say it grows as n², ignoring less significant terms.
Big Oh Notation O(g(n)) (3 marks)
Definition:
"When we have only asymptotic upper bound then we use O notation. If f and g are any two functions from set of integers then function f(x) is said to be big Oh of g(x)."
Formally:
f(n) = O(g(n)) if and only if there exist positive constants c and n₀ such that:
$$f(n) \leq c \cdot g(n) \quad \text{for all } n \geq n_0$$
- f(n) is the actual running time of the algorithm.
- g(n) is the bounding function (upper bound).
- c and n₀ are positive constants.
This means Big Oh gives the worst-case or upper bound on the growth of an algorithm.
Example
If f(n) = 4n + 2, then:
- 4n + 2 ≤ 5n for all n ≥ 2
- So f(n) = O(n), with c = 5 and n₀ = 2
Curve / Graphical Representation
Running Time | c * g(n) | ./ | ./ | .../ <-- f(n) always stays | .../ below c*g(n) after n₀ | .../ | .../ |../ |_________________________ n n₀- For all values of n ≥ n₀, the curve of f(n) lies at or below the curve of c * g(n).
- Big Oh notation thus represents the asymptotic upper bound.
Key Points
Property Description Notation O(g(n)) Meaning Upper bound on running time Use case Worst-case analysis Condition f(n) ≤ c * g(n) for all n ≥ n₀ Common Big Oh Complexities (Best to Worst)
$$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(2^n) < O(n!)$$
Conclusion: Big Oh notation is the most widely used asymptotic notation because it tells us the maximum time an algorithm will ever take, helping us guarantee performance in the worst case.
- 115 marksLinear Queue, Circular Queue, Priority QueHideAnswer
Define queue. Explain about enqueue and dequeue operation in circular queue. [5]
A queue is a linear data structure that follows the FIFO (First In First Out) principle, meaning the element inserted first is the one deleted first. Elements are inserted at the rear end and deleted from the front end. Common operations...
- 125 marksLinear Queue, Circular Queue, Priority QueHideAnswer
Write short notes on: a. Priority Queue b. Breadth First traversal of a graph [5]
--- A priority queue is a collection of elements in which each element has been assigned a priority value, and the order of deletion and processing is governed by the following rules: 1. An element of higher priority is processed before ...