Professional Documents
Culture Documents
Lecture Outline
General problem solving
Problem solving process
Problem Solving
Problem Solving
It is not about whether you can solve the
problem, but...
Whether you can provide an algorithm (or
recipe) for E to solve the problem.
The algorithm is exact, effective, general
and must terminate.
The algorithm is constrained by:
the language that E understands;
the abstract mechanism behind how E
works.
CS1010E Lecture 12 p.4/21
Language
What are the primitive values?
int, double, char
Abstract Mechanism
Assignment
Expression evaluation: arithmetic, relational,
boolean
Type conversions
Function call/activation/termination
Control flow (flow chart)
if..else, switch..case
while, do..while, for
Pointers, arrays/strings and structures
Recursive calls and activations
CS1010E Lecture 12 p.6/21
Modeling
Within the set of possible programs
constructed using the rudimentary constructs,
devise an abstract model that is complete,
consistent and correct.
Completeness
All possible constructs can be modeled
precisely;
Consistency
The same construct is modeled in the
same way everytime;
Correctness
Gives a correct representation of the
internal workings of the true mechanism.
Maze Example
Maze Example
Maze Example
Problem formulation from abstract description
to algorithm.
Algorithmic problem solving with control flow.
Sequence
Selection
Repetition
What is the input/output? How are they
represented?
How to represent movement using the
left-hand rule?
CS1010E Lecture 12 p.10/21
Problem Formulation
Get starting and ending positions;
while (destination is not reached)
{
if (you can turn left)
turn left;
else
if (you can go forward)
stay put;
else
if (you can turn right)
turn right;
else
turn back;
Move one step forward;
}
CS1010E Lecture 12 p.11/21