Skip to content

Glasgow | 26-JUL-SDC |Shreef Ibrahim | Sprint 2 |Improve precomputing - #255

Open
shreefAhmedM wants to merge 1 commit into
CodeYourFuture:mainfrom
shreefAhmedM:improve_with_precomputing
Open

shreefAhmedM wants to merge 1 commit into
CodeYourFuture:mainfrom
shreefAhmedM:improve_with_precomputing

Conversation

@shreefAhmedM

@shreefAhmedM shreefAhmedM commented Oct 14, 2026 •

Copy link
Copy Markdown

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

Task code

CYF-1183

Changelist

Replaced the nested loops that compared every pair of strings with a sorting-based approach.

Precomputed the sorted order of the input strings to reduce redundant comparisons.

Compared only adjacent strings, since the longest common prefix shared by any pair can be found among adjacent strings in sorted order.

Preserved the existing function interface and tests.

@github-actions

This comment has been minimized.

4 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | improve_with_caches Glasgow / 26-Jul-SDC /Shreef Ibrahim /Module-Complexity/Sprint-2 /improve_with_caches Oct 14, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow / 26-Jul-SDC /Shreef Ibrahim /Module-Complexity/Sprint-2 /improve_with_caches Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | improveWithCaches Oct 14, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | improveWithCaches Glasgow | 26-Jul-SDC | Shreef Ibrahim | Module-Complexity/Sprint-2/improve_with_caches Oct 16, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Module-Complexity/Sprint-2/improve_with_caches Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint-2 | improve_with_caches Oct 16, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint-2 | improve_with_caches Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint-2 | Improve Code with Caches Oct 16, 2026
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint-2 | Improve Code with Caches Glasgow | 26-JUL-SDC |Shreef Ibrahim | Sprint 2 |Improve precomputing Oct 16, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 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.

  • Could you use complexity to explain how the new implementation is better than the original implementation?

  • Why is the Changelist section empty?

@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 Oct 16, 2026
@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@shreefAhmedM

Copy link
Copy Markdown
Author
  • Could you use complexity to explain how the new implementation is better than the original implementation?
  • Why is the Changelist section empty?
    Thanks for pointing out that the original implementation had a time complexity of O(n²L), where L is the maximum string length, as it compared every pair of strings. This made the test with one million strings take a very long time. I've updated the implementation to sort the strings first and compare only adjacent pairs, reducing the time complexity.

@cjyuan

cjyuan commented Oct 16, 2026

Copy link
Copy Markdown

What's the complexity of the improved implementation?

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@shreefAhmedM

Copy link
Copy Markdown
Author

What's the complexity of the improved implementation?

What's the complexity of the improved implementation?
The improved complexity is O(nL log n): sort, then compare adjacent strings. ti is faster than the original one. But if I managed to achieve O(nL), I think it would be better and faster

@shreefAhmedM shreefAhmedM added Complete Volunteer to add when work is complete and all review comments have been addressed. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Complete Volunteer to add when work is complete and all review comments have been addressed. labels Oct 16, 2026
@cjyuan

cjyuan commented Oct 16, 2026 •

Copy link
Copy Markdown

Analyses look good.

Note: An optimal complexity of $O(nL)$ for find_longest_common_prefix would probably require some data structure.

@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 Oct 16, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants