Skip to content

Added Bitonic Sort Algorithm #1370

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

prasad-chavan1
Copy link

Open in Gitpod 
know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@prasad-chavan1
Copy link
Author

Respected @appgurueu & @raklaptudirm ,

I apologize for any inconvenience caused by my recent pull request. It includes code indentation fixes that I'm addressing promptly. Please consider merging the request, and I'll ensure it aligns perfectly with project standards in the next update. Your guidance is appreciated.

Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

Please also add a proper JSDoc comment. Try to reuse the tests of existing sorting algorithms (but don't just copy and paste; simply execute the same tests for multiple sorting algorithms that offer the same API).

* more information: https://en.wikipedia.org/wiki/Bitonic_sorter

*/
function compAndSwap (a, i, j, order) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than taking an order parameter, this should take a comparison function.

// order, if order = 1
function bitonicMergeArr (a, low, cnt, dir) {
if (cnt > 1) {
const k = parseInt(cnt / 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use parseInt instead of cnt >> 1 for floor division by 2?

function bitonicMergeArr (a, low, cnt, dir) {
if (cnt > 1) {
const k = parseInt(cnt / 2)
for (let i = low; i < low + k; i++) { compAndSwap(a, i, i + k, dir) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not inline compAndSwap?


function bitonicSort (a, low, cnt, order) { // (arr 0 arrLen AS-Ds-order)
if (cnt > 1) {
const k = parseInt(cnt / 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here (use cnt >> 1)


// Calling of bitonicSort func for sorting the entire array
// of length N in ASCENDING order
// here up=1 for ASCENDING & up=0 for DESCENDING
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, I'd prefer a comparator.

}

// displaying array
function logArray (arr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function doesn't belong here. It should be removed.


export { sort }

// Test Case method
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't belong here.

@@ -0,0 +1,36 @@
import {sort} from '../BitonicSort'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should use proper Jest tests.

@prasad-chavan1
Copy link
Author

prasad-chavan1 commented Sep 24, 2023 via email

Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

Why did this PR just change from Bitonic Sort to Polynomial Hash?

@prasad-chavan1
Copy link
Author

Why did this PR just change from Bitonic Sort to Polynomial Hash?

Sir actually am too busy...Today is my final theory paper so i didnt made any changes to that algo but instead of that i added another hash algo with proper format..so sorry for that....i'll do it by today or tommorow..

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

Successfully merging this pull request may close these issues.

2 participants