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 intoCodeYourFuture:mainfrom
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?
Sprint-2/improve_with_precomputing/common_prefix/common_prefix.py
Outdated
Show resolved
Hide resolved
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. |
Learners, PR Template
Self checklist
Changelist
Refactor common_prefix and count_letter functions with precomputing.