Given the list [5, 3, 8, 4], what is the list after the first full pass of bubble sort?
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]
Bubble sort compares adjacent pairs and swaps if the left is bigger.
After the first pass, the largest number moves to the end. The swaps are: 5 and 3 swap → [3,5,8,4], then 5 and 8 no swap, then 8 and 4 swap → [3,5,4,8].
Which statement best describes the main idea of selection sort?
Think about how selection sort picks elements to place in order.
Selection sort finds the smallest element in the unsorted part and swaps it with the first unsorted element, moving the boundary forward.
Which of the following is true about bubble sort compared to selection sort?
Consider how each algorithm moves elements during sorting.
Bubble sort swaps adjacent elements whenever they are out of order, often many times per pass. Selection sort only swaps once per pass when placing the smallest element.
What is the list after the first pass of selection sort on [7, 2, 5, 3]?
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]
Selection sort finds the smallest element and swaps it with the first element.
The smallest element is 2 at index 1. It swaps with element at index 0 (7), resulting in [2, 7, 5, 3].
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?
Think about which algorithm moves the largest element to the end each pass by swapping neighbors.
Bubble sort works by swapping adjacent elements and pushing the largest unsorted element to the end after each pass.