1
MERGE SORT Name__________________________ Follow the algorithm for a merge sort and analyze its usefulness. The algorithm for a merge sort is as follows: 1. Split the set of cards into two equal sets (or almost equal with an odd number of cards). 2. Repeat step 1 until there are no more than 2 cards in each set. 3. For each set, flip over both cards. If they are in order, flip face down. If they are not, swap them and then flip them both face down. 4. Take two sets and merge them as follows: A. Flip over the smallest card from each set. B. Place the smaller one in the first open slot in a new set, then flip it face-down. C. Flip over the next card in the set that just came from, so there are 2 face-up cards. D. Repeat steps A-C until there are no face-up cards. 5. Repeat step 4 until all sets are merged. Perform the merge sort on your set of 8 cards. 1) What is the least number of steps this method could take? 2) What is the maximum number of steps this method could take? 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?

Merge Sort

Embed Size (px)

DESCRIPTION

Analyzing the merge sort complexity using cards.

Citation preview

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

    The algorithm for a merge sort is as follows:

    1. Split the set of cards into two equal sets (or almost equal with an odd number of cards). 2. Repeat step 1 until there are no more than 2 cards in each set. 3. For each set, flip over both cards. If they are in order, flip face down. If they are not, swap

    them and then flip them both face down. 4. Take two sets and merge them as follows:

    A. Flip over the smallest card from each set. B. Place the smaller one in the first open slot in a new set, then flip it face-down. C. Flip over the next card in the set that just came from, so there are 2 face-up cards. D. Repeat steps A-C until there are no face-up cards.

    5. Repeat step 4 until all sets are merged.

    Perform the merge sort on your set of 8 cards.

    1) What is the least number of steps this method could take?

    2) What is the maximum number of steps this method could take?

    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?