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-
( ): Upper bound; worst-case growth rate: for . - Big-
( ): Lower bound; best-case performance: . - Big-
( ): Tight asymptotic bound: .
- Big-
Part 2: Structural Frameworks (10 Marks)
Standard Growth Rate Hierarchy
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 |
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++;
}
}
- Outer loop runs for
. - Inner loop iterations sum:
- Drop constants and lower-order terms:
.
When loops divide by a factor (e.g.
for (int i = 1; i < n; i *= 2)), the complexity is, NOT !