Unit 3, Chapter 1, Lesson 3: Creativity in Algorithms
Students will be able to:
- Develop an algorithm to solve a new problem with playing cards
- Express an algorithm in the Human Machine Language
- Identify Sequencing, Selection and Iteration in a program written the Human Machine Language
- Describe the properties of the Human Machine Language that make it a “low level” language.
Conclusions from Find Min
- Finish FindMin from last class–remember you can use the scissors to cut the commands or your can just write them in pencil
- Before moving on to the activity you should all have some solution to FindMin written in the Human Machine Language.
Creativity in Algorithms
- One thing about algorithms is that once you know a few, and know how they work, you can combine them (or slightly modify them) to solve new problems. Creativity in algorithms comes from figuring out clever ways to solve problems by developing a process that could be executed by a machine.
- We study algorithms and care about them because in programming the techniques and mechanics of certain processes come up over and over and over again. So it’s worth knowing a few so you don’t have to reinvent the wheel.
- For example, you just wrote an algorithm to find the smallest card in a row of cards. Is it hard to modify that exact same strategy to find the max card?
- Today we’ll challenge you with a few more problems that will require you to get creative!
Adding SWAP to Human Machine Language
- Get the – Human Machine Language – Part 2: Min To Front – Activity Guide from your teacher
- Get with a partner
- Review the first page of the activity guide and the addition of the “swap” command.
- Do the example program
- Review the example: Here is the solution–END STATE: the order of the cards has been reversed. It does this by first moving the right hand to the end of the list, then shifting each hand progressively toward the middle of the orw, swapping cards each time. The program stops once the hands have crossed over each other (by checking if RHPos<LHPos)
- The challenge is to find the min card and swap it to the front of the list, keeping the order of the rest of the cards the same.
- As you work try to solve the problem in pieces.
- Here are some suggestions:
- IDEA: Solve move-to-front first
- Remember: “Algorithms can be combined to make new algorithms”
- You should know a solution to find min, so you can put that out of mind for a minute.
- Start by assuming that you’ve found the min card, and writing a procedure to move some card to the front of the list, by swapping.
- Once you’ve got that you can tack the two together
- IDEA: Don’t be afraid to invent a completely new algorithm
- get creative – you might need or want to invent a whole new algorithm
- Learning to program is really learning how to think in terms of algorithms and processes. And it can be really fun and addicting. It also can make you feel like you have magical powers.
- In the next lesson we’ll start writing programs that a real machine (not a human machine) will execute. But since programming is really about thinking and problem solving your “human machine” skills will come in handy – reasoning about program is also about reasoning about what a computer can and cannot do, and what the given language you’re using let’s you and doesn’t let you do.
- If you didn’t want to learn how to program before, perhaps this video will change your mind… You Should Learn to Program: Christian Genco at TEDxSMU – Video