Sorting Algorithms Flashcards
Which sorting algorithm makes comparisons and swaps between pairs of elements?
Bubble sort
Which example shows bubble sort?
A B C 3 5 4 1 2 -> 3 4 5 1 2 -> 3 4 1 5 2 -> 3 1 4 5 2 -> 1 3 4 5 2 -> 1 2 3 4 5
Which example showed bubble sort?
B
Which example shows insertion sort?
A B C 3 5 4 1 2 -> 3 5 4 1 2 -> 4 5 1 2 -> 4 1 5 2 -> 1 2 4 5 -> 3 2 4 5 -> 1 2 3 4 5.
Which example showed bubble sort?
C
Which sorting algorithm is shown here?
Quick sort with the middle element chosen as the pivot.
Perform the first pass of bubble sort on the values 4 2 3 5 1.
4 2 3 5 1 -> 2 4 3 5 1 -> 3 2 4 5 1 -> 3 4 2 5 1 -> 1 3 4 5.
Which sorting algorithm can be improved by adding a flag to record whether or not a swap has occurred?
Bubble sort.
Perform insertion sort on the values 4 2 3 5 1.
Initial: 4 2 3 5 1 -> 2 4 3 5 1 -> 3 2 4 5 1 -> 1 2 3 4 5.
Name the two functions in merge sort.
MergeSort and Merge.
In which sorting algorithm is the largest element in place after the first pass?
Bubble sort.
Which sorting algorithm uses pivots?
Quick sort.
Which of our sorting algorithms is the most efficient?
Merge sort.
Perform merge sort on the values 4 2 3 5.
Initial: 4 2 3 5 -> 4 2 3 5 -> 2 4 3 5 -> 2 3 4 5.