Skip to content

Conversation

@eaball35
Copy link

Sorting & Reverse Sentence

Question Answer
Describe how Bubble Sort works Bubble sort compares each value, bubbling up the max value to the top of the list. Once the max is at the top, the list shrinks by one and iterates through again continuing to bubble the max value to the top each time until the list is ordered.
Describe how Selection Sort works Selection sort works by working with a sorted and unsorted portion of the list. Each iteration you find the minimum value in the unsorted portion and add it to the beginning of the sorted list until the entire list is sorted.
Describe how Insertion sort works Insertion sort works by comparing each element to value and inserting that value into its correct position in "sorted" portion of list. Each time it iterates the list of unsorted values shrinks until all elements are sorted
Which Sorting Algorithm has the best time complexity?  Merge Sort or other more complicated algorithm

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.

As you noted it's not reversing in place. It's also using the = sign to change my_sentence and it has problems with the tests. You do have a good sort. Take a look at my comments and let me know if you have questions.

# Time complexity: O(n^2)
# Space complexity: O(n)

# Doesn't reverse in place - still working

Choose a reason for hiding this comment

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

Gotcha

hi -= 1
low += 1
end
my_sentence = words.join

Choose a reason for hiding this comment

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

Note my lesson in how functions work This won't change the argument. So the tests are failing.

# 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 insertion sort.

# 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.

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

@@ -0,0 +1,19 @@
# require_relative "test_helper"

Choose a reason for hiding this comment

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

Why are these commented out? Made me wonder what was up.

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