Open In App
Related Articles

Time complexities of different data structures

Improve Article
Improve
Save Article
Save
Like Article
Like

Time Complexity is a concept in computer science that deals with the quantification of the amount of time taken by a set of code or algorithm to process or run as a function of the amount of input. In other words, the time complexity is how long a program takes to process a given input. The efficiency of an algorithm depends on two parameters:

  • Time Complexity
  • Space Complexity

Time Complexity: It is defined as the number of times a particular instruction set is executed rather than the total time taken. It is because the total time taken also depends on some external factors like the compiler used, the processor’s speed, etc.

Space Complexity: It is the total memory space required by the program for its execution.

                     Best case time complexity of different data structures for different operations 

Data structureAccessSearchInsertionDeletion
ArrayO(1)O(1)O(1)O(1)
StackO(1)O(1)O(1)O(1)
QueueO(1)O(1)O(1)O(1)
Singly Linked listO(1)O(1)O(1)O(1)
Doubly Linked ListO(1)O(1)O(1)O(1)
Hash TableO(1)O(1)O(1)O(1)
Binary Search TreeO(log n)O(log n)O(log n)O(log n)
AVL TreeO(log n)O(log n)O(log n)O(log n)
B TreeO(log n)O(log n)O(log n)O(log n)
Red Black TreeO(log n)O(log n)O(log n)O(log n)

Worst Case time complexity of different data structures for different operations

Data structureAccessSearchInsertionDeletion
ArrayO(1)O(N)O(N)O(N)
StackO(N)O(N)O(1)O(1)
QueueO(N)O(N)O(1)O(1)
Singly Linked listO(N)O(N)O(N)O(N)
Doubly Linked ListO(N)O(N)O(1)O(1)
Hash TableO(N)O(N)O(N)O(N)
Binary Search TreeO(N)O(N)O(N)O(N)
AVL TreeO(log N)O(log N)O(log N)O(log N)
Binary TreeO(N)O(N)O(N)O(N)
Red Black TreeO(log N)O(log N)O(log N)O(log N)

The average time complexity of different data structures for different operations

Data structureAccessSearchInsertionDeletion
ArrayO(1)O(N)O(N)O(N)
StackO(N)O(N)O(1)O(1)
QueueO(N)O(N)O(1)O(1)
Singly Linked listO(N)O(N)O(1)O(1)
Doubly Linked ListO(N)O(N)O(1)O(1)
Hash TableO(1)O(1)O(1)O(1)
Binary Search TreeO(log N)O(log N)O(log N)O(log N)
AVL TreeO(log N)O(log N)O(log N)O(log N)
B TreeO(log N)O(log N)O(log N)O(log N)
Red Black TreeO(log N)O(log N)O(log N)O(log N)
Last Updated : 18 Nov, 2022
Like Article
Save Article
Similar Reads
Related Tutorials