Unit 3, Chapter 1, Lesson 3: Creativity in Algorithms

Objectives

Students will be able to:

  1. Develop an algorithm to solve a new problem with playing cards
  2. Express an algorithm in the Human Machine Language
  3. Identify Sequencing, Selection and Iteration in a program written the Human Machine Language
  4. Describe the properties of the Human Machine Language that make it a “low level” language.

Getting Started

Conclusions from Find Min

  1. Finish FindMin from last class–remember you can use the scissors to cut the commands or your can just write them in pencil
  2. Before moving on to the activity you should all have some solution to FindMin written in the Human Machine Language.

Creativity in Algorithms

  1. 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.
  2. 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.
  3. 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?
  4. Today we’ll challenge you with a few more problems that will require you to get creative!

Activity

Adding SWAP to Human Machine Language

  1. Get the – Human Machine Language – Part 2: Min To Front – Activity Guide from your teacher
  2. Get with a partner
  3. Review the first page of the activity guide and the addition of the “swap” command.
  4. Do the example program
  5. 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)

Challenge: Min-to-Front

  1. 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.
  2. As you work try to solve the problem in pieces.
  3. Here are some suggestions:
    1. IDEA: Solve move-to-front first
      1. Remember: “Algorithms can be combined to make new algorithms”
      2. You should know a solution to find min, so you can put that out of mind for a minute.
      3. 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.
      4. Once you’ve got that you can tack the two together
    2. IDEA: Don’t be afraid to invent a completely new algorithm
      1. get creative – you might need or want to invent a whole new algorithm

Wrap Up

  1. 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.
  2. 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.
  3. 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

Leave a comment

Your email address will not be published. Required fields are marked *