Sorting Algorithms Flashcards
What is the merge sort?
A sorting algorithm that is more efficient than bubble sort.
What is the first step in the merge sort algorithm?
Divide the unsorted list into n sublists, each containing one element.
What is the second step in the merge sort algorithm?
Repeatedly merge two sublists at a time to produce new sorted sublists until there is only one sublist remaining.
True or False: Merge sort produces a sorted list by repeatedly merging sublists.
True
Fill in the blank: Merge sort is much more efficient than _______.
bubble sort
What is the main operation performed in a bubble sort?
Each pair of items are compared and if the first one is greater, the items swap.
This process continues until the entire list is sorted.
What happens after one pass of bubble sort?
The last item will be in place.
This means that the largest item has been moved to its correct position.
How many passes are needed to sort n items in bubble sort?
The maximum number of passes is n - 1.
This accounts for the worst-case scenario where each item needs to be compared with every other item.
What additional variable is needed to swap two items in programming?
An extra ‘temp’ variable.
This variable temporarily holds one item during the swap process.
What Boolean variable is used in bubble sort?
A Boolean variable to check if any swaps had been made in that pass.
This helps to determine if the list is already sorted.
Fill in the blank: In a bubble sort, after two passes, the last _______ items will be sorted.
two
Each pass places at least one more item in its correct position.