IBM Family Science Saturdays Wanna Build Your Own

IBM Family Science Saturdays Wanna Build Your Own Watson? Intro to Your Must Know Algorithms ANCA SAILER In-class Handout

1. Out-of-Place Selection Sort Algorithm Start with a) b) An empty (sorted) list An unsorted list of items to add to the list 2. Now Select the lightest item from your unsorted list and move that item into the sorted list. 3. Then Select the next lightest item from your unsorted list and move that item to the end of your sorted list. 4. Repeat step 3 until your unsorted list is empty.

Insertion Sort Algorithm 1. Start with a) b) An empty (sorted) list An unsorted list of items to add to the list 2. Put the first item from the unsorted list into the sorted list. 3. Take the next item from the unsorted list and “compare it” to the first item of the sorted list. a) b) If item from the sorted list lighter, repeat step 3 with the next item from the sorted list. If the item from the unsorted list is lighter, insert that item into the sorted list by placing it “before” the item you just compared it to. Leave the rest of the sorted list in the same order. 4. Repeat step 3 until the unsorted list is empty.

Merge Sort Algorithm (the merge step) 1. Start with two sorted lists, each sorted low->high 2. Compare the first item from each list. 3. Put the lighter of the two items into the merged list and return the other item to its original list. 4. Repeat steps 2 and 3 until you have a complete merged list. Note that if one list runs out of items, you can simply add all the items from the other list in order to the end of the combined list.

Map Coloring-1 Have. To Algorithm: Change colors only when you “have to” How many colors do you “Have. To” use? _____

Map Coloring-2 Have. To Algorithm: Change colors only when you “have to” How many colors do you “Have. To” use? _____

Map Coloring-3 Have. To Algorithm: Change colors only when you “have to” How many colors do you “Have. To” use? _____

Map Coloring Kit* red red red blue blue blue green green green orange orange orange green orange * Color as indicated and cut the individual squares.

Cyphers and Codes Decoding T Encoding H A N K T H S F O R C S F O M I N G O T O F A M T I L Y S C I I E N C E I Coded Message: T S O T I I H F … Note: Recipient must know width of grid (in this example, 5) in order to decode the message.

Cyphers and Codes Coded Message: 8 DFHFTMNLORFOROOOAD LUYUNIARBKSFTOPTERTE EWOOUTMNEAWFHRLRJA DCBIROCESWKSOLTIWEV EXEWMEHEIYELX Decoding D F H (This message happens to be a quote from Thomas J. Watson, the founder of IBM. ) Algorithm: 1) 2) 3) 4) 5) Create a grid with 8 columns. Count the letters in the message. Divide by 8 and make that many rows Fill the letters down the columns of your grid. Once done, read the message across the rows. 8 columns wide

Coin Tossing 0 1 2 3 4
- Slides: 11