2.3.3 Sorting Algorithms Flashcards

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

How can a bubble sort be improved?

A

Adding a flag to record whether or not a swap has occured

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

Which sorting algorithm compares and swaps pairs of elements?

A

Bubble sort

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

What sorting algorithm places the largest element after the first pass?

A

Bubble sort

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

Name the 2 functions of a merge sort.

A

MergeSort( )
Merge( )

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

Which sorting algorithm uses pivots?

A

Quick sort

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

Which sorting algorithm is the fastest?

A

Quick sort

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

Outline the stages of a bubble sort.

A

Compare first value in list with the next
If first is bigger, swap the positions
Move to second value
Repeat until no more items to compare
Return to start of list
Repeat until pass through made without any swaps needed

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

Outline the stages of a merge sort.

A

Repeatedly divide list in two until all elements separated into sublists
Merge sublists to produce new sorted sublist
Repeat until elements are in single list

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

Outline the stages of an insertion sort.

A

Separates first value as sorted list
Compare next value in unsorted list with sorted
Move value to correct position
Repeat until the end of the list is reached

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

Outline the stages of a quick sort.

A

Pivot element selected
All elements less than moved to left of pivot, all elements greater move to right
Repeat process with new pivots for each side of list

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

What does the left pointer do in a quick sort?

A

Moves right until item larger than pivot found then it stops and hands to right pointer

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

What does the right pointer do in a quick sort?

A

Moves left until item smaller than pivot found then stops

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

What is the disadvantage of a quick sort?

A

If the split point is skewed too far left or right, division will be uneven
Results in O(n²) time complexity

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

What is the time complexity for bubble sort?

A

O(n)

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

What is the time complexity for merge sort?

A

O(n log n)

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

What is the time complexity for quick sort?

A

O (n log n)

17
Q

What is the time complexity for insertion sort?

A

O(n²)