Assignment1 Algorithm Complexity FullPPP
Assignment1 Algorithm Complexity FullPPP
Components of an Algorithm:
Output: The result produced by the algorithm after processing the input.
Correctness: Ensuring the algorithm produces the expected output for all valid
inputs.
Algorithm BubbleSort(A, n)
for i ← 0 to n-1 do
for j ← 0 to n-i-2 do
CO23317
ASSIGNMENT-1
Analysis of Algorithms:
Space Complexity: Measures the amount of memory an algorithm uses during its
execution.
Asymptotic Notations:
Big O Notation (O): Describes the upper bound of the time complexity,
representing the worst-case scenario.
Omega Notation (Ω): Describes the lower bound, representing the best-case
scenario.
Theta Notation (Θ): Describes a tight bound, indicating that the time complexity is
both upper and lower bounded by the same function.
O(1): Constant time – the algorithm's execution time does not depend on the input
size.
O(n): Linear time – execution time grows linearly with the input size.
O(n²): Quadratic time – execution time grows quadratically with the input size.
O(log n): Logarithmic time – execution time grows logarithmically as the input size
increases.
O(2ⁿ): Exponential time – execution time doubles with each additional input
element.
To visualize how different time complexities grow with input size, consider the following
graph:
In this graph:
O(n log n) grows faster than linear but slower than quadratic.
CO23317
ASSIGNMENT-1
O(2ⁿ) grows exponentially, becoming impractical for relatively small input sizes.
Theoretical Analysis:
currentMax ← A[0]
for I ← 1 to n – 1 do
currentMax ← A[I]
return currentMax
Performance Analysis
Criteria: Time complexity and space complexity.
CO23317
ASSIGNMENT-1
Asymptotic Notations
Big O Notation (O):
- Indicates the algorithm's running time grows at the same rate for both upper and lower
bounds.
CO23317