Sorting Algorithms Flashcards

1
Q

What is the merge sort?

A

A sorting algorithm that is more efficient than bubble sort.

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

What is the first step in the merge sort algorithm?

A

Divide the unsorted list into n sublists, each containing one element.

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

What is the second step in the merge sort algorithm?

A

Repeatedly merge two sublists at a time to produce new sorted sublists until there is only one sublist remaining.

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

True or False: Merge sort produces a sorted list by repeatedly merging sublists.

A

True

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

Fill in the blank: Merge sort is much more efficient than _______.

A

bubble sort

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

What is the main operation performed in a bubble sort?

A

Each pair of items are compared and if the first one is greater, the items swap.

This process continues until the entire list is sorted.

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

What happens after one pass of bubble sort?

A

The last item will be in place.

This means that the largest item has been moved to its correct position.

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

How many passes are needed to sort n items in bubble sort?

A

The maximum number of passes is n - 1.

This accounts for the worst-case scenario where each item needs to be compared with every other item.

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

What additional variable is needed to swap two items in programming?

A

An extra ‘temp’ variable.

This variable temporarily holds one item during the swap process.

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

What Boolean variable is used in bubble sort?

A

A Boolean variable to check if any swaps had been made in that pass.

This helps to determine if the list is already sorted.

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

Fill in the blank: In a bubble sort, after two passes, the last _______ items will be sorted.

A

two

Each pass places at least one more item in its correct position.

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