2.1 Bubble sort Flashcards

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

bubble sort algorithm

A

compares adjacent data items and orders them

several passes may be needed to sort the whole list

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

order of sorting

A

data can be sorted into ascending or descending order

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

how a bubble sort works

A
  • starts at the first two items, if they are not in the correct order they are swapped
  • looks at the second and third items, if they are in the correct place they are left alone
  • continues until the end of the list
  • passes through the list again until none of the items need to be swapped
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A student has stored the names of some friends in a list

David, Claire, Stefan, Sophie, Matt

Show the stages of a bubble sort when applied to this data to sort it into ascending order [5]

A
pass 1:
*Claire, *David, Stefan, Sophie, Matt
Claire, David, Stefan, Sophie, Matt
Claire, David, *Sophie, *Stefan, Matt
Claire, David, Sophie, *Matt, *Stefan

pass 2:
Claire, David, *Matt, *Sophie, Stefan

pass 3:
Claire, David, Matt, Sophie, Stefan

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

Show the stages of a bubble sort when applied to the following data to sort it into ascending order:

4, 1, 2, 6, 3, 5 [5]

A
pass 1:
*1 *4 2 6 3 5
1 *2 *4 6 3 5
1 2 4 6 3 5
1 2 4 *3 *6 5
1 2 4 3 *5 *6

pass 2:
1 2 4 3 5 6
1 2 4 3 5 6
1 2 *3 *4 5 6

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