CSC211 · TU past paper
Data Structures and Algorithms 2074 question paper
The complete TU 2074 exam paper for Data Structures and Algorithms (CSC211), all 13 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- Q1.10 marksBinary Search Tree, Insertion, Deletion, THideAnswer
Illustrate the algorithm for Binary search tree with example.[10]
- Q2.10 marksTypes of Linked ListHideAnswer
What do you mean by circular list? Differentiate between stack as a circular list and Queue as a circular list.[10]
- Q3.10 marksAVL tree and Balancing algorithm, ApplicatHideAnswer
Explain the procedure for construction of Huffman algorithm with example.[10]
- Q4.5 marksConversion from infix to postfix/prefix exHideAnswer
Explain the infix to post fix conversion algorithm. [5]
- Q5.5 marksFactorial, Fibonacci Sequence, GCD, Tower HideAnswer
Explain the Tower of Hanoi (TOH) with practical example. [5]
- Q6.5 marksTypes of Linked ListHideAnswer
What do you mean by double linked list? Explain with example. [5]
Double Linked List
Definition
A doubly linked list (also called a two-way linked list) is a linked list in which every node contains three fields:
- PREV (Left Link) - a pointer that points to the previous node in the list
- INFO (Data) - the actual data stored in the node
- NEXT (Right Link) - a pointer that points to the next node in the list
The PREV pointer of the first node and the NEXT pointer of the last node both contain NULL.
Node Structure
+--------+--------+--------+ | PREV | INFO | NEXT | +--------+--------+--------+In C, the node can be declared as:
struct node { struct node *prev; int info; struct node *next; };
Diagrammatic Example
Consider a doubly linked list containing three elements: 10, 20, 30
START | v +------+----+------+ +------+----+------+ +------+----+------+ | NULL | 10 | o---+--->| o---| 20 | o---+--->| o---| 30 | NULL | +------+----+------+ +------+----+------+ +------+----+------+ Node 1 <---+---o Node 2 <---+---o Node 3- Node 1: PREV = NULL, INFO = 10, NEXT = address of Node 2
- Node 2: PREV = address of Node 1, INFO = 20, NEXT = address of Node 3
- Node 3: PREV = address of Node 2, INFO = 30, NEXT = NULL
Key Characteristics
Feature Description Traversal Can be done in both forward and backward directions PREV of first node Always NULL NEXT of last node Always NULL Memory Requires more memory than singly linked list (extra pointer per node)
Advantages of Doubly Linked List
- Bidirectional traversal is possible (forward and backward).
- Deletion of a node is easier because we can access the previous node directly without traversing from the beginning.
- Insertion before a given node is simpler compared to singly linked list.
Disadvantage
- Each node requires an extra pointer (PREV), which uses more memory than a singly linked list.
Summary
A doubly linked list allows movement in both directions through the list, making operations like reverse traversal, deletion, and insertion more efficient compared to a singly linked list, at the cost of slightly more memory per node.
- Q7.5 marksConcept and Definitions, Basic Operations HideAnswer
What are the types of binary tree? Compare between them. [5]
- Q8.5 marksBinary Search Tree, Insertion, Deletion, THideAnswer
Differentiate between pre-order traversal and in order traversal. [5]
- Q9.5 marksComparison Sorting AlgorithmsHideAnswer
What do you mean by sorting? Explain the Bubble sort with example. [5]
Sorting and Bubble Sort
What is Sorting?
Sorting is the process of arranging data elements in a specific order (either ascending or descending) so that the data can be searched, accessed, or processed more efficiently. Sorting organizes a collection of data into a sequence ordered by some criterion.
Example: Arranging
[5, 2, 8, 1, 9]into[1, 2, 5, 8, 9](ascending order).
Bubble Sort
Definition: Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. The basic idea is to pass through the array sequentially several times. Each pass consists of comparing each element
a[i]with its adjacent elementa[i+1]and interchanging them if they are not in proper order.After each pass, the largest unsorted element "bubbles up" to its correct position at the end of the array.
Algorithm
for i = 0 to n-2: for j = 0 to n-2-i: if a[j] > a[j+1]: swap(a[j], a[j+1])Time Complexity
Case Complexity Best Case O(n^2) Average Case O(n^2) Worst Case O(n^2)
Worked Example
Array:
[5, 3, 8, 1, 4]Pass 1 (i = 0)
Step Comparison Array State j=0 5 > 3? Yes, swap [3, 5, 8, 1, 4]j=1 5 > 8? No [3, 5, 8, 1, 4]j=2 8 > 1? Yes, swap [3, 5, 1, 8, 4]j=3 8 > 4? Yes, swap [3, 5, 1, 4, 8]Largest element 8 is now at its correct position.
Pass 2 (i = 1)
Step Comparison Array State j=0 3 > 5? No [3, 5, 1, 4, 8]j=1 5 > 1? Yes, swap [3, 1, 5, 4, 8]j=2 5 > 4? Yes, swap [3, 1, 4, 5, 8]Second largest element 5 is now at its correct position.
Pass 3 (i = 2)
Step Comparison Array State j=0 3 > 1? Yes, swap [1, 3, 4, 5, 8]j=1 3 > 4? No [1, 3, 4, 5, 8]Pass 4 (i = 3)
Step Comparison Array State j=0 1 > 3? No [1, 3, 4, 5, 8]Final Sorted Array
[1, 3, 4, 5, 8]
Summary
- Bubble sort is simple but inefficient for large datasets due to O(n^2) complexity.
- It performs a maximum of n-1 passes for an array of n elements.
- It is an in-place sorting algorithm (no extra memory required).
- Q10.5 marksIntroduction to Searching, Search AlgorithHideAnswer
Differentiate between sequential searching and binary searching. [5]
- Q11.5 marksDefinition and Representation of Graphs, GHideAnswer
Discuss the Kruskal's algorithm with example. [5]
- Q12.5 marksData types, Data structure and Abstract daHideAnswer
Differentiate between structure and union. [5]
- Q13.5 marksAsymptotic notations and common functionsHideAnswer
Describe the Big 'O' notation. [5]