West Midlands | 25-SDC-July | Gabriel Deng | Sprint 1 | Analyse and refactor functions#69
West Midlands | 25-SDC-July | Gabriel Deng | Sprint 1 | Analyse and refactor functions#69gai93003 wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
-
I could not find the complexity analysis of the original and the refactored code.
-
The PR description does not have much info about this PR.
|
Thanks @cjyuan for the review. I have added the analysis as comments on the individual exercises |
|
|
||
| // In this case, the time complexity is O(n * m), it will only become O(n^2) when the two arrays have equal lengths. This case easily be avoided by using a set to store the second sequence. When checking for a match in the set using item in second-set, this has a time complexity of O(1). | ||
|
|
There was a problem hiding this comment.
What is the complexity of the improved approach?
There was a problem hiding this comment.
The complexity for this improved approach is O(n + m) compared to the original O(n * m)
| * Time Complexity: O(n) | ||
| * Space Complexity: O(n) | ||
| * Optimal Time Complexity: O(1) | ||
| * |
There was a problem hiding this comment.
Are these the complexities of the original function, the improved function, or something else?
An O(1) approach? How?
There was a problem hiding this comment.
I mixed the complexities around and they are for this improved function,
Time complexity is O(n) as you have to scan through the whole array
Space complexity is O(1) because it is constant extra memory
Optimal Time Complexity could be O(n) with the use of a set
|
Changes look good. |
|
Thank you for the review @cjyuan |
Learners, PR Template