Flashcards on Insertion sort
Insertion Sort: Simplified Guide to Its Algorithm & Complexity
Tap to flip · Swipe to navigate
Insertion Sort Algorithm
18 cards
Card 1
Question: What kind of sorting algorithm is insertion sort?
Answer: Insertion sort is a straightforward and intuitive sorting algorithm that builds a final sorted array one item at a time.
Card 2
Question: When is insertion sort particularly effective?
Answer: It is particularly effective for small data sets or for lists that are already mostly sorted.
Card 3
Question: What analogy is used to understand the principle behind insertion sort?
Answer: The card sorting analogy, where you sort a hand of playing cards in ascending order.
Card 4
Question: How does the card sorting analogy relate to insertion sort?
Answer: You pick one card at a time, compare it with already sorted cards in your other hand, and insert it into its correct position, shifting larger cards.
Card 5
Question: How does insertion sort conceptually divide an array?
Answer: It divides the array into two conceptual parts: a sorted sub-array and an unsorted sub-array.
Card 6
Question: What is the initial state of the sorted sub-array in insertion sort?
Answer: Initially, the first element of the array is considered sorted.
Card 7
Question: In insertion sort, what is the 'key' in the step-by-step process?
Answer: The 'key' is the current element taken from the unsorted part of the array.
Card 8
Question: How does insertion sort compare the 'key' with elements in the sorted sub-array?
Answer: It compares the key with elements in the sorted sub-array, moving from right to left (from the element just before the key, backwards towards the begi
Card 9
Question: What happens if an element in the sorted sub-array is greater than the 'key' during insertion sort?
Answer: If an element in the sorted sub-array is greater than the key, it is shifted one position to the right to make space for the key.
Card 10
Question: When does the shifting stop during the insertion process in insertion sort?
Answer: Shifting continues until an element smaller than or equal to the key is found, or the beginning of the array is reached.