Skip to content

Conversation

@brilatimer
Copy link

Sorting & Reverse Sentence

Question Answer
Describe how Bubble Sort works Compares adjacent elements and swaps if in wrong order, largest element is at the top.
Describe how Selection Sort works Finds smallest element and moves to the front, continues through grouping and moves smaller items to the front as needed until sorted.
Describe how Insertion sort works Works through items, moving each item to the front based on small to large, as it moves through list.
Which Sorting Algorithm has the best time complexity? Insertion sort has the best time complexity, O(n).
 

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.

Well done! You hit all the learning goals here. Take a look at my comments and let me know if you have questions

Comment on lines +6 to +19
def reverse_word(string, start, ending)

i = start
j = ending

while i < j
temp = string[i]
string[i] = string[j]
string[j] = temp

i += 1
j -= 1
end
end

Choose a reason for hiding this comment

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

Love the helper method!

def reverse_sentence(my_sentence)
raise NotImplementedError
# Time complexity: O(N)
# Space complexity: O(N)

Choose a reason for hiding this comment

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

Since you're not making another string or array, this is actually O(1) space complexity.

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

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