Skip to content

NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | improve with precomputing#172

Open
TzeMingHo wants to merge 4 commits into
CodeYourFuture:mainfrom
TzeMingHo:coursework/improve_with_precomputing
Open

NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | improve with precomputing#172
TzeMingHo wants to merge 4 commits into
CodeYourFuture:mainfrom
TzeMingHo:coursework/improve_with_precomputing

Conversation

@TzeMingHo

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

I have attempted with sorted and set

@TzeMingHo TzeMingHo added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 21, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 22, 2026
@TzeMingHo TzeMingHo added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jun 23, 2026
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you lookup the complexity of sorted() in Python?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worst case for sorted is NlogN, when the list is randomly ordered.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😄

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 23, 2026
@TzeMingHo TzeMingHo added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jun 23, 2026
@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants