This page contains the complexities of different algorithms in this repository.
ALGORITHMS
ITERATIVE
SEARCHING
PATTERN SEARCHING
SORTING
STRINGS
BITWISE
MATHEMATICAL
GEOMETRIC
RANDOMIZED
DIVIDE AND CONQUER
BRANCH AND BOUND
GRAPHS
GREEDY
DYNAMIC PROGRAMMING
GAME THEORY
MISC
RECURSIVE
SEARCHING
LINEAR SEARCH
BINARY SEARCH
PATTERN SEARCHING
SORTING
STRINGS
BITWISE
MATHEMATICAL
GEOMETRIC
RANDOMIZED
DIVIDE AND CONQUER
BRANCH AND BOUND
GRAPHS
GREEDY
DYNAMIC PROGRAMMING
GAME THEORY
MISC
DATA STRUCTURES
ARRAYS
STRING
LISTS
STACKS
QUEUES
SIMPLE QUEUE
FIXED ARRAY SIMPLE QUEUE
DYNAMIC ARRAY SIMPLE QUEUE
LINKED SIMPLE QUEUE
CIRCULAR QUEUE
FIXED ARRAY CIRCULAR QUEUE
LINKED CIRCULAR QUEUE
PRIORITY QUEUE
FIXED ARRAY PRIORITY QUEUE
LINKED PRIORITY QUEUE
HEAPED PRIORITY QUEUE
HASHTABLE
TREES
BINARY TREE
GENERIC TREES
THREADED BINARY TREE
XOR TREES
BINARY SEARCH TREE
AVL TREES
RED BLACK TREES
SPLAY TREES
AUGMENTED TREES
SCAPEGOAT TREES
INTERVAL TREES
HEAP TREE
GRAPHS
BLOCKCHAIN
SNo.
Algorithm
Order of complexity O(n)
Type of Complexity
Iterative
1
Linear Search
O(n)
Linear
✔️
2
Binary Search
O(log n)
Logarithmic
✔️
SNo.
Algorithm
Order and type of Time complexity O(n)
Order and Type of Space Complexity
Stable/Unstable Sort
In Place Algorithm
1
Bubble Sort
O(n^2) -- Quadratic
O(1) -- Constant
Stable / Can be Unstable**
✔️
2
Selection Sort
O(n^2) -- Quadratic
O(1) -- Constant
Unstable
✔️
3
Insertion Sort
O(n^2) -- Quadratic
O(1) -- Constant
Stable
✔️
4
Shell Sort
O(n^2) or better -- Quadratic or other
Unstable
✔️
5
Counting Sort
O(n) -- Linear
Stable / Unstable
✖️
6
Radix Sort
O(n) or slower than O(nlogn) -- Linear / Logarithmic
Stable
Can Be
**Not an efficient Way
SNo.
Algorithm
Order of complexity O(n)
Type of Complexity
Recursive
1
Linear Search
O(n)
Linear
✔️
2
Binary Search
O(log n)
Logarithmic
✔️
SNo.
Algorithm
Order of complexity O(n)
Type of Complexity
Stable/Unstable Sort
In Place Algorithm
Space Complexity
1
Merge Sort
O(n logn)
Logarithmic
Stable
✖️
2
Quick Sort
O(n logn)
Logarithmic
Unstable
✔️
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n)
Linear
3
Deletion at beginning
O(n)
Linear
4
Insertion at end (empty array)
O(1)
Constant
5
Deletion at end (empty array)
O(1)
Constant
6
Deletion of the value without having index
O(n)
Linear
7
Update value without having index
O(n)
Linear
8
Update value having index
O(1)
Constant
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n^2)
Quadratic
3
Deletion at beginning
O(n^2)
Quadratic
4
Insertion at end (empty array)
O(1)
Constant
5
Deletion at end (empty array)
O(1)
Constant
6
Deletion of the value without having index
O(n^n)
Quadratic
7
Update value without having index
O(n^2)
Quadratic
8
Update value having index
O(1)
Constant
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n^3)
Cubic
3
Deletion at beginning
O(n^3)
Cubic
4
Insertion at end (empty array)
O(1)
Constant
5
Deletion at end (empty array)
O(1)
Constant
6
Deletion of the value without having index
O(n^3)
Cubic
7
Update value without having index
O(n^3)
Cubic
8
Update value having index
O(1)
Constant
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n^4)
Quadratic
3
Deletion at beginning
O(n^4)
Quadratic
4
Insertion at end (empty array)
O(1)
Constant
5
Deletion at end (empty array)
O(1)
Constant
6
Deletion of the value without having index
O(n^4)
Quadratic
7
Update value without having index
O(n^4)
Quadratic
8
Update value having index
O(1)
Constant
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n)
Linear
3
Deletion at beginning
O(n)
Linear
4
Insertion at end (empty array)
O(n)
Linear
5
Deletion at end (empty array)
O(n)
Linear
6
Deletion of the value without having index
O(n)
Linear
7
Update value without having index
O(n)
Linear
8
Update value having index
O(1)
Constant
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n^2)
Quadratic
3
Deletion at beginning
O(n^2)
Quadratic
4
Insertion at end (empty array)
O(n^2)
Quadratic
5
Deletion at end (empty array)
O(n^2)
Quadratic
6
Deletion of the value without having index
O(n^2)
Quadratic
7
Update value without having index
O(n^2)
Quadratic
8
Update value having index
O(1)
Constant
SNo.
Operations
Order of complexity O(n)
Type of Complexity
1
Use value by indexes
O(1)
Constant
2
Insertion at beginning
O(n^3)
Cubic
3
Deletion at beginning
O(n^3)
Cubic
4
Insertion at end (empty array)
O(n^3)
Cubic
5
Deletion at end (empty array)
O(n^3)
Cubic
6
Deletion of the value without having index
O(n^3)
Cubic
7
Update value without having index
O(n^3)
Cubic
8
Update value having index
O(1)
Constant
SNo.
Methods
Order of complexity O(n)
Type of Complexity
1
equals()
O(n)
Linear
2
toString()
O(n)
Linear
3
fill()
O(n)
Linear
4
sort()
O(n logn)
LinearLogarithmic
5
binarySearch()
O(log n)
Logarithmic
6
copyOf()
O(n)
Linear
SNo. | Methods | Order of complexity O(n) | Type of Complexity
1 | char charAt() | O(1) | Constant
2 | int indexOf() | O(n) | Linear
3 | lastIndexOf() | O(n) | Linear
4 | int length() | O(1) | Constant
5 | substring() | O(n) | Linear
6 | replace() | O(n) | Linear
7 | concat(str) | O(n^2) | Quadratic
8 | equals(str) | O(n) | Linear
9 | toUpperCase() | O(n) | Linear
10 | toLowerCase() | O(n) | Linear
SINGULAR LINKED LIST (having head and next)
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Traversing a list
O(n) -- Linear
O(1) -- Constant
2
Insertion at Head
O(1) -- Constant
O(1) -- Constant
3
Insertion at Tail
O(n) -- Linear
O(1) -- Constant
4
Insertion at Middle using Position
O(n) -- Linear
O(1) -- Constant
5
Insertion at Middle Exactly
O(n/2) -- Linear
O(1) -- Constant
6
Deletion from Head
O(1) -- Constant
O(1) -- Constant
7
Deletion from Tail
O(n) -- Linear
O(1) -- Constant
8
Deletion from Middle using Position
O(n) -- Linear
O(1) -- Constant
9
Deletion from Middle using Value
O(n) -- Linear
O(1) -- Constant
10
Deletion from Middle Exactly
O(n/2) -- Linear
O(1) -- Constant
11
Linear Search
O(n) -- Linear
O(1) -- Constant
12
Clear list
O(1) -- Constant
O(1) -- Constant
HYBRID SINGULAR LINKED LIST (having head,tail and next)
DOUBLE LINKED LIST (having head,tail and next,prev)
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Traversing a list (from left or right)
O(n) -- Linear
O(1) -- Constant
2
Insertion at Head
O(1) -- Constant
O(1) -- Constant
3
Insertion at Tail
O(1) -- Constant
O(1) -- Constant
4
Insertion at Middle using Position
O(n) -- Linear
O(1) -- Constant
5
Insertion at Middle Exactly
O(n/2) -- Linear
O(1) -- Constant
6
Deletion from Head
O(1) -- Constant
O(1) -- Constant
7
Deletion from Tail
O(1) -- Constant
O(1) -- Constant
8
Deletion from Middle using Position
O(n) -- Linear
O(1) -- Constant
9
Deletion from Middle using Value
O(n) -- Linear
O(1) -- Constant
10
Deletion from Middle Exactly
O(n/2) -- Linear
O(1) -- Constant
11
Linear search
O(n) -- Linear
O(1) -- Constant
12
Clear list
O(1) -- Constant
O(1) -- Constant
13
Optimal Search
O(n/2) -- Linear
O(1) -- Constant
HYBRID DOUBLE LINKED LIST (having head,prev and next)
STANDARD CIRCULAR LINKED LIST
(having tail ,next and loop)
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Traversing a list (from left to right to head)
O(n) -- Linear
O(1) -- Constant
2
Insertion at Head
O(1) -- Constant
O(1) -- Constant
3
Insertion at Tail
O(1) -- Constant
O(1) -- Constant
4
Deletion from Head
O(1) -- Constant
O(1) -- Constant
5
Deletion from Tail
O(n) -- Linear
O(1) -- Constant
6
Deletion from middle using value
O(n) -- Linear
O(1) -- Constant
6
Linear search
O(n) -- Linear
O(1) -- Constant
7
Clear list
O(1) -- Constant
O(1) -- Constant
CIRCULAR LINKED LIST VARIANT 1
(having head ,next and loop)
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Traversing a list (from left to right to head)
O(n) -- Linear
O(1) -- Constant
2
Insertion at Head
O(n) -- Linear
O(1) -- Constant
3
Insertion at Tail
O(n) -- Linear
O(1) -- Constant
4
Insertion at Middle
O(n) -- Linear
O(1) -- Constant
4
Deletion from Head
O(n) -- Linear
O(1) -- Constant
5
Deletion from Tail
O(n) -- Linear
O(1) -- Constant
6
Deletion from middle
O(n) -- Linear
O(1) -- Constant
7
Linear search
O(n) -- Linear
O(1) -- Constant
8
Clear list
O(1) -- Constant
O(1) -- Constant
9
Length of list
O(1) -- Constant
O(1) -- Constant
MEMORY EFFICIENT (XOR) DOUBLE LINKED LIST
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Traversing a list
O(n) -- Linear
O(1) -- Constant
2
add(element) -- Insertion at Tail
O(1) -- Constant
O(1) -- Constant
3
add(index,element) -- Insertion at Middle using index
O(n) -- Linear
O(1) -- Constant
4
remove(index) -- Deletion from Middle using index
O(n) -- Linear
O(1) -- Constant
5
contains(element) -- Search List
O(n) -- Linear
O(1) -- Constant
6
get(index) -- Accessing random element
O(1) -- Constant
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
Find the nth node from end in single linked list
SNo.
APPROACH
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Compute the size while adding
O(n) -- Linear
O(1) -- Constant
2
Using two current pointers
O(n^2) -- Quadratic
O(1) -- Constant
3
Using hashtable
O(n) -- Linear
O(n) -- Linear
4
Using Hashtable while adding
O(1) -- Constant
O(n) -- Linear
5
Finding node in one scan
O(n) -- Linear
O(1) -- Constant
6
Using recursion
O(n) -- Linear
O(n) -- Linear
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Push an element or Insert element
O(1) -- Constant
O(1) -- Constant
2
Pop an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Get value of top
O(1) -- Constant
O(1) -- Constant
4
Is empty or not
O(1) -- Constant
O(1) -- Constant
5
Printing the stack
O(n) -- Linear
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Push an element or Insert element
O(n) -- Linear
O(log(n)) -- Logarithmic
2
Pop an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Get value of top
O(1) -- Constant
O(1) -- Constant
4
Is empty or not
O(1) -- Constant
O(1) -- Constant
5
Printing the stack
O(n) -- Linear
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Push an element or Insert element
O(1) -- Constant
O(1) -- Constant
2
Pop an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Get value of top
O(1) -- Constant
O(1) -- Constant
4
Is empty or not
O(1) -- Constant
O(1) -- Constant
5
Printing the stack/deletestack
O(n) -- Linear
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Enqueue an element or Insert element
O(1) -- Constant
O(1) -- Constant
2
Dequeue an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Print the queue
O(n) -- Linear
O(1) -- Constant
4
Size of the queue
O(1) -- Constant
O(1) -- Constant
5
Queue is Empty or not
O(1) -- Constant
O(1) -- Constant
DYNAMIC ARRAY SIMPLE QUEUE
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Enqueue an element or Insert element
O(1) -- Constant
O(log n) -- Logarthmic
2
Dequeue an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Print the queue
O(n) -- Linear
O(1) -- Constant
4
Size of the queue
O(1) -- Constant
O(1) -- Constant
5
Queue is Empty or not
O(1) -- Constant
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Enqueue an element or Insert element
O(n) -- Linear
O(1) -- Constant
2
Dequeue an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Print the queue
O(n) -- Linear
O(1) -- Constant
4
Size of the queue
O(1) -- Constant
O(1) -- Constant
5
Queue is Empty or not
O(1) -- Constant
O(1) -- Constant
FIXED ARRAY CIRCULAR QUEUE
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Enqueue an element or Insert element
O(1) -- Constant
O(1) -- Constant
2
Dequeue an element or Delete element
O(1) -- Constant
O(1) -- Constant
3
Print the queue
O(n) -- Linear
O(1) -- Constant
4
Size of the queue
O(1) -- Constant
O(1) -- Constant
5
Queue is Empty or not
O(1) -- Constant
O(1) -- Constant
FIXED ARRAY PRIORITY QUEUE
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Insert element with priority
O(n) -- Linear
O(1) -- Constant
2
Delete element with highest priority
O(n) -- Constant
O(1) -- Constant
3
Print the queue
O(n) -- Linear
O(1) -- Constant
4
Size of the queue
O(1) -- Constant
O(1) -- Constant
5
Queue is Empty or not
O(1) -- Constant
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
1
Insert element with priority
O(n) -- Linear
O(1) -- Constant
2
Delete element with highest priority
O(1) -- Constant
O(1) -- Constant
3
Print the queue
O(n) -- Linear
O(1) -- Constant
4
Size of the queue
O(1) -- Constant
O(1) -- Constant
5
Queue is Empty or not
O(1) -- Constant
O(1) -- Constant
SNo.
Operations
Order and Type of Time Complexity O(n)
Order and Type of Space Complexity
Iterative
Recursive
1
In Order Traversal
O(n) -- Linear
O(n) -- Linear
✔️
✔️
2
Pre Order Traversal
O(n) -- Linear
O(n) -- Linear
✔️
✔️
3
Post Order Traversal
O(n) -- Linear
O(n) -- Linear
✔️
✔️
4
Level Order Traversal
O(n) -- Linear
O(n) -- Linear
✔️
❌
5
Bottom View of a Tree
O(n) -- Linear
O(n) -- Linear
✔️
❌