Skip to content

Added script in JAVA for how many times an array has been rotated in O(log N) #2448

Merged
siriak merged 3 commits into
TheAlgorithms:masterfrom
nirmalya8:master
Oct 4, 2021
Merged

Added script in JAVA for how many times an array has been rotated in O(log N) #2448
siriak merged 3 commits into
TheAlgorithms:masterfrom
nirmalya8:master

Conversation

@nirmalya8

@nirmalya8 nirmalya8 commented Oct 3, 2021

Copy link
Copy Markdown
Contributor

Added the script in Searches Folder

Describe your change:

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

References

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 Java files are placed inside an existing directory.
  • All filenames are in all uppercase characters with no spaces or dashes.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@nirmalya8 nirmalya8 requested a review from siriak as a code owner October 3, 2021 09:11

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add tests showing how it works. It seems that it won't work for arrays with duplicate elements

@nirmalya8

Copy link
Copy Markdown
Contributor Author

Please add tests showing how it works. It seems that it won't work for arrays with duplicate elements

Can you tell me where to add the tests. I added 3 testcases in the file as comments.
As for duplicate elements, I am checking the script and will update the PR

@nirmalya8

Copy link
Copy Markdown
Contributor Author

Hey @siriak , I couldn't find a solution for duplicate elements. If there are duplicate elements then maybe the complexity has to go up. Can you tell me where to add the tests(I don't know about them, can you explain)?

And, I found out, I can add the solution to another such question:
Given a rotated sorted array(rotated from its initial sorted position.), search for an element.
Input-Output:
Eg. [11,12,15,18,2,5,6,8]
Search Element: 6
Position: 6
Again, in O(log n) time.

@siriak

siriak commented Oct 4, 2021

Copy link
Copy Markdown
Member

Just mention in the description that the array cannot contain duplicates. As for tests, we don't have anything set up, so your comments will serve the purpose.

@nirmalya8

Copy link
Copy Markdown
Contributor Author

Just mention in the description that the array cannot contain duplicates. As for tests, we don't have anything set up, so your comments will serve the purpose.

Done it. Thanks!

@siriak siriak merged commit a352a49 into TheAlgorithms:master Oct 4, 2021
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