Skip to content

Leaves - Alice#22

Open
sun-alice wants to merge 1 commit into
Ada-C12:masterfrom
sun-alice:master
Open

Leaves - Alice#22
sun-alice wants to merge 1 commit into
Ada-C12:masterfrom
sun-alice:master

Conversation

@sun-alice

Copy link
Copy Markdown

No description provided.

@CheezItMan CheezItMan 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.

Nice work! You hit all the learning goals here. See my note on delete_at and it's impact on runtime.

Otherwise excellent job!

Comment thread lib/practice_exercises.rb

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n), linear, because the amount of times the while loop iterates is directly proportionate to the length of the array.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are using delete_at which has a runtime of O(n), you actually have O(n2) runtime complexity.

Remember delete_at shifts each of the subsequent elements over one index.

Comment thread lib/practice_exercises.rb
# Space Complexity: ?
# Time Complexity: O(n*m), quadratic, because there are two loops present: the while and the each. Each of those loops are based on different data sizes, and are proportionate to the size of the data.
# Space Complexity: O(n), linear, because longest_prefix is a variable that may increase if the data size increases.
def longest_prefix(strings)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants