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

Laura | Nodes #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lauracodecreations
Copy link

time and space complexity in comments of my code

i = 0
j = my_phrase.length - 1
while i < my_phrase.length
if my_phrase[i] == " "

Choose a reason for hiding this comment

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

To account for multiple, consecutive white spaces, consider making the conditional statements on line 29 and line 33 into while loops.


i = 0
j = my_phrase.length - 1
while i < my_phrase.length

Choose a reason for hiding this comment

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

i does not need to go through all indices from 0 through length-1, It's sufficient to reach mid-way through the string to confirm whether the string is a palindrome or not. (Similar to string_reverse).
So, line 28, could simply be i < j.

@@ -1,5 +1,44 @@
# A method to check if the input string is a palindrome.
# Return true if the string is a palindrome. Return false otherwise.
# Time: O(n)

Choose a reason for hiding this comment

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

With regards to time and space complexities: Always explain what n stands for while explaining your time and space complexity. That along with your explanation for reasoning behind your answer, is the complete answer for the time and space complexity. In this case, n is the number of characters in the input string parameter.

@shrutivanw
Copy link

Your algorithm is getting to place where it can work in all scenarios. See some comments added inline on the algorithm and on explaining the time and space complexities.

Slack me if you have any questions.

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