Skip to content

Commit 0afa310

Browse files
authored
Create README.md
1 parent f2fc2d2 commit 0afa310

File tree

1 file changed

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

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Cycle Sort Algorithm
2+
3+
## Overview
4+
Cycle Sort is a comparison-based sorting algorithm that is efficient when minimizing memory writes is important. It is an in-place sorting algorithm that rearranges the elements by identifying cycles in the permutation of elements.
5+
6+
## Algorithm Explanation
7+
The algorithm works by:
8+
1. Identifying the correct position of each element in the array.
9+
2. Placing the element in its correct position and replacing the element already there in the cycle.
10+
3. Repeating the process for the remaining unsorted elements.
11+
12+
## Complexity
13+
- **Time Complexity**:
14+
- Best, Worst, and Average Case: O(n²) (due to nested cycles).
15+
- **Space Complexity**: O(1) (in-place sorting).
16+
17+
## Usage Example
18+
```python
19+
from Cycle_Sort import cycle_sort
20+
21+
arr = [4, 5, 3, 2, 1]
22+
print("Original array:", arr)
23+
writes = cycle_sort(arr)
24+
print("Sorted array:", arr)
25+
print("Number of writes performed:", writes)

0 commit comments

Comments
 (0)