Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mentoring.md #2350

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tracks/python/exercises/perfect-numbers/mentoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A simple optimization is to use `range(1, number // 2 + 1)` as the `for` loop `i
This halves the complexity of the solution.

For a more efficient solution, one can compute all the factors by using the smaller `range(1, int(math.sqrt(number)) + 1)` as the `iterable`.
This solution is longer and more involved but significantly faster, reducing the complextiy from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).
This solution is longer and more involved but significantly faster, reducing the complexity from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).

```python
def classify(number):
Expand All @@ -49,5 +49,5 @@ def classify(number):

Students unfamiliar with `generator expressions` might write: `aliquot = sum([item for item in range(1, number) if number % item == 0])`.
Note this first creates a `list` of factors in memory by iterating over the entire range, then iterates once more over the `list` to `sum()` its values.
This is inefficent for both memory and processing time.
Dropping the `[]` drops `list` creation and allows `sum()` to lazily process a `generator expression`, wich only requires a single iteration and a smaller memory footprint.
This is inefficient for both memory and processing time.
Dropping the `[]` drops `list` creation and allows `sum()` to lazily process a `generator expression`, which only requires a single iteration and a smaller memory footprint.
Loading