ITM 252

Data Structure and Algorithms

TU BITM · Semester 4 · BITM curriculum and programme regulation

Requirement
required
Credits
3
Study Guide
9 units available

Chapter notes

Authoritative study guide across 9 syllabus units

Open a unit to read its study notes.

Unit 1: Introduction to data structure and algorithms· 4 LHs· ~5 marks

Part 1: Core Concepts (2 Marks)

  • Data Structure: A specialized format for organizing, processing, retrieving, and storing data in computer memory to enable efficient algorithmic operations.
  • Abstract Data Type (ADT): A mathematical model for data types defined strictly by its behavior and supported operations (e.g. Stack: push, pop, peek) rather than its specific underlying implementation.
  • Asymptotic Notations:
    • Big-OO (OO): Upper bound; worst-case growth rate: f(n)≤c⋅g(n)f(n) \le c \cdot g(n) for n≥n0n \ge n_0.
    • Big-Ω\Omega (Ω\Omega): Lower bound; best-case performance: f(n)≥c⋅g(n)f(n) \ge c \cdot g(n).
    • Big-Θ\Theta (Θ\Theta): Tight asymptotic bound: c1g(n)≤f(n)≤c2g(n)c_1 g(n) \le f(n) \le c_2 g(n).

Part 2: Structural Frameworks (10 Marks)

Standard Growth Rate Hierarchy

O(1)<O(log⁡n)<O(n)<O(nlog⁡n)<O(n2)<O(n3)<O(2n)<O(n!)O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)

Time Complexity Growth Visualization:

  • O(1): Constant time (Hash map lookup)
  • O(log n): Logarithmic (Binary search)
  • O(n): Linear (Single loop scan)
  • O(n log n): Linearithmic (MergeSort, QuickSort average)
  • O(n^2): Quadratic (Nested loops, BubbleSort)
  • O(2^n): Exponential (Recursive Fibonacci)

Part 3: Distinction Tables

Basis of Comparison Time Complexity Space Complexity
Metric Measured Computational CPU operations executed as input size nn scales. Auxiliary memory space allocated (stack + heap) during execution.
Trade-Off Often minimized by using auxiliary lookup tables (Hash Maps). Often reduced at the expense of additional CPU recalculation passes.

Part 4: Worked Problems & Exam Traps

Analyzing Nested Loop Time Complexity

int sum = 0;
for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
        sum++;
    }
}
  1. Outer loop runs for i=0,1,2,…,n−1i = 0, 1, 2, \dots, n - 1.
  2. Inner loop iterations sum:
    0+1+2+⋯+(n−1)=(n−1)n2=n2−n20 + 1 + 2 + \dots + (n - 1) = \frac{(n-1)n}{2} = \frac{n^2 - n}{2}
  3. Drop constants and lower-order terms: T(n)=O(n2)T(n) = O(n^2).

When loops divide by a factor (e.g. for (int i = 1; i < n; i *= 2)), the complexity is O(log⁡2n)O(\log_2 n), NOT O(n)O(n)!