1
INSERTION SORT Name__________________________ Follow the algorithm for a insertion sort and analyze its usefulness. The algorithm for an insertion sort is as follows: 1. Flip over the first card. 2. Flip over the next card - if it is bigger than the last card, leave it where it is. 3. If the new card is smaller, swap the two face-up cards. Then flip the card before it and compare again. Keep swapping until the previous card is smaller. 4. Flip all but the last face-up card face-down. 5. Repeat steps 2-4 until you reach the end of the list. Perform the insertion sort on your set of 8 cards. 1) What is the least number of steps this method could take? What type of situation would this be? 2) What is the maximum number of steps this method could take? What type of situation would this be? 3) What about if you used n cards? 4) If you were to alphabetize the books on a bookshelf using this method, what would that look like?

Insertion Sort

Embed Size (px)

DESCRIPTION

Analyzing the insertion sort complexity using cards.

Citation preview

  • INSERTION SORT Name__________________________ Follow the algorithm for a insertion sort and analyze its usefulness.

    The algorithm for an insertion sort is as follows:

    1. Flip over the first card. 2. Flip over the next card - if it is bigger than the last card, leave it where it is. 3. If the new card is smaller, swap the two face-up cards. Then flip the card before it and compare

    again. Keep swapping until the previous card is smaller. 4. Flip all but the last face-up card face-down. 5. Repeat steps 2-4 until you reach the end of the list.

    Perform the insertion sort on your set of 8 cards.

    1) What is the least number of steps this method could take? What type of situation would this be?

    2) What is the maximum number of steps this method could take? What type of situation would this be?

    3) What about if you used n cards?

    4) If you were to alphabetize the books on a bookshelf using this method, what would that look like?