Data Structure And Algorithms Complexity (Big-O)

Big-O notation is a mathematical representation used to describe the complexity of a data structure and algorithm. There are two types of Complexity :

  1. Time Complexity: Its measure based on steps need to follow for an algorithm.
  2. Space Complexity: It measures the space required to perform an algorithm and data structure.

Data Structure and Algorithm Decision

Data structure and algorithm decisions are based on the complexity of size and operations need to perform on data. Some algorithms perform better on a small set of data while others perform better for big data sets for certain operations.

These days Space Complexity is not big concerns but the main performance of an algorithm measures based on time complexity. We can make the decision to choose an algorithm based on below performance criteria with respect to Complexity.

ComplexityPerformance
O(1)Excellent
O(log(n))Good
O(n)Fair
O(n log(n))Bad
O(n^2)Horrible
O(2^n)Horrible
O(n!)Horrible
Complexity Level

This post almost covers data structure and algorithms space and time Big-O complexities. Here you can also see time complexities for types of operations like access, search, insertion, and deletion.

See also: 

Data Structure Space and Time Complexity

Data StructureTime ComplexitySpace Complexity
AverageWorst
AccessSearchInsertionDeletion
ArrayΘ(1)Θ(n)Θ(n)Θ(n)O(n)
StackΘ(n)Θ(n)Θ(1)Θ(1)O(n)
QueueΘ(n)Θ(n)Θ(1)Θ(1)O(n)
Singly-Linked ListΘ(n)Θ(n)Θ(1)Θ(1)O(n)
Doubly-Linked ListΘ(n)Θ(n)Θ(1)Θ(1)O(n)
Skip ListΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n log(n))
Hash TableN/AΘ(1)Θ(1)Θ(1)O(n)
Binary Search TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Cartesian TreeN/AΘ(log(n))Θ(log(n))Θ(log(n))O(n)
B-TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Red-Black TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Splay TreeN/AΘ(log(n))Θ(log(n))Θ(log(n))O(n)
AVL TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
KD TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Data Structure Complexity

Sorting Algorithms Space and Time Complexity

AlgorithmTime ComplexitySpace Complexity
BestAverageWorstWorst
Quick SortΩ(n log(n))Θ(n log(n))O(n^2)O(log(n))
Merge SortΩ(n log(n))Θ(n log(n))O(n log(n))O(n)
Tim SortΩ(n)Θ(n log(n))O(n log(n))O(n)
Heap SortΩ(n log(n))Θ(n log(n))O(n log(n))O(1)
Bubble SortΩ(n)Θ(n^2)O(n^2)O(1)
Insertion SortΩ(n)Θ(n^2)O(n^2)O(1)
Selection SortΩ(n^2)Θ(n^2)O(n^2)O(1)
Tree SortΩ(n log(n))Θ(n log(n))O(n^2)O(n)
Shell SortΩ(n log(n))Θ(n(log(n))^2)O(n(log(n))^2)O(1)
Bucket SortΩ(n+k)Θ(n+k)O(n^2)O(n)
Radix SortΩ(nk)Θ(nk)O(nk)O(n+k)
Counting SortΩ(n+k)Θ(n+k)O(n+k)O(k)
Cube SortΩ(n)Θ(n log(n))O(n log(n))O(n)
Sorting Algorithms Complexity

Let me know your thought on it.

Happy Learning !!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s