Skip to content

Commit c6add60

Browse files
authored
Update README.md
1 parent 5fd8183 commit c6add60

File tree

1 file changed

+24
-0
lines changed
  • Data Structures and Algorithms/Sorting Algorithms

1 file changed

+24
-0
lines changed

Diff for: Data Structures and Algorithms/Sorting Algorithms/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,27 @@ print("Original array:", arr)
2323
writes = cycle_sort(arr)
2424
print("Sorted array:", arr)
2525
print("Number of writes performed:", writes)
26+
```
27+
# Pigeonhole Sort Algorithm
28+
29+
## Overview
30+
Pigeonhole Sort is a sorting algorithm that works well for sorting lists where the range of values (i.e., the difference between the maximum and minimum values) is not significantly larger than the number of elements in the list. It is a non-comparison-based sorting algorithm.
31+
32+
The algorithm works by placing each element into its corresponding "pigeonhole" (a slot or bucket) and then iterating through the pigeonholes in order to reconstruct the sorted list.
33+
34+
## Complexity
35+
- **Time Complexity**:
36+
- The time complexity of Pigeonhole Sort is O(n + range), where n is the number of elements in the list and range is the difference between the maximum and minimum values.
37+
38+
- This makes it efficient for lists with a small range of values.
39+
- **Space Complexity**: The space complexity is O(range), as it requires additional space for the holes list.
40+
- **Limitations**: Pigeonhole Sort is not suitable for lists with a large range of values, as it would require a lot of memory for the holes list.
41+
42+
## Usage Example
43+
```python
44+
from PigeonHole_Sort import pigeonhole_sort
45+
46+
arr = [4, 5, 3, 2, 1]
47+
print("Original array:", arr)
48+
writes = pigeonhole_sort(arr)
49+
print("Sorted array:", arr)

0 commit comments

Comments
 (0)