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

Dionisia - Edges - reverse_sentence #35

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

Conversation

larachan15
Copy link

time complexity is O(1)
space complexity is O(1)
Only 2 variables temporarily created to hold the sentence start and end points. Doesn't change based on the input size.

@@ -1,4 +1,58 @@
# A method to reverse the words in a sentence, in place.

# time complexity is O(1)

Choose a reason for hiding this comment

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

The space complexity and it's reasoning is correct. However the time complexity of your algorithm is not O(1). To figure out the time complexity, you want to count the number of steps or the number of operations your algorithm takes in relation to the size of the input. If the input has n characters and you are looking to examine each character, then just to examine each character, you will need n steps. In this case, you want to add up the number of steps taken by word_reverse and reverse_words to compute the time complexity.

@shrutivanw
Copy link

The algorithm looks good. I added some comments inline for the time and space complexity.

Take a look at another similar solution and explanation of the time and space complexity here: https://github.com/Ada-C10/reverse_words/blob/solution/lib/reverse_words.rb Slack me if you'd like to discuss further or 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