Bubble sort Flashcards

(9 cards)

1
Q

What is a sorting algorithm?

A

• An algorithm that arranges data into order

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

What orders are sorting algorithms usually used for?

A

• Ascending
• Descending

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

What three sorting algorithms should you know?

A

• Bubble sort
• Merge sort
• Insertion sort

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

How does bubble sort work?

A

• Compare adjacent items
• Swap if they are in the wrong order
• Repeat passes until no swaps are needed

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

What happens in each pass of a bubble sort?

A

• Adjacent items are compared
• Swaps are made if needed
• The largest unsorted item moves towards the end

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

Why are fewer comparisons needed in later passes of bubble sort?

A

• The largest values have already moved to the end

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

When does bubble sort stop?

A

• When a full pass makes no swaps

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

What are the advantages of bubble sort?

A

• Easy to understand
• Easy to implement

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

What are the disadvantages of bubble sort?

A

• Slow on large lists
• Slow on reverse-ordered lists

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