Skip to content

Conversation

@YasminM11
Copy link

…paces and white spaces)

Sorting & Reverse Sentence

Question Answer
Describe how Bubble Sort works Bubble Sort comparing adjacent elements and swapping them if they are out of order
Describe how Selection Sort works Selection Sort selecting: If sorted ascending: find the smallest value in the unsorted portion of the array. if sorted descending: find the largest value in the unsorted portion of the array
Describe how Insertion sort works looking at each element and inserting it into its proper place
Which Sorting Algorithm has the best time complexity? Merge sort has the best time complexity
 

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Not bad, but you didn't reverse in place and didn't handle extra spaces in the output. Otherwise not bad. Check out my comments and let me know if you have questions.

# Time complexity: ?
# Space complexity: ?
# Time complexity: o(n)
# Space complexity: o(1)

Choose a reason for hiding this comment

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

You are doing my_sentence.split which creates a new array of equal size to the string. So... This is O(n) space complexity.

You were asked to do this in place.

end
# binding.pry
# print words
final_word = words.join(" ")

Choose a reason for hiding this comment

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

This works, but you assume each word is separated by one space. That's not necessarily true.

# Time complexity: ?
# Space complexity: ?
# Time complexity: o(n^2)
# Space complexity: o(1)

Choose a reason for hiding this comment

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

Since you do .split this has space complexity of O(n).

# Space complexity: ?
# Time complexity: o(n^2)
# Space complexity: o(1)
def sort_by_length(my_sentence)

Choose a reason for hiding this comment

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

Nice bubblesort.

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