Part 6, Algorithms Flashcards
finish the sentence
a well written algorithm can be
implemented into many different programming languages
give a definition that would describe an algorithm for a program
a set of unambiguous, self contained, step-by-step instructions. Guaranteed to complete a particular task in a finite amount of time.
what is this sentence a definition of
a set of unambiguous, self contained, step-by-step instructions. Guaranteed to complete a particular task in a finite amount of time.
this is the definition of an algorithm for a program
what is meant by unambiguous in the definition for a programs algorithm
a set of unambiguous, self contained, step-by-step instructions. Guaranteed to complete a particular task in a finite amount of time.
the term unambiguous means that no part of the algorithm is open to interpretation
the algorithm is therefore written clearly and precise for the benefit of the computer and anyone wanting to reuse the algorithm
what is meant by self contained in the definition for a programs algorithm
a set of unambiguous, self contained, step-by-step instructions. Guaranteed to complete a particular task in a finite amount of time.
the term self contained means that the algorithm contains all information it needs
therefore when using the algorithm it will require no external sources of information or extra work put into it
what is meant by step-by-step instructions in the definition for a programs algorithm
a set of unambiguous, self contained, step-by-step instructions. Guaranteed to complete a particular task in a finite amount of time.
step-by-step instructions means that the algorithm is written in steps which eventually lead to the desired outcome
this is much like the steps written in a recipe
an algorithm needs refinement/decomposition
what does this mean
this means the algorithm is open to more than one interpretation
it should be refined or decomposed until all ambiguities have been resolved
an algorithm is open to more than one interpretation what two terms describe the process it must go through to rid it of the open interpretation
refinement
decomposition
what method might you use to refine an algorithm that is open to more than one interpretation
break the step down into several smaller clearer steps
how can you tell when an algorithm is refined fully
the algorithm will be clear and precise to the author and any audience that uses it
what four fundamental features do all algorithms share
- inputs and outputs
- sequence of instructions
- repetition of instructions
- selection of instructions
what shares these four features
- inputs and outputs
- sequence of instructions
- repetition of instructions
- selection of instructions
algorithms
an algorithm will follow a sequence of instructions unless
1.
2.
- there is repetition in which case the algorithm repeats a set of instructions until the loop is broken
- there is selection. in which case the sequence of instructions will branch to different sequence of instructions and outcomes
name four input sources an algorithm might get its data from
- the user
- a constant unchangeable value written in the algorithm
- data from the current environment (current time, current mouse position)
- lists
what is a case instruction or a switch statement
this can be used in contrast to selection.
instead an input variable is assessed then if the variable exists as a case or switch then it has its block of code ran
switch (variable or an integer expression) { case constant: //C Statements ; case constant: //C Statements ; default: //C Statements ; }
this can be used in contrast to selection.
instead an input variable is assessed then if the variable exists as a case or switch then it has its block of code ran
switch (variable or an integer expression) { case constant: //C Statements ; case constant: //C Statements ; default: //C Statements ; }
case instruction/switch statement