BCA / B.Tech 6 min read

Algorithm of Time Complexity

Algorithm of Time Complexity in Data Structures:


Time complexity is a measure of the time taken for the execution of an algorithm. It is usually represented according to the size of the input and is expressed in Big O Notation. Here we will understand time complexity through an example of a simple algorithm.

Basic Rules of Time Complexity:
  • Worst Case: The situation in which the algorithm will take the most time.
  • Best Case: The situation in which the algorithm will take the least time.
  • Average Case: The average time of all possible situations.

Algorithm of Time Complexity:
Let's say we have the task of creating a Fibonacci Sequence for a number. The time complexity of a simple recursive algorithm for this is O(2^n). This means that for every function call, two more function calls are made, creating a binary tree-like structure. The number of nodes in this tree is close to 2^n.

Types of Time Complexity:
  • O(1) - Constant Time Complexity
  • O(n) - Linear Time Complexity
  • O(n^2) - Quadratic Time Complexity
  • O(log n) - Logarithmic Time Complexity