2074

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.

  1. 110 marksBinary Search Tree, Insertion, Deletion, TAnswer

    Illustrate the algorithm for Binary search tree with example.[10]

    A Binary Search Tree (BST) is a binary tree that is either empty or in which every node contains a key (value) and satisfies the following conditions: - All keys in the left sub-tree of the root are smaller than the key in the root node....

  2. 210 marksTypes of Linked ListAnswer

    What do you mean by circular list? Differentiate between stack as a circular list and Queue as a circular list.[10]

    A circular list is a linked list in which the last node points back to the first node, forming a closed loop or circle. Unlike a linear linked list where the last node points to NULL, in a circular list there is no NULL pointer -- every ...

  3. 310 marksAVL tree and Balancing algorithm, ApplicatAnswer

    Explain the procedure for construction of Huffman algorithm with example.[10]

    Huffman coding is a greedy algorithm used for lossless data compression. It assigns variable-length binary codes to characters based on their frequencies -- characters with higher frequencies get shorter codes and characters with lower f...

  4. 45 marksConversion from infix to postfix/prefix exAnswer

    Explain the infix to post fix conversion algorithm. [5]

    Infix notation is the standard mathematical notation where operators are placed between operands (e.g., A + B). Postfix notation (Reverse Polish Notation) places operators after their operands (e.g., A B +). The conversion uses a stack d...

  5. 55 marksFactorial, Fibonacci Sequence, GCD, Tower Answer

    Explain the Tower of Hanoi (TOH) with practical example. [5]

    Tower of Hanoi is a classic mathematical puzzle that is naturally recursive in nature. It involves moving a set of disks from one peg to another following specific rules. TOH is one of the best examples of a problem that is naturally rec...

  6. 65 marksTypes of Linked ListAnswer

    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:

    1. PREV (Left Link) - a pointer that points to the previous node in the list
    2. INFO (Data) - the actual data stored in the node
    3. 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

    FeatureDescription
    TraversalCan be done in both forward and backward directions
    PREV of first nodeAlways NULL
    NEXT of last nodeAlways NULL
    MemoryRequires more memory than singly linked list (extra pointer per node)

    Advantages of Doubly Linked List

    1. Bidirectional traversal is possible (forward and backward).
    2. Deletion of a node is easier because we can access the previous node directly without traversing from the beginning.
    3. 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.

  7. 75 marksConcept and Definitions, Basic Operations Answer

    What are the types of binary tree? Compare between them. [5]

    A binary tree is a finite set of elements that is either empty or partitioned into three disjoint subsets: the root, the left subtree, and the right subtree, where each subtree is itself a binary tree. --- A binary tree in which every no...

  8. 85 marksBinary Search Tree, Insertion, Deletion, TAnswer

    Differentiate between pre-order traversal and in order traversal. [5]

    Binary Tree Traversal means visiting each node in a tree exactly once in a systematic manner. Two of the three popular traversal methods are Pre-order and In-order traversal. --- The pre-order traversal of a non-empty binary tree is defi...

  9. 95 marksComparison Sorting AlgorithmsAnswer

    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 element a[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

    CaseComplexity
    Best CaseO(n^2)
    Average CaseO(n^2)
    Worst CaseO(n^2)

    Worked Example

    Array: [5, 3, 8, 1, 4]

    Pass 1 (i = 0)

    StepComparisonArray State
    j=05 > 3? Yes, swap[3, 5, 8, 1, 4]
    j=15 > 8? No[3, 5, 8, 1, 4]
    j=28 > 1? Yes, swap[3, 5, 1, 8, 4]
    j=38 > 4? Yes, swap[3, 5, 1, 4, 8]

    Largest element 8 is now at its correct position.

    Pass 2 (i = 1)

    StepComparisonArray State
    j=03 > 5? No[3, 5, 1, 4, 8]
    j=15 > 1? Yes, swap[3, 1, 5, 4, 8]
    j=25 > 4? Yes, swap[3, 1, 4, 5, 8]

    Second largest element 5 is now at its correct position.

    Pass 3 (i = 2)

    StepComparisonArray State
    j=03 > 1? Yes, swap[1, 3, 4, 5, 8]
    j=13 > 4? No[1, 3, 4, 5, 8]

    Pass 4 (i = 3)

    StepComparisonArray State
    j=01 > 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).
  10. 105 marksIntroduction to Searching, Search AlgorithAnswer

    Differentiate between sequential searching and binary searching. [5]

    --- Sequential searching is a method of finding a particular element in a list by checking each element one by one from the beginning until the desired element is found or the list ends. - The list need not be sorted. - Searching starts ...

  11. 115 marksDefinition and Representation of Graphs, GAnswer

    Discuss the Kruskal's algorithm with example. [5]

    Kruskal's algorithm is a greedy algorithm used to find the Minimum Spanning Tree (MST) of a connected, undirected, weighted graph. It builds the MST by selecting edges in increasing order of weight, skipping any edge that would form a cy...

  12. 125 marksData types, Data structure and Abstract daAnswer

    Differentiate between structure and union. [5]

    Structure: A structure is a user-defined data type in C/C++ that creates a data type used to group items of possibly different types into a single type. Each member of a structure has its own separate memory location. Union: A union is a...

  13. 135 marksAsymptotic notations and common functionsAnswer

    Describe the Big 'O' notation. [5]

    Big O notation is a mathematical notation that describes the limiting behaviour of a function when the argument tends towards a particular value or infinity. In computer science, Big O notation is used to classify algorithms according to...