Writing algorithms
To solve a problem we must write a algorithm which will take a input and provide the required output.
The input and output must be reliable. We will ignore validation and assume that the input is always within range. There are some exceptions to this for example removing from a stack when it is empty WOULD be covered in the algorithm but adding a node which has no data (presence check) would not. As a beginner this may seems strange but all we are trying to do is to focus on the main points of the algorithm rather than worry about un-related details.
In order to solve a algorithm we must decide on the following -
- What information needs to be saved?
- Are there anything which needs repeating?
- Are there any decisions which need to be made?