What is an Algorithm? TechNights October 17, 2016
An Algorithm Is… A step-by-step set of instructions for a specific task Clear and organized What algorithms do you know about?
Lego Construction Algorithm Teams of four Look at the picture and build the object Write directions on the paper (an algorithm!) Trade pieces and directions with another team Follow the directions to build the object—2 minutes! Compare with the picture A total of 5 minutes for this exercise.
Lego Construction Algorithm Can we do better? Give them 10 minutes
Problem-Solving Strategies Our Toolbox Problem-Solving Strategies
“Brute Force”
How would you find the piece that fits? Jigsaw – each girl should have one piece Give them 3-4 minutes
“Divide and Conquer” Give everyone a number. Sort yourselves! Recursion!
Sort yourselves By Birthdays! Volunteers – choose a girl to be a pivot for a couple groups Remember Quicksort?
Bisection How do we search effectively? We run a binary search on the girls Whose birthday is closest to today?
Bisection
Bisection
Bisection
Bisection
“Greedy” Knapsack Problem
Limit: 20 pounds A. $1, 3 pounds B. $9, 4 pounds C. $5, 2 pounds D. $9, 6 pounds E. $11, 7 pounds F. $6, 3 pounds G. $12, 5 pounds 1. Choose the best item 2. If it fits, put it in and go to step 1 3. If it doesn’t, put it aside and go to step 1 4. If there are no more items, stop 5. If your bag is full, stop 6. Otherwise, go to step 1
Choose the most ‘dense’ 1. Choose the best item 2. If it fits, put it in and go to step 1 3. If it doesn’t, put it aside and go to step 1 4. If there are no more items, stop 5. If your bag is full, stop 6. Otherwise, go to step 1 A. $1, 3 pounds = 0.33 B. $9, 4 pounds = 2.25 C. $5, 2 pounds = 2.5 D. $9, 6 pounds = 1.5 E. $11, 7 pounds = 1.6 F. $6, 3 pounds = 2 G. $12, 5 pounds = 2.4 Answer they should get: $50 Also the optimal answer
How do I write a clear algorithm? What strategies can I use? Reflection How do I write a clear algorithm? What strategies can I use?