Skip to content

NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | improve with precomputing #178

Closed
ZabihollahNamazi wants to merge 2 commits into
CodeYourFuture:mainfrom
ZabihollahNamazi:s2-improve-with-precomputing
Closed

NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | improve with precomputing #178
ZabihollahNamazi wants to merge 2 commits into
CodeYourFuture:mainfrom
ZabihollahNamazi:s2-improve-with-precomputing

Conversation

@ZabihollahNamazi

@ZabihollahNamazi ZabihollahNamazi commented Jun 24, 2026

Copy link
Copy Markdown
  • 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

Hi! Could you please check my code?
The old code used slow loops and would freeze with big data. I fixed them by using sorting and sets so they now run instantly and easily handle millions of characters.All tests are passing perfectly. Thank you!

@ZabihollahNamazi ZabihollahNamazi 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. Module-Complexity The name of the module. labels Jun 24, 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 complexity to explain how the new implementation is better than the original implementation?

@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 26, 2026
@ZabihollahNamazi

Copy link
Copy Markdown
Author

-Common Prefix:
Old Way (Slow): To find the best matching pair, the code had to compare every single word with every other word one by one. If you had 10,000 words, it took millions of slow steps.

New Way (Fast): By sorting the list first (O(N log N . M)) , words that look alike are automatically grouped right next to each other. Now, the code only needs to look at neighbor pairs in one quick pass. It cuts out thousands of useless comparisons!

-Count Letters
Old Way (Slow): For every uppercase letter found, the code had to scan the entire text again from start to finish to see if a lowercase version existed. This repeated scanning made it freeze up on large text (O(N^2)).
New Way (Fast): The code reads the text exactly once from start to finish to sort letters into two Hash Sets. Because checking a Python set is instant (O(1)), the whole program runs in a single, fast linear pass (O(N)).

@ZabihollahNamazi ZabihollahNamazi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jun 27, 2026
@cjyuan

cjyuan commented Jun 28, 2026

Copy link
Copy Markdown

Explanation is clear. Well done.

Note: You could also just mention the complexity of the original Common Prefix algorithm is O(M*N^2) without giving an example of 10,000 words.

@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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jun 28, 2026
@illicitonion

Copy link
Copy Markdown
Member

Closing PR because the SDC run has finished. Feel free to re-open if you're still working on it.

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. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants