2. Developing a Language
◦ To computers to do what we want we need to know what are the “primitive” operations – the
most basic set of operations that will allow us to do most of the tasks that situation requires.
◦ The art (and science) of using well-define languages of primitive operations to solve problems
is the art and science of algorithms.
◦ Algorithms are precise series of sequences of instructions for processes that can be executed
by a computer and are implemented using programing languages.
◦ One way to think of the study of algorithms is that it is the study of processes – how can use a
small set of instructions to clearly and correctly define a process.
◦ Any time you are trying to write a precise set of instructions for a process to solve a problem
you are designing an algorithm.
3. Find the Minimum Card Activity:
◦ We have to think computer can act. We have to think of computational processes – processes
than can be executed by a computer – which have specific sets of constraints
◦ You will act as a “Human Machine” while working on this activity.
◦ When acting a machine, we have to keep the limitations of a computer in mind.
◦ Follow the instructions on the activity guide and come up with an algorithm to find the smallest
card in the set.
◦ Some things to consider:
◦ How do you know when to stop?
◦ Do instructions state where and when to start?
◦ It is clear were to put cards back down after you’ve picked them up?
5. Define Actions
◦ As we look at these algorithms you came up with, we can see they are not all the same.
◦ However, there are common things that you are all making the human machine do and
commonalities in some of your instructions.
◦ Can we define a language of common Human Machine commands for moving cards around?
What are the commands or actions most of these instruction have in common?
◦ SHIFT (hand) – some form of shifting hands one position down the row left or right
◦ MOVE (hand) – some form of moving a hand directly to a particular card based on its position in the list or
to the position of one of the other hands
◦ COMPARE – some way to compare cards and do something based on the results like: “if card in right hand
is less than card in left hand then…”
◦ GO TO LINE – some way to jump to an earlier or later line in the program
◦ PICK CARD UP/PUT CARD DOWN – some way to do this that also makes clear where to put a card
back to.
6. The Human Machine:
◦ For our next activity you will be using the commands we just went over in the last slide and
preforming the commands with algorithms.
◦ Complete the packet using these commands
◦ First learn about how the different commands can be used in a sequence so that you can later
apply these command to create a more complex algorithm.
◦ After getting the gist of things you will then use these same commands to create an algorithm to
find the smallest card in a set.
◦ All cards are face up. Card positions have numbers
◦ Don’t need to pick up cards or put them down. There is actually no way to move cards at all only ands
◦ The ending state is well defined – left and touching the min card.
7. Solution to find Min:
This algorithm has the right
hand shift repeatedly to the
right until it finds a card that is
less than the left hand card, and
then move the left hand to the
position of the right hand – so
the left hand is now on the new
smallest card.
It stops once the right hand
reaches position 7, the end of
the list.
8. Wrap-up
◦ Different algorithms can be developed to solve the same problem.
◦ Even though you were all trying to solve the same problem (find min) as a class we came up with different
methods for doing it. We would say we came up with different algorithms
◦ Different code can be written to implement the same algorithm
◦ This is sometimes surprising to newcomers. When writing “code” (even with the human machine
language) two people trying to write code to implement the same algorithm may very easily code it
differently.
◦ These two facts embody art of programming and what makes programming so fun, engaging and
creative.
◦ A beautiful algorithm is an elegant and clever idea for how to solve a problem.
◦ A beautiful program is an elegant use of whatever language structures are provided to make the algorithm
actually work on a computer.