1
BUBBLE SORT Name__________________________ Follow the algorithm for a merge sort and analyze its usefulness. The algorithm for a bubble sort is as follows: 1. Flip over the first two cards. 2. If they are in order (smaller one first), leave them as is. 3. If they are not in order (larger one first), swap the positions. 4. Flip the earlier card face down, then flip up the next card. 5. Repeat steps 2-4 until you reach the end of the list, then flip all cards face down. 6. Repeat steps 1-6 until the whole list is in order. Perform the bubble 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?

Bubble Sort

Embed Size (px)

DESCRIPTION

Analyzing the bubble sort complexity using cards.

Citation preview

  • BUBBLE SORT Name__________________________ Follow the algorithm for a merge sort and analyze its usefulness.

    The algorithm for a bubble sort is as follows:

    1. Flip over the first two cards. 2. If they are in order (smaller one first), leave them as is. 3. If they are not in order (larger one first), swap the positions. 4. Flip the earlier card face down, then flip up the next card. 5. Repeat steps 2-4 until you reach the end of the list, then flip all cards face down. 6. Repeat steps 1-6 until the whole list is in order.

    Perform the bubble 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?