Unit I: Linear Data Structures - Static and Linked Lists
Start here if you are new. This unit builds the vocabulary of algorithms and data structures, then moves from arrays to dynamic memory and linked lists.
11 hours12 topic blocks36 viva prompts
A0A1A2A3
10->25->40NULL
Introduction to Algorithms
A recipe for solving a computational problem.
Input: data given to the algorithm.
Output: answer produced by the algorithm.
Finiteness: it must stop after a limited number of steps.
Definiteness: every step must be unambiguous.
Think IPOF: Input, Processing, Output, Finish.
Algorithm Attributes and Design Techniques
How we describe and build algorithms.
Brute force tries straightforward possibilities.
Divide and conquer splits a problem into smaller similar problems.
Greedy chooses the best-looking immediate option.
Dynamic programming stores results of overlapping subproblems.
Design techniques are problem-solving patterns, not programming languages.
Time Space Trade Off
Use more memory to save time, or save memory and spend time.
Lookup tables store answers for reuse.
Caching saves repeated computation.
Sparse matrix representation saves memory but may make some operations more complex.
Sorting first may take time but makes later searching faster.
Extra memory can act like a shortcut.
Data Structures, Classification and Operations
Ways to organize data so operations become easier.
Primitive: int, char, float, pointer.
Linear: array, linked list, stack, queue.
Non-linear: tree, graph.
Static: size fixed before use, like a normal array.
Linear means one-after-another; non-linear means branching or network-like.
Growth of Functions and Master's Theorem
How running time grows when input grows.
O(1): constant time.
O(log n): logarithmic time.
O(n): linear time.
O(n log n): common for efficient sorting.
For Master Theorem, compare f(n) with n^(log_b a).
Arrays: 1D, 2D and Multi-Dimensional
Same-type elements stored in contiguous memory.
Index usually starts from 0 in C-like languages.
Random access is fast: O(1).
Insertion and deletion in the middle can be costly because shifting is needed.
2D arrays can be stored in row-major or column-major order.
Array = apartment building: room number gives direct location.
Memory Representation and Address Calculation
How locations are calculated from base address and index.
Base address is the address of the first element.
Element size depends on data type.
In row-major order, rows are stored one after another.
In column-major order, columns are stored one after another.
Address = starting point + distance.
Sparse Matrices: Types and Representation
Matrices with mostly zero values.
Triplet form stores row, column, value.
Header row often stores rows, columns, and number of non-zero values.
Diagonal matrix, triangular matrix, symmetric matrix, and band matrix are common sparse-like types.
Sparse storage reduces space when non-zero elements are few.
Do not store silence; store only the notes that are played.
Dynamic Memory Allocation
Memory requested while the program is running.
Stack memory is automatic and limited.
Heap memory is manually managed in languages like C.
C functions include malloc, calloc, realloc, and free.