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

01 prework methodical problem solving #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

janiceshiu
Copy link
Owner

prework for the first class - methodical problem solving

Copy link

@robot-dreams robot-dreams left a comment

Choose a reason for hiding this comment

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

Looks great. Really appreciate the detailed comments / breakdown!


@staticmethod
def test():
phrases = [

Choose a reason for hiding this comment

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

Great test cases!

# overall
# time - o(n)
# space - o(n)
# where n is the length of `phrase`

Choose a reason for hiding this comment

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

Is this o(n) total or o(n) not including the input?

Copy link
Owner Author

Choose a reason for hiding this comment

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

@robot-dreams my understanding is o(n) total where n is length of phrase because a larger phrase may result in a larger set. (eg: 500-character phrase where each char is unique takes up more space than a 10-character phrase where each char is unique)

# * since c is a temporary variable
for c in phrase:
# o(1) constant time and space?
# does set.discard take constant time and space?

Choose a reason for hiding this comment

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

Yes, we can assume this (we'll talk in more detail about how set works in a later session)

reached before the phrase ends

The only difference from is_pangram_1 is that `len(alpha) == 0` becomes
`alpha == set()`

Choose a reason for hiding this comment

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

One more alternative you might consider here is not alpha

Copy link
Owner Author

Choose a reason for hiding this comment

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

@robot-dreams ah I see! I'm still not very clear on what counts as falsey for not so I wanted to be more explicit. I don't program in Python on a daily basis - it's just the language I use for DS&A since there are the most resources for it. so i'm teaching myself python along the way XD

# not sure about time and space.
# time - o(n)?
# * is length of the set calculated everytime or is it stored in a
# variable somewhere?

Choose a reason for hiding this comment

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

Good question! You can assume it'll be stored.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@robot-dreams if that's so, then len(alpha) is o(1) yes?

Choose a reason for hiding this comment

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

# overall loop
# time - o(n^2)?
# * o(n) `for c in phrase`
# * within that, another o(n) for `len(alpha)`?

Choose a reason for hiding this comment

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

What's the overall time if len(alpha) is o(1)?

Copy link
Owner Author

Choose a reason for hiding this comment

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

@robot-dreams if len(alpha) is o(1), then overall time is o(n) where n is length of phrase. max one iteration through phrase in for c in phrase

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