CompSci Notes online part 1.
Overview of Complexity
Focuses on Time Complexity (execution time) rather than code logic.
Storage Complexity (memory usage) is a secondary consideration.
Execution time depends on hardware; thus, efficiency is measured by the number of statement executions relative to input size .
Comparing Algorithms
Method 1 (Nested Loops): Iterates through rows and columns ( and ). Total executions amount to , or for a square matrix.
Method 2 (Single Loop): Iterates through the diagonal once (). Total executions amount to , or .
Big O Notation Principles
Definition: Predicts growth rate of runtime as input size increases.
Rules for Calculation:
Focus on the highest order term (e.g., dominates ).
Ignore constants (e.g., becomes ; becomes ).
Multiple variables must be preserved (e.g., becomes ).
Common Big O Classes
(Constant): Runtime is independent of input size.
(Logarithmic): Runtime increases slowly.
(Linear): Runtime increases proportionally with input.
(Quadratic): Runtime increases dramatically as grows.
Practical Application
Analyzing real code allows developers to choose the most efficient algorithm based on predicted scaling behavior rather than just correctness.