Week 4: Sorting Flashcards
Which of the following best describes sorting?
A) The process of randomly arranging items in a collection.
B) The process of arranging or ordering a collection of items such that each item and its successor satisfy a prescribed relationship.
C) The process of removing items from a collection.
D) The process of adding items to a collection.
B) The process of arranging or ordering a collection of items such that each item and its successor satisfy a prescribed relationship.
Explanation: Sorting is the process of arranging or ordering a collection of items based on the value of a sort key, making it easier to find and access items.
Which of the following statements about Bubble Sort is true?
A) Bubble Sort rearranges values by iterating over the list once.
B) Bubble Sort is a divide-and-conquer algorithm.
C) Bubble Sort rearranges values by iterating over the list multiple times, causing larger values to bubble to the top or end of the list.
D) Bubble Sort builds the final sorted array one element at a time.
C) Bubble Sort rearranges values by iterating over the list multiple times, causing larger values to bubble to the top or end of the list.
Explanation: Bubble Sort iterates over the list multiple times, comparing adjacent elements and swapping them if they are in the wrong order, causing larger values to move to the end of the list.
Which of the following statements about Selection Sort is true?
A) Selection Sort rearranges values by iterating over the list multiple times.
B) Selection Sort is a divide-and-conquer algorithm.
C) Selection Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
D) Selection Sort builds the final sorted array one element at a time.
C) Selection Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
Explanation: Selection Sort repeatedly finds the minimum element from the unsorted part of the array and places it at the beginning, gradually sorting the array.
Which of the following statements about Merge Sort is true?
A) Merge Sort rearranges values by iterating over the list multiple times.
B) Merge Sort is a simple sorting algorithm that builds the final sorted array one element at a time.
C) Merge Sort is a divide-and-conquer algorithm that recursively divides the list into smaller sublists, sorts them, and then merges them back together.
D) Merge Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
C) Merge Sort is a divide-and-conquer algorithm that recursively divides the list into smaller sublists, sorts them, and then merges them back together.
Explanation: Merge Sort is a divide-and-conquer algorithm that recursively divides the list into smaller sublists, sorts them, and then merges them back together to form a sorted list.
Which of the following statements about Insertion Sort is true?
A) Insertion Sort rearranges values by iterating over the list multiple times.
B) Insertion Sort is a divide-and-conquer algorithm.
C) Insertion Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
D) Insertion Sort builds the final sorted array one element at a time by iterating through an array or list of elements, comparing each element to the one before it, and swapping them if they are not in the correct order.
D) Insertion Sort builds the final sorted array one element at a time by iterating through an array or list of elements, comparing each element to the one before it, and swapping them if they are not in the correct order.
Explanation: Insertion Sort builds the final sorted array one element at a time by iterating through the array, comparing each element to the one before it, and swapping them if they are not in the correct order.
Which of the following statements about Quick Sort is true?
A) Quick Sort rearranges values by iterating over the list multiple times.
B) Quick Sort is a simple sorting algorithm that builds the final sorted array one element at a time.
C) Quick Sort works by selecting a pivot element, partitioning the list around the pivot, and then recursively sorting the two sub-lists.
D) Quick Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
C) Quick Sort works by selecting a pivot element, partitioning the list around the pivot, and then recursively sorting the two sub-lists.
Explanation: Quick Sort works by selecting a pivot element, partitioning the list around the pivot, and then recursively sorting the two sub-lists.
Which of the following statements about Heap Sort is true?
A) Heap Sort rearranges values by iterating over the list multiple times.
B) Heap Sort is a simple sorting algorithm that builds the final sorted array one element at a time.
C) Heap Sort works by creating a binary heap from the list and then repeatedly extracting the maximum element and adding it to the sorted portion of the list.
D) Heap Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
C) Heap Sort works by creating a binary heap from the list and then repeatedly extracting the maximum element and adding it to the sorted portion of the list.
Explanation: Heap Sort works by creating a binary heap from the list and then repeatedly extracting the maximum element and adding it to the sorted portion of the list.
Which of the following statements about Radix Sort is true?
A) Radix Sort rearranges values by iterating over the list multiple times.
B) Radix Sort is a simple sorting algorithm that builds the final sorted array one element at a time.
C) Radix Sort works by sorting the elements based on their individual digits or characters.
D) Radix Sort sorts an array by repeatedly finding the minimum element from the unsorted part of the array and placing it at the beginning.
C) Radix Sort works by sorting the elements based on their individual digits or characters.
Explanation: Radix Sort works by sorting the elements based on their individual digits or characters.
Which method is used to sort a list in Python in place?
A) sorted()
B) sort()
C) reverse()
D) key()
B) sort()
Explanation: The sort() method is used to sort a list in place in Python.
Which method is used to return a new sorted list from an iterable in Python?
A) sorted()
B) sort()
C) reverse()
D) key()
A) sorted()
Explanation: The sorted() method is used to return a new sorted list from an iterable in Python.