Anda di halaman 1dari 6

# Introduction to Algorithmic Thinking

Outline
What is an algorithm?
What is algorithmic thinking?
How are algorithms communicated?
Why are algorithms important?
What are the important properties of algorithms?
An example how to create an algorithm
What is an algorithm?
An algorithm is a precise, step-by-step set of instructions for soling a task! An algorithm
does not sole a task" it gies you a series of steps that, if executed correctly, will result
in a solution to a task! #ou use algorithms eery day but you often do not explicitly think
about the indiidual steps of the algorithm! \$or example, starting your car, putting on
your clothes, logging into your computer, or following a recipe for cooking a food dish,
are all accomplished using an algorithm, a step-by-step series of actions!
\$or an algorithm to be alid, each step %or instruction& must be'
unambiguous the instruction can only be interpreted in one uni(ue way
executable the person or deice executing the instruction must know how to
accomplish the instruction without any extra information!
ordered the steps of an algorithm must be ordered in a proper se(uence to
An example algorithm is shown in the seen steps below! )his algorithm explains how to
make *fro+en lemon ice-box pie,* %which is this author,s faorite dessert&!
-tep .' /our . can of chilled pet milk into a mixing bowl!
-tep 0' 1eat the pet milk until peaks form!
-tep 2' *\$old in* . cup of sugar and .30 cup of lemon 4uice!
-tep 5' 6f you want a more lemony taste, add . tsp of grated lemon peal!
-tep 7' -pread a graham cracker crust on the bottom of a .2* by 8* pan!
-tep 9' /our the pet milk mix into the pan!
-tep :' /lace in free+er until fro+en!
1efore leaing this example, ask yourself if the steps to this algorithm meet the criteria
listed aboe! )hat is, is each step unambiguous, executable, and in the correct order?
)his reading explains the concept of algorithms, some important properties of algorithms,
and how algorithms are created, executed, and alidated!
. of 9
6ntroduction to Algorithmic )hinking
What is Algorithmic Thinking?
Algorithmic thinking is the ability to understand, execute, evaluate, and create
algorithms! ;et,s discuss each of these ideas separately!
)o be an algorithmic thinker you need the ability to understand and execute algorithms!
-ome people find it easy to follow a series of precise instructions while other people find
it ery challenging! -ome people seem to lack the patience and diligence re(uired to
follow a step-by-step plan! Howeer, it is a aluable skill that all people should master!
Algorithmic thinking re(uires patience because each instruction must be executed in its
correct se(uence without skipping ahead or *glossing oer* some of the instructions! 6n
addition, algorithmic thinking re(uires diligence and perseerance! 6t is often tedious to
follow the steps of a complex algorithm and people sometimes fail to complete an
algorithm because they simply *gie up!*
Algorithmic thinking also re(uires the ability to evaluate algorithms! )his inoles
determining if an algorithm really does sole a gien task! )his can be ery challenging!
\$or example, a *preflight check list* is an algorithm for preparing an aircraft for take off!
-uppose you were gien the 4ob of determining if a new *preflight check list* for the \$27
%<oint -trike \$ighter& is correct %checks all systems on the aircraft properly& and complete
%does not leae out any important checks&! Hopefully you would agree that this is an
important 4ob pilot,s lies are dependent on getting it right and that getting the check
list correct and complete will not be easy! %As a side note, one way to create the preflight
check list is to determine the fault of each new aircraft crash and add a new check to the
list to preent future crashes! 1ut the cost in lies and money is too great! We need to get
the algorithm correct and complete before the first plane takes to flight to preent a single
aircraft loss=&
And finally, Algorithmic thinking includes the ability to create new algorithms! )his is
probably the most challenging aspect of algorithmic thinking! >ien a task, can you
create a series of precise, step-by-step instructions that always soles the task correctly?
Obiously the complexity of the task has a big impact on the complexity of an algorithm
that will accomplish the task! -imple tasks can typically be accomplished with simple
algorithms, while complex tasks typically re(uire more complex algorithms!
A critical aspect of algorithm creation is the *target executer* of an algorithm! \$or
example, the *target executer* of a preflight check list is a pilot! )he aerage person on
the street could not execute the preflight check list correctly because they would not
understand the instructions! )he three, preiously stated, characteristics of an algorithm
instruction %i!e!, an instruction must be unambiguous, executable, and ordered& must be
consistent with the knowledge and expertise of the *target executer!* When you create an
algorithm, make sure that each instruction can be unambiguously interpreted and
executed by the *target executer!*
We lie in the *information age,* where many of the tasks people need %or want& to do
can be accomplished by computers! Howeer, computers currently hae no real
understanding or cognition they can only perform tasks that people hae deeloped
0 of 9
6ntroduction to Algorithmic )hinking
algorithms to sole! )herefore, to create algorithms that computers can execute, you must
understand what a computer is capable of executing and be able to write a series of
unambiguous instructions that a computer can execute successfully! \$or the remainder of
this document we will restrict our discussion to the deelopment of algorithms that can be
executed on computers!
How are algorithms communicated?
?ach step %instruction& of an algorithm must be precisely stated! 6t is ery difficult to
explain algorithms precisely using only the ?nglish language! \$or example, please re-
read the example algorithm for making *fro+en lemon ice-box pie* and then answer the
following (uestions'
@oes pet milk come in different si+e containers? How much milk is *. can*?
@oes it matter what types of beaters are used to beat the pet milk?
6s *tsp* a teaspoon or a table spoon?
6f you tried to implement the recipe to make fro+en lemon ice-box pie you might ery
well discoer other ambiguities in the instructions! )o eliminate these *communication
problems,* we need a precise language for specifying algorithms, especially since our
*target executioner* is a dumb computer! A precise language for stating the instructions
of an algorithm that can be executed by a computer is called a *programming language!*
Aany programming languages hae been deeloped oer the years and each language has
its own special features and benefits! #ou hae probably heard of some of these
languages, such as B, BCC, /ascal, 1A-6B, <aa, /erl, /ython, and Ada! 6t re(uires a
significant amount of time to learn a new programming language and it is not a goal of
B-..D to teach you how to program computers! We want cadets to become better
problem solers by becoming algorithmic thinkers! One of the common ways to express
algorithms without using a programming language is called flowcharting
.
! \$lowcharts
proide a isual description of a step-by-step process! )he ma4or drawback to using
flowcharts is that they are tedious to draw and hard to modify if they are hand drawn on
paper! A computer program called EA/)OE was deeloped by @r! Barlisle here at
F-A\$A which allows a person to create an algorithm in flowchart form and then actually
execute the flowchart to test its alidity! /retty cool= We will discuss the details of how
to use EA/)OE in future lessons!
Why are Algorithms Important?
Algorithms are important for many reasons'
An algorithm documents the *how to* for accomplishing a particular task!
6f an algorithm is written well, it can be used to accomplish not only a single task
but a whole group of related tasks!
)he existence of an algorithm means that the task can potentially be automated
%i!e!, performed by a computer&!
.
http'33en!wikipedia!org3wiki3\$lowchart
2 of 9
6ntroduction to Algorithmic )hinking
)he automation of redundant, tedious, or dangerous tasks frees people from
haing to perform these boring, time-consuming, or potentially lethal tasks!
)he automation of some tasks makes new things possible %e!g!, accessing web
pages from all oer the entire world in the blink of an eye&!
Bonsider telephones for example! When telephones were inented, the problem of how to
connect one phone caller to another caller arose! \$or many years this problem was soled
manually by phone operators who pulled wires from a console and plugged them into the
correct connecting wire! 6t has been estimated that if this manual method was still used
today to handle the current daily phone calls made around the world, eery person on the
planet would hae to be a phone operator= )hankfully, gien the inention of fast
computers and algorithms to instruct those computers, almost all phone calls made today
are automatically connected without human interention! What would your life be like
without a phone? Ban you imagine it? Without algorithms, that is the way life would be=
We study algorithms in B-..D because algorithmic thinking is transferable! 6f you can
think and reason precisely and sole algorithmic problems in one domain %e!g! computer
programming&, then your ability to analy+e and sole problems in other areas will
improe!
What are the important properties of algorithms?
)he following is a list of some of the important properties of algorithms! )his list is by no
means comprehensie or complete!
Property 1' \$or any gien, non-triial task %or set of related tasks&, there are many
possible algorithms for accomplishing the task!
)his greatly confuses many students! *#ou mean there is more than one correct answer?*
)he answer is #?-= Eemember, an algorithm is not the solution to a problem" it is a step-
by-step set of instructions for finding a solution! 6s there only one way to get from
Aitchell Hall to Arnold Hall?

Property 2' An algorithm does not encode the underlying theory behind the instruction
steps!
An algorithm tells you how to accomplish a task! 6f the algorithm is correct, and you
follow the instructions exactly, you will accomplish the task! 1ut you may not understand
why you did some of the steps! 6f a computer is executing an algorithm, this lack of
understanding is not a problem! 6f a person is trying to understand an algorithm so that it
can be updated or enhanced, this lack of understanding can make changes almost
impossible! Bomplex algorithms often hae associated documentation that proides
detailed explanations of how they work!
Property 3' -ome algorithms are more efficient than other algorithms!
5 of 9
6ntroduction to Algorithmic )hinking
)he execution of an algorithm re(uires some amount of time! 6f an algorithm is used
often, its efficiency becomes an issue! 6t is common to create multiple algorithms to
accomplish a particular task and then select the faster algorithm to include in a final
product! One of the challenges of software deelopment is deciding how much time and
effort you should expend on the search and deelopment of more efficient algorithms!
Property 4' Bomputer programs that are used oer many years typically must be
Bomputer programs are not typically static ob4ects! )hey re(uire *maintenance* to keep
them current with changes in task re(uirements! \$or example, a computer program that
calculates income taxes must change eery year as the income tax laws change! -ome
studies hae shown that up to :7G of software deelopment costs are consumed by the
maintenance of existing software!
6n conclusion, when we deelop new algorithms, we attempt to create one of many
possible se(uences of instructions that will sole our task at hand! 6deally we would like
the algorithm to execute (uickly and be well *commented* so that it can easily be
maintained oer time!
An Example How to create an algorithm
)his section will walk you through the process of creating an algorithm for a simple
problem! Hopefully you will use the principles discussed here when it comes time for you
-ample /roblem' )wo people work for the same company and hae a total combined
salary of W dollars, but one person earns H dollars more than the other
person! How much did they each earn?
Principle 1: -ole a specific instance of the problem by hand using pencil and paper!
A specific instance of a problem is when all the *ariables* are gien a specific alue!
-uppose we let W be I7:!DD and let H be I7!DD! Jow the problem reads'
Specific
Problem
Instance'
)wo people work for the same company and hae a total combined salary
of I7:!DD, but one person earns I7!DD dollars more than the other person!
How much did they each earn?
Arithmetic Reasoning: Algebraic reasoning:
Of the I7:, /erson. gets I7 more then
/erson0!
)herefore, both e(ually share I7:-I7 K
I70!
I70 3 0 is I09, so each gets at least I09!
;et L K /erson.,s pay
;et # K /erson0,s pay!
)herefore, we know from the problem that'
L K # C 7 and
L C # K 7:!
-ole these 0 e(uations using substitution'
7 of 9
6ntroduction to Algorithmic )hinking
/erson. gets I2. %I09 C I7&
/erson0 gets I09
% # C 7& C # K 7:
# K 09
)herefore L K # C 7 K 2.
/lease note' 6f you cannot sole this problem manually, it is impossible for you to write
an algorithm to sole the problem=
Principle 2: >enerali+e your solution by replacing your specific instance alues with
*ariables*!
)he two preiously shown solutions now become'
Arithmetic Reasoning: Algebraic reasoning:
Of the total salary W, /erson. gets H
dollars more then /erson0!
)herefore they both e(ually share %W - H&!
?ach gets at least %W H& 3 0!
/erson. gets %W H& 3 0 C H
/erson0 gets %W H& 3 0
;et L K /erson.,s pay
;et # K /erson0,s pay!
)herefore, we know from the problem that'
L K # C H and
L C # K W!
-ole these 0 e(uations using substitution'
% # C H& C # K W
# K %W H&30
)hereforeL K %W H&30 C H
Principle 3: Aanually execute your algorithm on seeral test cases to erify that it
produces correct answers! )his is called desk checking or walking through
the algorithm!
!
?xample .' W K .DD, H K .D
/erson. K %.DD .D&30 C .D K 77
/erson0 K %.DD .D&30 K 57
%)his is correct because 77 C 57 K .DD and /erson. earns .D more dollars
than /erson0&
?xample 0' W K 2., H K 0
/erson. K %2. 0&30 C 0 K .9!7
/erson0 K %2. 0&30 K .5!7
%)his is correct because .9!7 C .5!7 K 2. and /erson. earns 0 more dollars
than /erson0&
Principle 4: After a general solution to the task is known, write correct programming
statements to implement your solution on the computer!
How to write correct programming statements will be coered in the next few lessons!
9 of 9