NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | improve with precomputing#172
NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | improve with precomputing#172TzeMingHo wants to merge 4 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Code looks good.
Could you use Big O notation to quantify the improvement achieved by the new implementation? A brief comparison of the time complexity before and after the change would be helpful.
| return longest | ||
|
|
||
| # before changes, it was N^2, bacause it got a for loop inside a for loop | ||
| # after changes, it is N + N. The first N for sorted, and another N for the loop. |
There was a problem hiding this comment.
Could you lookup the complexity of sorted() in Python?
There was a problem hiding this comment.
The worst case for sorted is NlogN, when the list is randomly ordered.
There was a problem hiding this comment.
O(n log n) is the optimal average-case time complexity achievable by any comparison-based sorting algorithm.
An O(n) complexity approach is possible but that would involve writing a lot of code. 😄
|
Closing PR because the SDC run has finished. Feel free to re-open if you're still working on it. |
Learners, PR Template
Self checklist
Changelist
I have attempted with sorted and set