-
-
Notifications
You must be signed in to change notification settings - Fork 14
ZA | 25-SDC-July | Luke Manyamazi | Sprint 1 | JavaScript and Python Exercises #61
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
base: main
Are you sure you want to change the base?
ZA | 25-SDC-July | Luke Manyamazi | Sprint 1 | JavaScript and Python Exercises #61
Conversation
cjyuan
left a comment
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.
Your analysis looks good.
| // The complexity is reduced by combining the two sequential O(N) loops | ||
| // into a single O(N) loop, cutting the number of array traversals in half. | ||
| for (const num of numbers) { | ||
| sum += num; | ||
| product *= num; | ||
| } |
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.
Performance can be improved by combining the loops, but the complexity remains O(N).
In complexity analysis, the constant factor is ignored.
N, 2N, or even 100N operations, are all considered as O(N) complexity.
| Time Complexity: | ||
| Space Complexity: | ||
| Optimal time complexity: | ||
| Time Complexity: O(N) |
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.
I think this "Time Complexity" refers to the complexity of the original code, and the optimal one refers to the refactored code.
Learners, PR Template
Self checklist
Changelist
Questions