Involves evaluating itsperformance, efficiency, and resource
usage to understand how it behaves under various conditions.
Analysis of an
Algorithm
2.
Time Complexity:
Big ONotation (O):
Describes the upper bound or worst-case time complexity.
Time Complexities:
O(1): Constant time, e.g., accessing an array element, assigning a value
O(log n): Logarithmic time, e.g., binary search.
O(n): Linear time, e.g., iterating through a list.
O(n log n): Linearithmic time, e.g., merge sort.
O(n2
): Quadratic time, e.g., bubble sort.
O(2n
): Exponential time, e.g., recursive algorithms like the Fibonacci sequence.
Measures the amount of time an algorithm takes to run as a
function of the input size (n). It focuses on how the running time
grows as the input size increases.
Space Complexity:
Big ONotation (O):
Describes the upper bound or worst-case time complexity.
It considers the extra space required, excluding input data.
Measures the amount of memory an algorithm uses relative to
the input size. It includes memory for variables, data structures,
and function call overheads.
13.
Best, Average, WorstCases
Best Case
The scenario where the algorithm performs most efficiently
(minimum time).
Worst Case
The scenario where the algorithm performs least efficiently
(maximum time).
Average Case
The expected time for typical inputs. Taking all possible inputs and
calculate computing time for all the inputs. (average time or typical)