London | SDC Nov 25 | Emiliano Uruena | Sprint 2 |Improve with precomputing#142
London | SDC Nov 25 | Emiliano Uruena | Sprint 2 |Improve with precomputing#142Emilianouz wants to merge 2 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Can you use complexity to explain how the new implementation are better than the original implementation?
using sorted(strings) to prevent the side effect.
|
Can you also address this comment: #142 (review) |
@cjyuan The original had complexity O(n² × m) because compares every possible pair of strings, and each comparison can take up to O(string length). The improved version first sorts the list in O(n log n) then only compares neighbours strings O(n × m). That reduces the number of comparisons. |
|
If we are factoring in the length of the strings, m, then the complexity of sorting won't just be O(nlogn). nlogn measures only the number of comparisons needed. |
The new implementation first sorts the strings, which costs O(n log n × m) since string comparisons can take up to O(m). After sorting, only adjacent strings are compared, reducing the comparison phase to O(n × m). Overall the complexity improves from O(n² × m) to O(n log n × m) |
|
All good. Well done. |
Learners, PR Template
Self checklist
Changelist
Refactor common_prefix and count_letter functions with precomputing.