Algorithms and Pseudocode (Problem solution steps (1. Problem definition…
Algorithms and Pseudocode
A problem is specified by
Problem solution steps
1. Problem definition
Clear understanding of the problem is required before formulating a solution.
2. Problem analysis
Develop mathematical formulation, define inputs, outputs and their relationships, state any assumptions.
Formulate a series of step by step instructions for solving the problem (pseudocode or flow charts)
Conversion of the algorithm into the desired programming language.
5. Testing and verification
Does the program perform its intended function, debugging, verification.
Internal and external documentation.
7.Maintenance and modification
Correcting errors and enhancing features.
What is an algorithm
Algorithm is a step by step procedure for solving a problem in a finite amount of time.
: An algorithm has input values from a specified set.
From each set of input values an algorithm produces output values from a specified set. The output values are the solution to the problem.
: The steps of an algorithm must be defined precisely.
An algorithm should always produce the correct output values for each set of input values.
always gives a solution when one exists.
Properties of algorithm
An algorithm should produce the desired output after a finite number of steps for any input in the set.
It must be possible each step of an algorithm exactly and in finite amount of time.
The procedure should be applicable for all problems of the desired form, not just for a particular set of input values.
runs in polynomial time.
Method of designing algorithms
Breaking large problems into smaller, manageable ones.
Involves two techniques:
1.Define the problem statement in general.
2.Decompose the original problem into sub problems.
Refine each of the general steps in greater detail- this is iterative step with each one adding more detail.
Advantages of Top-Down
Produces well designed modular programs.
Helps reduce complexity since decisions are posponed until appropriate level in the development.
Algorithms are usually presented using
- is an English like presentation of algorithms.
Is a balance between clarity and detail.
Abstracts the algorithm
Makes good use of mathematical notation.
Is easy to read and write.
Gives too many details.
Is too implementation specific.
Used to write the algorithm once the data structure is fully understood.
Instruction is written on a separate line from top to bottom with one entry and one exit.