Purpose of Algorithm Analysis

Time Complexity Cases

Worked Example: Best, Worst, and Average Case — Linear Search

int linearSearch(int arr[], int n, int key) {
    for (int i = 0; i < n; i++) {
        if (arr[i] == key) return i;   // found
    }
    return -1;                          // not found
}

Key reasoning point: Big-O is quoted for the worst case unless a question specifically asks otherwise — Linear Search is described as "O(n)", not "O(1)", because O(n) is the guarantee holding for every possible input, not just a lucky one.

Exam angle: when FPSC asks for best/worst/average case complexity, always state a concrete input scenario for each ("best case: element already at index 0") rather than a vague description — examiners award marks for that concrete justification, not just the final O() label.


Space Complexity

Empirical vs Theoretical Analysis

Exam Angle