Worst Case Time Complexity of Algorithms

Worst Case Time Complexity of Algorithms

Data Structures:

  • Array: Access O(1), Search O(n), Insertion O(n), Deletion O(n)

  • Linked List: Access O(n), Search O(n), Insertion O(1), Deletion O(1)

  • Stack: Access O(n), Search O(n), Insertion O(1), Deletion O(1)

  • Queue: Access O(n), Search O(n), Insertion O(1), Deletion O(1)

  • Binary Search Tree: Access O(log n), Search O(log n), Insertion O(log n), Deletion O(log n)

  • Heap: Access O(1), Search O(n), Insertion O(log n), Deletion O(log n)

  • Hash Table: Access O(1), Search O(1), Insertion O(1), Deletion O(1)

Algorithms:

  • Linear Search: O(n)

  • Binary Search: O(log n)

  • Bubble Sort: O(n^2)

  • Selection Sort: O(n^2)

  • Insertion Sort: O(n^2)

  • Quick Sort: O(n log n) average case, O(n^2) worst case

  • Merge Sort: O(n log n)

  • Heap Sort: O(n log n)

  • Counting Sort: O(n + k), where k is the range of the input

  • Radix Sort: O(d(n+k)), where d is the number of digits in the maximum number and k is the range of the input

  • Breadth-First Search: O(V + E), where V is the number of vertices and E is the number of edges in the graph

  • Depth-First Search: O(V + E), where V is the number of vertices and E is the number of edges in the graph

  • Dijkstra's Algorithm: O((V+E) log V), where V is the number of vertices and E is the number of edges in the graph

  • Bellman-Ford Algorithm: O(VE), where V is the number of vertices and E is the number of edges in the graph

  • Floyd-Warshall Algorithm: O(V^3), where V is the number of vertices in the graph

Note that these time complexities represent the worst-case scenario, and actual running times may vary depending on factors such as input size and data distribution.

Did you find this article valuable?

Support Sawan Kumar Jha by becoming a sponsor. Any amount is appreciated!