Bubble and selection sort
Algorithms must be understood operationally: how they behave, how to trace them, and when their efficiency makes them suitable.
What you need to be able to do
- Construct + trace + evaluateAnd trace algorithms to implement bubble sort and selection sort, evaluating their time and space complexities
Rapid Recall Deck
Say the answer aloud before flipping. Mark secure knowledge quickly and spend time on the gaps.
- What does bubble sort do during a pass through a list?: It compares adjacent items and swaps them when they are in the wrong order, causing larger or smaller values to move toward one end.
- What does selection sort do during each pass?: It finds the smallest or largest remaining item and places it into its next correct position.
- What is the key operational difference between bubble sort and selection sort?: Bubble sort repeatedly swaps adjacent items; selection sort repeatedly selects an extreme value and usually performs fewer swaps.
- How do basic bubble sort and selection sort scale?: Their time grows quadratically, O(n²), for typical/worst-case analysis, so both become inefficient on large data sets.
- What space characteristic do basic in-place bubble and selection sorts share?: They use only a small fixed amount of additional memory, commonly described as O(1) auxiliary space.
Core knowledge and application
And trace algorithms to implement bubble sort and selection sort, evaluating their time and space complexities
Algorithms must be understood operationally: how they behave, how to trace them, and when their efficiency makes them suitable.
Explain it without notes
Construct + trace + evaluate: And trace algorithms to implement bubble sort and selection sort, evaluating their time and space complexities in the context of a program that searches and organizes a growing dataset.
- The time and space complexities of each algorithm, denoted by their respective Big O notations
- The advantages and disadvantages of each algorithm in terms of efficiency across various data sets
Programming checkpoint
for end in range(len(data)-1, 0, -1):
for i in range(end):
if data[i] > data[i+1]:
data[i], data[i+1] = data[i+1], data[i]for (int end = data.length - 1; end > 0; end--) {
for (int i = 0; i < end; i++) {
if (data[i] > data[i+1]) {
int t = data[i]; data[i] = data[i+1]; data[i+1] = t;
}
}
}Modify it
Change one condition, input or operation so the program solves a slightly different problem. Predict the effect before editing.
Bubble sort vs selection sort
Bubble sort idea
Compare adjacent items and swap those that are out of order. After each full pass, one large item has “bubbled” toward its final position.
Selection sort idea
Find the smallest item in the unsorted region and swap it into the next fixed position.
for start in range(len(data) - 1):
min_i = start
for i in range(start + 1, len(data)):
if data[i] < data[min_i]:
min_i = i
data[start], data[min_i] = data[min_i], data[start]for (int start = 0; start < data.length - 1; start++) {
int minI = start;
for (int i = start + 1; i < data.length; i++) {
if (data[i] < data[minI]) minI = i;
}
int t = data[start]; data[start] = data[minI]; data[minI] = t;
}Transfer to a new scenario
- The time and space complexities of each algorithm, denoted by their respective Big O notations
- The advantages and disadvantages of each algorithm in terms of efficiency across various data sets
Paper 2 practice
- Construct + trace + evaluate: And trace algorithms to implement bubble sort and selection sort, evaluating their time and space complexities in the context of a program that searches and organizes a growing dataset.
Finish the learning cycle
IA — main task
Refine Criteria A/B/C. Use today’s lesson to make the problem specification, decomposition, algorithms or testing plan more precise where relevant.
Syllabus — 10–15 min
Repeat the recall deck and complete the lesson response prompt without model support.