Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Multi-threaded Merge Sort in Java and Rust #53

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

KiranRajeev-KV
Copy link

PR: Implement Multi-threaded Merge Sort in Java and Rust

This PR adds the implementation of Multi-threaded Merge Sort in both Java and Rust, as stated in issue #42.

Added Features

  • Normal Merge Sort: Implemented Normal Merge Sort in both Java and Rust. (this serves as the base implementation to build the Parallel Merge Sort)
  • Parallel Merge Sort: Implemented a Parallel Merge Sort in both Java and Rust

Changes Made

  • Updated .gitignore to exclude target and debug folders from Cargo
  • Updated README.md to add instructions for Rust code execution using Cargo

Copy link
Collaborator

@FirefoxSRV FirefoxSRV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have given my review for your code @KiranRajeev-KV

if (arr.length > 1) {
int mid = arr.length / 2;

int[] left = new int[mid];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this could fail if there is a null array (NOT EMPTY). [ NullPointerException is bound to occur] .......

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For very large arrays, int mid = arr.length / 2; could lead to integer overflow if arr.length exceeds Integer.MAX_VALUE (unlikely but theoretically possible).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check for null arrays


// Threshold to switch to normal merge sort
// change this value according to the size of the array to get the best performance
private static final int THRESHOLD = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the THRESHOLD = 5 seem to look too low ? For performance measurement with small arrays, creating threads is more expensive than sorting them sequentially.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the threshold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a .java and .rs implementation of multithreaded mergesort
3 participants