Draw a flowchart for the Bubble Sort algorithm to sort the list [5, 3, 8, 4] in ascending order.
0
0
Sorting algorithms (bubble, selection) in Intro to Computing - Draw & Build Visually
Draw This - beginner
10 minutes
Hint 1
Hint 2
Hint 3
Grading Criteria
Start and End oval symbols present
Initialization steps for counters (i and j) included
Decision diamonds used for comparisons (j < length-1-i and list[j] > list[j+1])
Swapping step clearly shown when condition is true
Loop back arrows correctly connect decisions and processes
Swapped flag used to detect if sorting is complete
Flowchart covers all passes until no swaps occur
Solution
j
j+1
j
Go back to |
j
j+1
↩Go back to |
This flowchart shows the Bubble Sort algorithm working on the list [5, 3, 8, 4].
1. Start with i = 0, which tracks how many passes have been done.
2. Set a flag swapped to false to check if any swaps happen in this pass.
3. Use j to compare adjacent elements from the start to the end minus the sorted part.
4. If list[j] is greater than list[j+1], swap them and set swapped to true.
5. Increment j and repeat until the end of the unsorted part.
6. If no swaps happened (swapped is false), the list is sorted and the algorithm ends.
7. Otherwise, increment i and repeat the process for the next pass.
This process continues until the list is fully sorted in ascending order.
Variations - 2 Challenges
[intermediate] Draw a flowchart for the Selection Sort algorithm to sort the list [7, 2, 9, 1] in ascending order.
[advanced] Draw a flowchart for Bubble Sort to sort the list [4, 6, 2, 9, 1] in descending order.