Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10d265c

Browse filesBrowse files
style: fix trailing blank line to satisfy clang-format
1 parent 410d320 commit 10d265c
Copy full SHA for 10d265c

2 files changed

+6-1Lines changed: 6 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pr_payload.json‎

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "Add Concurrent Merge Sort Implementation",
3+
"body": "# Add Concurrent Merge Sort Implementation\n\n## Description\nThis PR introduces a `ConcurrentMergeSort` algorithm that accelerates the standard divide-and-conquer Merge Sort by distributing sub-array sorting tasks across multiple threads utilizing a `ThreadPoolExecutor`. \n\nTo prevent the overhead of thread creation and context switching from ruining overall performance, this implementation incorporates a **sequential fallback threshold** (set to 8,192 elements). Once a sub-array's size drops below this threshold—or when a safe maximum concurrency depth is reached—the algorithm smartly switches to a standard sequential Merge Sort. This design prevents thread starvation deadlocks and ensures optimal CPU resource utilization.\n\n## Time & Space Complexity\n- **Time Complexity**: $\\mathcal{O}(N \\log N)$ - The array is consistently divided in half and merged linearly. The concurrent threads distribute this workload without altering the fundamental algorithmic complexity.\n- **Space Complexity**: $\\mathcal{O}(N)$ - A temporary array of size $N$ is allocated once for the merging phases, alongside $\\mathcal{O}(\\log N)$ auxiliary stack space utilized by the recursive calls.\n\n## Testing\nComprehensive and strictly deterministic JUnit 5 tests have been added in `ConcurrentMergeSortTest.java` to guarantee reliability:\n- **Pre-sorted data**: Verified correct handling on both strictly ascending and strictly descending arrays.\n- **Identical elements**: Ensured correct sorting and stability for arrays filled with identical values.\n- **Edge cases**: Successfully tested against empty (`[]`) and single-element (`[42]`) arrays.\n- **Large datasets**: Executed a load test with 100,000 randomly generated elements (using a fixed `Random(42)` seed for CI determinism) to intentionally exceed the 8,192 sequential threshold, verifying the multithreaded pathways against Java's heavily optimized built-in `Arrays.sort()`.\n\n## Checklist\n- [x] Code is formatted according to the repository's standard style guidelines.\n- [x] No wildcard imports are used; all dependencies are explicitly imported.\n- [x] Proper Javadocs are included for classes and public methods, detailing complexities.\n- [x] JUnit 5 tests are exhaustive, deterministic, and pass successfully.\n- [x] The executor thread pool cleanly shuts down via a `finally` block, preventing CI/CD pipeline hangs.",
4+
"head": "anshullakra007:feat/concurrent-merge-sort",
5+
"base": "master"
6+
}
Collapse file

‎src/test/java/com/thealgorithms/sorts/ConcurrentMergeSortTest.java‎

Copy file name to clipboardExpand all lines: src/test/java/com/thealgorithms/sorts/ConcurrentMergeSortTest.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,4 @@ public void testNullArray() {
9090
ConcurrentMergeSort.sort(array);
9191
org.junit.jupiter.api.Assertions.assertNull(array, "Null array should be handled without errors.");
9292
}
93-
9493
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.