Skip to content

Conversation

@criacuervos
Copy link

@criacuervos criacuervos commented Sep 24, 2019

Sorting & Reverse Sentence

Question Answer
Describe how Bubble Sort works by comparing two adjacent items, and swaps them if one is bigger. eventually it moves the largest element to the end through this mechanism. it goes all the way through the array until it reaches the end and starts again.
Describe how Selection Sort works selection sort works by finding the smallest item in an array, and moving it to index 0. then it looks at a subarray, which is the array without the first element, and finds the smallest in there, moving it to the next index, index 1.
Describe how Insertion sort works insertion sort works most of the time as an in place method. it looks at a pair of numbers and figures out which is greater and moves it accordingly. then, it continues swap numbers after the sorted numbers.
Which Sorting Algorithm has the best time complexity? merge sort
 

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, think about how you could have done the reverse sentence in-place. There is a better way.

Otherwise nice work.

# Time complexity: ?
# Space complexity: ?
# 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.

You were requested to do this in-place, so without creating a new array.

Comment on lines +1 to +2
# Time complexity: O(n^2)
# Space complexity: O(n)

Choose a reason for hiding this comment

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

Correct space complexity is correct since you have to split the string.

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