- Compile the java code:
javac OddEvenTranspositionSort.java - Run the java file:
java OddEvenTranspositionSort
- Compile the java code:
javac Sasaki.java - Run the java file:
java Sasaki
- Compile the java code:
javac AlternateTimeOptimalSorting.java - Run the java file:
java AlternateTimeOptimalSorting
| Algorithm | Time Complexity (Worst) | Space Complexity | Number of Steps (Rounds) |
|---|---|---|---|
| Odd-Even Transposition Sort | O(n²) | O(n) | n |
| Atsushi Sasaki's Time-Optimal | O(n * (n-1)) | O(n) | n - 1 |
| Alternate Time-Optimal Sorting | O(n/3 * (n-1)) | O(n) | n - 1 |
| Input Type | Odd-Even Transposition | Atsushi Sasaki's Sort | Alternate Time-Optimal |
|---|---|---|---|
| 10 entites | 16 ms | 31 ms | 9 ms |
| 20 entites | 26 ms | 21 ms | 16 ms |
| 30 entites | 27 ms | 29 ms | 18 ms |
| 50 entites | 33 ms | 34 ms | 17 ms |
- Data Structure Used: -
int[]array — used to hold and manipulate the elements being sorted directly in memory. - Time Complexity:
O(n²)- The algorithm performsnphases, and in each phase, up ton/2comparisons/swaps may happen — resulting in a worst-case ofO(n²). - Space Complexity:
O(n)- Uses the input array and a list of threads (up ton/2per phase), so space usage remains linear.
- Data Structure Used: Linked list of nodes (
Node), each containing two elements (Element), with threading to parallelize comparisons and swaps. - Time Complexity: O(n^2) due to n-1 rounds with O(n) work per round.
- Space Complexity: O(n) for storing elements and nodes, plus space for threads.
- Data Structure Used:
int[]- array — used for in-place sorting and accessing neighbors for compare-and-swap operations. - Time Complexity:
O(n²)- The algorithm runs forn - 1rounds, and in each round, up ton/3comparisons happen — leading to a worst-case behavior proportional ton². - Space Complexity:
O(n)- Only the input array and a thread array of sizenare used; no additional data structures grow beyond linear space.