Involves evaluating its performance, efficiency, and resource
usage to understand how it behaves under various conditions.
Analysis of an
Algorithm
Time Complexity:
Big O Notation (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.
Binary
search
O(log n)
Binary
search
O(log n)
O(n)
Merge
Sort
O(n log n)
Merge
Sort
O(n log n)
4 2 1 7 5
Bubble Sort
2 4 1 7 5
2 4 1 7 5
2 1 4 7 5
2 1 4 7 5
2 1 4 7 5
2 1 4 5 7
1st Loop
O(n2
)
Bubble Sort
2 1 4 5 7
2nd Loop
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
O(n2
)
Bubble Sort 3rd Loop
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
O(n2
)
Bubble Sort 4th Loop
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
1 2 4 5 7
O(n2
)
Space Complexity:
Big O Notation (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.
Best, Average, Worst Cases
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)

Analysis of Algorithms in Computer Science

  • 1.
    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.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
    4 2 17 5 Bubble Sort 2 4 1 7 5 2 4 1 7 5 2 1 4 7 5 2 1 4 7 5 2 1 4 7 5 2 1 4 5 7 1st Loop O(n2 )
  • 9.
    Bubble Sort 2 14 5 7 2nd Loop 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 O(n2 )
  • 10.
    Bubble Sort 3rdLoop 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 O(n2 )
  • 11.
    Bubble Sort 4thLoop 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 1 2 4 5 7 O(n2 )
  • 12.
    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)