0
0
Intro to Computingfundamentals~10 mins

Sorting algorithms (bubble, selection) in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to swap two elements in a list.

Intro to Computing
temp = arr[[1]]
arr[[1]] = arr[[2]]
arr[[2]] = temp
Drag options to blanks, or click blank then click option'
Ai
Bj
C0
Dlen(arr)
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with wrong indices
Using the same index twice
2fill in blank
medium

Complete the code to compare two adjacent elements in bubble sort.

Intro to Computing
if arr[[1]] > arr[[2]]:
Drag options to blanks, or click blank then click option'
Ai
Bi+1
Cj
Dj+1
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing wrong indices
Using outer loop variable instead of inner loop variable
3fill in blank
hard

Fix the error in the selection sort inner loop condition.

Intro to Computing
for j in range(i+1, [1]):
Drag options to blanks, or click blank then click option'
Ai
Blen(arr)-1
Clen(arr)
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(arr)-1 which skips last element
Using wrong start index
4fill in blank
hard

Fill both blanks to complete the bubble sort outer and inner loops.

Intro to Computing
for i in range([1]):
    for j in range([2] - i - 1):
Drag options to blanks, or click blank then click option'
Alen(arr)
Blen(arr) - 1
Clen(arr) - i
Dlen(arr) + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(arr) - 1 for outer loop
Incorrect inner loop range causing index errors
5fill in blank
hard

Fill all three blanks to complete the selection sort swap step.

Intro to Computing
min_idx = [1]
for j in range(i+1, [2]):
    if arr[j] < arr[min_idx]:
        min_idx = j
arr[[3]], arr[i] = arr[i], arr[[3]]
Drag options to blanks, or click blank then click option'
Ai
Blen(arr)
Cmin_idx
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping wrong indices
Incorrect loop range
Not updating min_idx correctly