Answer:
Algorithmic Complexity
Algorithmic complexity refers to the amount of time and memory (space) an algorithm needs to
solve a problem, depending on the size of the input (n). It helps compare different algorithms and
choose the most efficient one.
It is expressed using Big O notation, which represents the growth rate of the algorithm’s running
time or memory usage.
The goal is to analyze and compare algorithms without implementing them, so we can choose
the one that performs better for large inputs.
Types of Algorithmic Complexity
There are mainly three types of time complexities used to describe algorithm performance:
1. Best-Case Complexity
• The best-case describes the minimum amount of time an algorithm will take to complete.
• It occurs when the input data is arranged in such a way that the algorithm finishes quickly
— an ideal situation.
Example:
In Linear Search, if we are searching for the first element of an array of size n, the algorithm will
find it immediately on the first comparison.
Hence,
𝑇(𝑛) = 𝑂(1)
This means it takes constant time, regardless of the input size.
2. Worst-Case Complexity
• The worst-case represents the maximum time an algorithm will take for any input of size
n.
• It shows the upper limit of running time and helps in guaranteeing performance even in
the worst possible conditions.
Example:
In Linear Search, if the element is not present in the array or is at the last position, the algorithm
must check all n elements.
Hence,
𝑇(𝑛) = 𝑂(𝑛)
This shows linear growth with the input size.
3. Average-Case Complexity
• The average-case represents the expected running time of an algorithm for a random
input.
• It gives a more realistic view of the algorithm’s performance compared to best or worst
cases.
Example:
In Linear Search, if the element is equally likely to be anywhere in the array, on average it will
be found after checking about half the elements.
Hence,
𝑛
𝑇(𝑛) = 𝑂 ) + , 𝑎𝑝𝑝𝑟𝑜𝑥 𝑂(𝑛)
2
So, even the average case for Linear Search grows linearly with input size.
Illustration with Example
Let’s consider a simple example using Binary Search on a sorted list of size n:
• Best Case: Element found in the middle at first check → 𝑂(1)
• Worst Case: 𝑂(𝑙𝑜𝑔 𝑛)
• Average Case: On average, about 𝑙𝑜𝑔₂𝑛/2 comparisons → 𝑂(𝑙𝑜𝑔 𝑛)
Why Algorithmic Complexity Matters
¨ Predicts performance before coding.
¨ Helps in choosing optimal algorithms for large inputs.
¨ Identifies bottlenecks and areas to improve.
¨ Ensures scalability of software systems.