-
O(n!): Factorial time complexity, represents the complexity of an algorithm where the time it takes to complete grows factorially with the input size n.
-
O(1): Constant time complexity, operations that take the same time regardless of input size.
-
O(n): Linear time complexity, operations that scale linearly with input size.
-
O(n2): Quadratic time complexity, operations that involve nested iterations over input data.
-
O(log n): Logarithmic time complexity, operations that reduce the problem size in each step.
-
O(n log n): Log-linear time complexity, operations that divide the problem into smaller subproblems and process each independently.
- Array
- Fixed Size
- Dynamic Size
- Matrices
- Fixed Size
- Dynamic Size
- Singly Linked List
- With Both Head and Tail Pointers
C++ code Python code - With Head Pointer only
C++ code
- Doubly Linked List
C++ code - Circular Linked List
- Using Fixed Sized Array
- Using Dynamic Array or Vector
- Using Linked Lists
C++ code
- Queue
- Using Fixed Sized Array
- Using Dynamic Array or Vector
- Using Linked Lists
C++ code
- Hash Table
- Hash Function
- Collision Handling
- Open Addressing
- Using Chaining
C++ code
Operation | Detail |
---|---|
Access | Retrieve an element from the data structure. |
Insert | Add a new element into the data structure. |
Delete | Remove an existing element from the data structure. |
Update | Modify an element in the data structure. |
Search | Locate an element by its value or key. |
Traverse | Visit each element in the data structure, often used to perform operations on all elements. |
Check | Determine certain properties or conditions, such as whether the structure is empty or whether an element exists. |
Sorting is typically not included as a fundamental operation for all data structures because:
Not All Data Structures Support Sorting Directly:
Some data structures, like stacks or queues, are inherently unordered and don't support direct sorting operations. Sorting is more relevant to data structures like arrays or lists, where elements have a specific order.
Sorting is an Operation on Data, Not a Data Structure:
Sorting is often considered an algorithmic operation applied to data structures rather than a fundamental operation of the data structures themselves. For example, you sort an array using sorting algorithms, but sorting isn't a built-in operation of the array data structure.
Sorting Complexity:
Sorting introduces complexity that depends on the type of data structure and the algorithm used. It's not a basic operation like access or insertion, which are more universally applicable.
Array
Operation | Time Complexity | Note |
---|---|---|
Access | O(1) | - |
Insert | O(n)/O(1) | Inserting from an arbitrary position / Inserting at the end if there is space |
Delete | O(n)/O(1) | deleting from an arbitrary position / deleting from the end |
Update | O(1) | - |
Search | O(n)/O(log n) | Linear search / Binary search if sorted |
Matrix
Operation | Time Complexity | Note |
---|---|---|
Access | O(1) | - |
Insert | O(m . n) | If resizing or modifying a specific element in a fixed-size matrix |
Delete | O(m . n) | Similar to insert if resizing or modifying |
Update | O(1) | - |
Search | O(m . n) / O(log n) | Linear search / if sorted |
Linked List
- With Head Pointer Only:
Operation | Time Complexity | Note |
---|---|---|
Access | O(n) | - |
Insert | O(1)/O(n) | At the head / At an arbitrary position |
Delete | O(1)/O(n) | At the head / At an arbitrary position |
Update | O(n) | - |
Search | O(n) | Linear search |
- With Both Head and Tail Pointers:
Operation | Time Complexity | Note |
---|---|---|
Access | O(n) | - |
Insert | O(1)/O(n) | At the head or tail / At an arbitrary position |
Delete | O(1)/O(n) | At the head or tail / At an arbitrary position |
Update | O(n) | - |
Search | O(n) | Linear search |
Stack
- Array:
Operation | Time Complexity | Note |
---|---|---|
Access | O(1) | - |
Push | O(1)/O(n) | Fixed-sized or No resizing required / When resizing is required |
Pop | O(1) | - |
Update | O(1) | - |
Search | O(n) | - |
- Linked List:
Operation | Time Complexity | Note |
---|---|---|
Access | O(n) | - |
Push | O(1) | At the Head |
Pop | From the Head | - |
Update | O(n) | - |
Search | O(n) | - |
Queue
- Array:
Operation | Time Complexity | Note |
---|---|---|
Access | O(1) | - |
Enqueue | O(1)/O(n) | Fixed-sized or No resizing required / When resizing required |
Dequeue | O(1) | - |
Update | O(1) | - |
Search | O(n) | - |
- Linked List:
Operation | Time Complexity | Note |
---|---|---|
Access | O(n) | - |
Enqueue | O(1) | At the Tail |
Dequeue | O(1) | From the Head |
Update | O(n) | - |
Search | O(n) | - |
Hash Table
Average case for all basic operations on hash table is O(1) and Worst case if there are many collisions in Open Addressing or all elements hash into the same bucket in Chaining is O(n).
-
Selection Sort
Pseudocode C++ code Python code -
Bubble Sort
Pseudocode C++ code Python code -
Insertion Sort
Pseudocode C++ code Python Code -
Merge Sort
Pseudocode C++ code Python Code -
HeapSort
Pesudocode -
QuickSort
Pseudocode -
Counting Sort
Pseudocode -
Radix Sort
Pseudocode -
Bucket Sort
Pseudocode -
ShellSort
Pseudocode -
TimSort
Pseudocode -
3-way Merge Sort
Pseudocode
Algorithm | Worst Case | Average Case |
---|---|---|
Selection Sort | O(n2) | O(n2) |
Bubble Sort | O(n2) | O(n2) |
Insertion Sort | O(n2) | O(n2) |
Merge Sort | O(n log n) | O(n log n) |
HeapSort | O(n log n) | O(n log n) |
QuickSort | O(n2) | O(n log n) |
Counting Sort | O(n + k) | O(n + k) |
Radix Sort | O(nk) | O(nk) |
Bucket Sort | O(n2) | O(n + k) |
ShellSort | O(n2) | O(n log n) to O(n2) |
TimSort | O(n log n) | O(n log n) |
3-way Merge Sort | O(n log n) | O(n log n) |
- Comb Sort
- Tree Sort
- Odd-Even Sort / Brick Sort
- Linear Search
- Binary Search
Python Code - Hashing
- Interpolation Search
- Ternary Search
- Jump Search
- Exponential Search
- Fibonacci Search
- Binary Tree
- Binary Search Tree
- Ternary Tree
- AVL Tree
- Red Black Tree
- Segment Tree
- N-ary Tree
- B-Tree
- Pre Order
- In Order
- Post Order