-
-
Notifications
You must be signed in to change notification settings - Fork 633
reduced pythagorean-triplet's time complexity from cubic to quadratic #1324
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
reduced pythagorean-triplet's time complexity from cubic to quadratic #1324
Conversation
@@ -58,7 +58,7 @@ describe('Triplet', () => { | |||
]); | |||
}); | |||
|
|||
test.skip('triplets for large number', () => { | |||
xtest('triplets for large number', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it still takes ~ 16 s, we can't "unskip" this, because the web UI has a maximum of 10 s of run time. Apart from that, all these changes are great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to run the test on a smaller input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an input of 25000 takes ~9.5s and returns [ [ 5000, 9375, 10625 ] ]. Or do you mean i should mark the test as skipped but keep the code changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That last thing! So people can run it likely but it won't run in the web.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great. I'll have the workflow format your code by writing:
/format
/format |
The "Format code" action has started running. |
The "Format code" action has finished running. |
For security reasons,
|
In the previous implementation the triplets function had a time complexity of O(n^3). This commit reduces it to O(n^2). I believe the current best known optimal solution for this type of problem is O(n^2(log log n)/log ^2n) but in order to achieve that result we would need to make changes to this solution which would negatively impact readability/understandability. The final test still takes a long time (~16s) but I don't think that can be significantly improved for an input of that size.