Sorting Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Which sorting algorithm makes comparisons and swaps between pairs of elements?

A

Bubble sort

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

Which example shows bubble sort?

A

A B C 3 5 4 1 2 -> 3 4 5 1 2 -> 3 4 1 5 2 -> 3 1 4 5 2 -> 1 3 4 5 2 -> 1 2 3 4 5

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

Which example showed bubble sort?

A

B

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

Which example shows insertion sort?

A

A B C 3 5 4 1 2 -> 3 5 4 1 2 -> 4 5 1 2 -> 4 1 5 2 -> 1 2 4 5 -> 3 2 4 5 -> 1 2 3 4 5.

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

Which example showed bubble sort?

A

C

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

Which sorting algorithm is shown here?

A

Quick sort with the middle element chosen as the pivot.

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

Perform the first pass of bubble sort on the values 4 2 3 5 1.

A

4 2 3 5 1 -> 2 4 3 5 1 -> 3 2 4 5 1 -> 3 4 2 5 1 -> 1 3 4 5.

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

Which sorting algorithm can be improved by adding a flag to record whether or not a swap has occurred?

A

Bubble sort.

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

Perform insertion sort on the values 4 2 3 5 1.

A

Initial: 4 2 3 5 1 -> 2 4 3 5 1 -> 3 2 4 5 1 -> 1 2 3 4 5.

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

Name the two functions in merge sort.

A

MergeSort and Merge.

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

In which sorting algorithm is the largest element in place after the first pass?

A

Bubble sort.

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

Which sorting algorithm uses pivots?

A

Quick sort.

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

Which of our sorting algorithms is the most efficient?

A

Merge sort.

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

Perform merge sort on the values 4 2 3 5.

A

Initial: 4 2 3 5 -> 4 2 3 5 -> 2 4 3 5 -> 2 3 4 5.

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