You are on page 1of 2

Particular Space Complexity Time Complexity

Addition in ordered list
O(log N) to find the position
O(N) for elements shifting
Total O(log N) + O(N)
Linear Search O(1)
Best Case :- O(1)
Worst Case :- O(N)
Average Case :- O(N)
Binary Search O(1)
Best Case :- O(log (N))
Worst Case :-
Average Case :- O(logN)
Insertion Sort
Worst Case :- O(N*N)
Note:- Insertion Sort is
online & requires
Random Access Average Case :- O(N*N)
Merge Sort
O(N) for both Worst &
Average case
Worst Case :- O(N*logN)
Note:- Merge Sort is
not full online &
doesnot requires
Random Access Average Case :- O(N*logN)
Quick Sort O(N)
Best Case :- O(1)
Worst Case :- O(1)
Average Case :- O(N*logN)
Bucket or Bin Sort
where K is the range
size and N is number of
elements O(K) O(N)
Euclid Algorithm O(log(x)) due to call stack O(log(x))
O(1+a) where a is load factor
which is n/m. Where n is
number of elements and m is
size of table. And O(n) for
worst case
Ordered Dictionary
is equals to height of tree
Height of empty tree is 0
Height of non empty tree is 1 +
Height of Balanced tree is logN
Height of Unbalanced tree is N
Height of AVL tree is O(logN)
AVL Tree
O(h) where h is height which is
logN, so O(LogN)
Balanced BST O(N)
O(logN) for worst & average
Hashtable O(N)
O(1) for avg case and O(N) for
worst case
Heap (min heapify)

ceil(log N)
Heap (build heap) <=2N
O(N) for build heap + N*O(log
N) so O(N log N) total for worst
Depth First Tree
Traversal Height of tree O(N)
Breadth First Tree
Max number of nodes in
two consecutive levels O(N)
Knapsack Greedy
O(n*log n) for ordering + O(log
n) for while loop + O(n) for
finding minimum & assigimg to
remaining weight. Hence total
is O(n*log n)
Depth First Search
O(V) where V is the visted
O(d(V)) is the time per vertex
and Sum of all vertices visted is
the total time
Dijkastra Algorithm
O(n*log n) for intializing queue
and 1 + deg (u) *log n for while
loop. Hence total is O(m*log n)
All pairs shortest path
O(n*(m+n)*log n) & for dense
graph O(n cube *log n)
Minimum Spanning
Tree (Kruskal
O(m*logm+L(m,n)) where
L(m,n) is the cost of all cluster
operations and cluster means
unordered link list of vertices
Minimum Spanning
Tree (Prim`s Jarnik
Algorithm) O((m+n)*log n)