-
Notifications
You must be signed in to change notification settings - Fork 48
Leaves - Mariya Burrows #30
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
base: master
Are you sure you want to change the base?
Conversation
CheezItMan
left a comment
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.
Nice work, you hit the learning goals here. Check out my comments and let me know if you have any questions.
| # A method to reverse the words in a sentence, in place. | ||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n ^2) because lines 47-55 contain a nested loop. |
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.
Actually since start_position jumps to the end of the reversed word after a reversal, this is O(n)
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n ^2) because lines 47-55 contain a nested loop. | ||
| # Space complexity: ? O(n) because of the empty_index_positions array from lines 33 - 38 |
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.
I would say O(m) where m is the number of words, but yet. Could you instead do this with O(1) space complexity?
| if my_sentence[i].length < comparison_word.length | ||
| puts my_sentence[i] | ||
| puts comparison_word | ||
| swap(my_sentence, i, j ) | ||
| comparison_word = my_sentence[j] | ||
| end |
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.
This is an interesting sort, it's not one of the standard sorts but does sort elements. It does work however.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n ^ 2) | ||
| # Space complexity: ? O(n) because of splitting the string at the beginning of the method |
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.
yup
Sorting & Reverse Sentence