Complexity Analysis
Complexity Analysis
1
Time Complexity Space
Algorithms Best Case Average Case Worst case Complexity
Bubble Sort O(n) O(n²) O(n²) O(1)
Selection Sort O(n²) O(n²) O(n²) O(1)
Insertion Sort O(n) O(n²) O(n²) O(1)
Radix Sort O(nk) O(nk) O(nk) O(n+k)
Shell Sort O(n*logn) O(n*logn) OR O(n2) O(1)
O(n1.25)
Practical No. 2
Time Complexity Space
Algorithms Best Case Average Case Worst case Complexity
Linear Search O(1) O(n) O(n) O(1)
Binary Search O(1) O(logn) O(logn) O(1)
Practical No. 3
Push operation:
Time Complexity Space
Push() Best Case Average Case Worst case Complexity
Stack using O(1) O(1) O(n) O(1)
Array
Stack using O(1) O(1) O(1) O(1)
LinkedList
Pop operation:
Time Complexity Space
Pop() Best Case Average Case Worst case Complexity
Stack using O(1) O(1) O(1) O(1)
Array
Stack using O(1) O(1) O(1) O(1)
LinkedList
Peek operation:
Time Complexity Space
Peek() Best Case Average Case Worst case Complexity
Stack using O(1) O(1) O(1) O(1)
Array
Stack using O(1) O(1) O(1) O(1)
LinkedList
Practical No. 4
Stack Application:
Algorithms Time Complexity Space Complexity
Postfix Evaluation O(n) O(n)
Balancing of Parenthesis O(n) O(n)
Practical No. 5
Different types of Queue:
Data structure Time Complexity Space
enqueue dequeue peek complexity
Queue (using O(1) O(n) O(1) O(n)
Array)
Circular Queue O(1) O(1) O(1) O(n)
Priority Queue O(log n) O(log n) O(1) O(n)
Practical No. 6
Different types of LinkedList:
Insert():
Data Time Complexity
structure Add at head Add at tail Add in middle
Singly O(1) O(1) or O(n)
LinkedList O(n)
Doubly O(1) O(1) O(1)
LinkedList
Circular O(1) O(n) O(n)
LinkedList
Delete():
Data structure Time Complexity
Delete first Delete last Delete in middle
node node
Singly LinkedList O(1) O(n) O(n)
Search():
Operation Time Complexity
in LinkedList Singly Doubly Circular
LinkedList LinkedList LinkedList
Search() O(n) O(n) O(n)
Practical No. 7
Application of LinkedList:
Algorithms Time Space
Complexity Complexity
Polynomial O(m+n) O(m+n)
addition
Sparse O(mn) O(mn)
Matrix
O(m + n): where m and n are number of nodes in first and second
lists respectively.
O(mn): m= Number of Rows & n=Number of Columns.
Practical No. 11
Linear Probing (Hashing Technique):
Time Complexity Space
Operations Best Case Average Case Worst case Complexity
Insertion O(1) O(1) or O(n) O(n) O(1)
Deletion O(1) O(1) or O(n) O(n) O(1)
Search O(1) O(1) (good O(n) O(1)
hash function)
O(n) (bad hash
function)
Practical No. 8
Operations on BST(Binary Search tree):
Time Complexity Space
Operations Best Case Average Case Worst case Complexity
Insertion O(log n) O(log n) O(n) O(n)
Deletion O(log n) O(log n) O(n) O(n)
Search O(log n) O(log n) O(n) O(n)
Practical No. 9
Heap Implementation:
Time Complexity Space
Operations Best Case Average Case Worst case Complexity
Insertion O(1) O(log n) O(log n)
Deletion O(1) O(log n) O(log n)
O(n)
Sorting O(n*logn)
Heapify O(n)