0% found this document useful (0 votes)
79 views

Complexity Analysis

The document summarizes the time and space complexity of various algorithms and data structures. It covers sorting algorithms like bubble sort, selection sort, insertion sort, and radix sort. It also discusses searching algorithms like linear search and binary search. Additional topics covered include stacks, queues, linked lists, trees, hashing and heaps. For each algorithm or data structure, the best case, average case and worst case time complexity and space complexity are provided.

Uploaded by

Atul Vishwakarma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Complexity Analysis

The document summarizes the time and space complexity of various algorithms and data structures. It covers sorting algorithms like bubble sort, selection sort, insertion sort, and radix sort. It also discusses searching algorithms like linear search and binary search. Additional topics covered include stacks, queues, linked lists, trees, hashing and heaps. For each algorithm or data structure, the best case, average case and worst case time complexity and space complexity are provided.

Uploaded by

Atul Vishwakarma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical No.

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)

Radix Sort: n-Length of Array & k-Number of digits.

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)

Doubly O(1) O(1) O(1)


LinkedList
Circular O(1) O(n) O(n)
LinkedList

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)

Operation Time Complexity Space Complexity


BST Height O(n) O(n)
n-No. of Nodes in BST
Pre Order Traversal O(n) O(1) OR O(h)
Post Order Traversal n-Size of Binary Tree h-Height of Tree
In-Order Traversal

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)

You might also like