Title: Add Concurrent Merge Sort Implementation by anshullakra007 · Pull Request #7544 · TheAlgorithms/Java · GitHub
Open Graph Title: Add Concurrent Merge Sort Implementation by anshullakra007 · Pull Request #7544 · TheAlgorithms/Java
X Title: Add Concurrent Merge Sort Implementation by anshullakra007 · Pull Request #7544 · TheAlgorithms/Java
Description: Add Concurrent Merge Sort Implementation Description This 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. To 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. Time & Space Complexity 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. 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. Testing Comprehensive and strictly deterministic JUnit 5 tests have been added in ConcurrentMergeSortTest.java to guarantee reliability: Pre-sorted data: Verified correct handling on both strictly ascending and strictly descending arrays. Identical elements: Ensured correct sorting and stability for arrays filled with identical values. Edge cases: Successfully tested against empty ([]) and single-element ([42]) arrays. 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(). Checklist Code is formatted according to the repository's standard style guidelines. No wildcard imports are used; all dependencies are explicitly imported. Proper Javadocs are included for classes and public methods, detailing complexities. JUnit 5 tests are exhaustive, deterministic, and pass successfully. The executor thread pool cleanly shuts down via a finally block, preventing CI/CD pipeline hangs.
Open Graph Description: Add Concurrent Merge Sort Implementation Description This PR introduces a ConcurrentMergeSort algorithm that accelerates the standard divide-and-conquer Merge Sort by distributing sub-array sorting...
X Description: Add Concurrent Merge Sort Implementation Description This PR introduces a ConcurrentMergeSort algorithm that accelerates the standard divide-and-conquer Merge Sort by distributing sub-array sorting...
Opengraph URL: https://github.com/TheAlgorithms/Java/pull/7544
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:fd90b4c0-bacc-a0e0-8eaf-e038ece9d3ca |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A7D4:1F5DD1:5F2732:825E24:6AFAA3DA |
| html-safe-nonce | a66522dd9bbfff10fcbecc6eff843ff2d973d14a6037c880e7f8cf35aeeab7c3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0Q0OjFGNUREMTo1RjI3MzI6ODI1RTI0OjZBRkFBM0RBIiwidmlzaXRvcl9pZCI6IjcwNTg0MTU1MTQ1MDE2ODYyMzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 56513b4322a1e093a399823e97e5d7abbc3b514c69130bf4d907c5611d4c0912 |
| hovercard-subject-tag | pull_request:4136908592 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/TheAlgorithms/Java/pull/7544/files |
| twitter:image | https://avatars.githubusercontent.com/u/177731511?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/177731511?s=400&v=4 |
| og:image:alt | Add Concurrent Merge Sort Implementation Description This PR introduces a ConcurrentMergeSort algorithm that accelerates the standard divide-and-conquer Merge Sort by distributing sub-array sorting... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/TheAlgorithms/Java git https://github.com/TheAlgorithms/Java.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 63477660 |
| octolytics-dimension-repository_nwo | TheAlgorithms/Java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63477660 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Java |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width