ITA 120 Introduction To Programming: Algorithms
ITA 120 Introduction To Programming: Algorithms
Introduction to Programming
Algorithms
Algorithm
Definitions
A precise specification of a behaviour
intended to solve a well-defined problem
A finite set of well-defined instructions for
accomplishing some task
An ordered set of unambiguous, executable
steps that defines a terminating process.
Properties of algorithms
An algorithm must:
Have a well established structure.
Consist of executable steps. To make a list of all
positive integers is not executable, as the list is infinite.
Be unambiguous. The actions required by each step
should be unique and complete.
Be correct. If the input conditions are satisfied and the
steps of the algorithm executed then the desired
outcome should be produced.
Lead to an end. The algorithm should terminate after a
finite number of steps.
Related Terms
Process
Routine
Technique
Procedure
Pattern
Recipe
Example - Narrative
Obtain a basket of unshelled peas and an
empty bowl.
As long as there are unshelled peas in the
basket, continue to execute the following
steps.
Take a pea from the basket
Break open the pea pod
Dump the peas from the pod into the bowl
Discard the pod
Example - Narrative
An algorithm for buying a ticket for a
movie
Go to the theatre
Walk to the ticket counter
Select a movie
Pay the price
Receive the ticket
Example - Flowchart
http://www.scpcp.org/dnn/Portals/0/process-improvement/glossary/basic-flowchart.gif
Example - Pseudocode
CalculateAverageMark
Start
1. Prompt for FirstMark
2. Get FirstMark
3. Prompt for SecondMark
4. Get SecondMark
5. Average = (FirstMark + SecondMark) / 2
6. Print Average
Stop
Exercises
Write narratives for the following: