-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
time - o(n^2)? space - o(1)?
time - o(n). space - o(1)?
There was a problem hiding this 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 = [ |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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()` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)`? |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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
prework for the first class - methodical problem solving