4.3.5 Sorting algorithms Flashcards

1
Q

What is the time complexity of:
Bubble sort
Merge sort

A

O(n^2)

O(nlog n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a merge sort?

A

It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The array is recursively divided in two halves till the size becomes 1. Once the size becomes 1, the merge processes comes into action and starts merging arrays back till the complete array is merged.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is bubble sort n^2?

A

In each pass through the list n items will be examined;

There will be (at most) n passes through the list;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly