0
0
Intro to Computingfundamentals~20 mins

Sorting algorithms (bubble, selection) in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sorting Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
trace
intermediate
2:00remaining
Trace the Bubble Sort Process

Given the list [5, 3, 8, 4], what is the list after the first full pass of bubble sort?

Intro to Computing
lst = [5, 3, 8, 4]
for i in range(len(lst)-1):
    if lst[i] > lst[i+1]:
        lst[i], lst[i+1] = lst[i+1], lst[i]
A[3, 5, 4, 8]
B[3, 4, 5, 8]
C[5, 3, 4, 8]
D[3, 5, 8, 4]
Attempts:
2 left
💡 Hint

Bubble sort compares adjacent pairs and swaps if the left is bigger.

🧠 Conceptual
intermediate
1:30remaining
Selection Sort Key Idea

Which statement best describes the main idea of selection sort?

ARepeatedly find the smallest unsorted element and move it to the front.
BRepeatedly swap adjacent elements if they are in the wrong order.
CUse a pivot to partition the list into smaller and larger elements.
DDivide the list into halves and sort each half recursively.
Attempts:
2 left
💡 Hint

Think about how selection sort picks elements to place in order.

Comparison
advanced
1:30remaining
Compare Bubble Sort and Selection Sort Behavior

Which of the following is true about bubble sort compared to selection sort?

ASelection sort swaps elements more frequently than bubble sort.
BBubble sort swaps elements more frequently than selection sort.
CBoth algorithms swap elements the same number of times.
DBubble sort never swaps elements.
Attempts:
2 left
💡 Hint

Consider how each algorithm moves elements during sorting.

🔍 Analysis
advanced
2:00remaining
Output of Selection Sort Partial Pass

What is the list after the first pass of selection sort on [7, 2, 5, 3]?

Intro to Computing
lst = [7, 2, 5, 3]
min_index = 0
for j in range(1, len(lst)):
    if lst[j] < lst[min_index]:
        min_index = j
lst[0], lst[min_index] = lst[min_index], lst[0]
A[3, 2, 5, 7]
B[7, 2, 5, 3]
C[2, 7, 5, 3]
D[2, 3, 5, 7]
Attempts:
2 left
💡 Hint

Selection sort finds the smallest element and swaps it with the first element.

identification
expert
1:30remaining
Identify the Algorithm from Behavior

A sorting algorithm repeatedly swaps adjacent elements if they are out of order, and after each full pass, the largest unsorted element moves to its correct position at the end. Which algorithm is this?

ASelection sort
BMerge sort
CInsertion sort
DBubble sort
Attempts:
2 left
💡 Hint

Think about which algorithm moves the largest element to the end each pass by swapping neighbors.