The document provides an introduction to problem solving and programming fundamentals. It defines a computer program as a set of instructions that directs a computer to solve a problem. The document outlines a four-step problem solving process of understanding the problem, devising a plan, carrying out the plan, and looking back. It also discusses analyzing a problem by identifying inputs, outputs, processing, and storage. The design phase involves developing an algorithm to solve the problem. Debugging addresses fixing syntax, runtime, and semantic errors in a program.
2. WHAT IS A PROGRAM ?
A computer program is a set of computer instructions, which are
used for solving a problem. The program directs the computer to
perform the actions that are needed to arrive at a solution.
The number of instructions required to solve a problem depends on
the complexity of the problem. These instructions may range from
a few to many hundreds or thousands.
The computation might be something mathematical, such as
solving a system of equations or finding the roots of a polynomial.
But it can also be a symbolic computation, such as searching and
replacing text in a document or (strangely enough) compiling a
program.
3. PROGRAMMING: A WAY OF THINKING
Combines features from mathematics, engineering, and
natural science.
Like mathematicians, computer scientists use formal
languages to denote ideas (specifically computations).
Like engineers, they design things, assembling components
into systems and evaluating tradeoffs among alternatives.
Like scientists, they observe the behavior of complex systems,
form hypotheses, and test predictions.
4. PROGRAMMING: A WAY OF THINKING
• The single most important skill for a computer scientist is
problem solving.
• Problem solving means:
• The ability to formulate problems, think creatively about solutions, and
express a solution clearly and accurately.
5. PROBLEMS? . . .
• The problem is not that there are problems. The problem is expecting
otherwise and thinking that having problems is a problem.“ Theodore Rubin
• The best way to escape from a problem is to solve it.--Brendan Francis
• Every problem contains within itself the seeds of its own solution.--Stanley
Arnold
• It isn't that they can't see the solution. It's that they can't see the problem.--
G. K. Chesterton
• Problems are to the mind what exercise is to the muscles, they toughen and
make strong. - Norman Vincent Peale
6. WHAT IS A PROBLEM (IN COMPUTING)
A discrepancy between what is required and what exists.
A computer program is meant to solve a problem.
Think of a programming problem in the same light as you
would think of a mathematical problem. It's not something
bad(though some people may say otherwise).
Rather, it is something that needs to be solved or a task that
needs to be accomplished.
7. WHAT IS PROBLEM SOLVING?
• Problem solving has long been recognized as one of the
hallmarks of mathematics.
• “Solving a problem means finding a way out of difficulty, a
way around an obstacle, attaining an aim which was not
immediately attainable.”
9. STEP-1: UNDERSTANDING THE PROBLEM
• Can you state the problem in your own words?
• What are you trying to find or do?
• What are the unknowns?
• What information do you obtain from the problem?
• What information, if any, is missing or not needed?
10. STEP-2: DEVISING A PLAN
(SOME STRATEGIES YOU MAY FIND USEFUL)
• Look for a pattern.
• Examine related problems and determine if the same technique can
be used.
• Examine a simpler problem to gain insight into the solution of the
original problem.
• Make a table or list.
• Make a diagram.
• Write an equation.
• Use guess and check.
• Work backward.
• Identify a subgoal.
• Use indirect reasoning.
• Use direct reasoning.
11. STEP-3: CARRYING OUT THE PLAN
• Implement the strategy or strategies.
• Check each step of the plan as you proceed.
• Keep an accurate record of your work.
• Implement the strategy of strategies in step 2 and perform
any necessary actions or computations.
• Check each step of the plan as you proceed. This may be
intuitive checking or a formal proof of each step.
• Keep an accurate record of your work. Label each step.
12. STEP-4: LOOKING BACK
CHECK THE RESULTS IN THE ORIGINAL PROBLEM
• Interpret the solution in terms of the original problem.
• Determine whether there is another method of finding the
solution.
• If possible, determine other related or more general problems
for which the techniques will work.
13. DEVELOPMENT OF COMPUTER SOLUTION
• Identify or Define the problem
• Analyze the problem in terms of inputs, outputs, formulas,
constants)
• Design the Solution
• Represent the most efficient solution in the form of an
algorithm.
• Implement (program coding)
• Evaluate
14. IDENTIFY OR DEFINE THE PROBLEM
In order for you to come up with an algorithm to solve a
problem, you must first have a clear understanding of what
the problem is.
The first thing you have to do is to obtain a problem
statement (a clear definition of the problem that needs to be
solved).
At this level it will usually be provided for you, but in the real
world the programmer would have to work with his client to
come up with one.
Here are some (very simple) examples of problem statements:
15. ANALYZE THE PROBLEM
We need to read it till we understand every detail
We need to dissect the problem into its component parts (e.g.
problems and sub-problems)
We need to remove any ambiguity, extra information
We need to determine our knowns and our unknowns
We need to be aware of any assumptions we are making.
16. ANALYZE THE PROBLEM
The Program Must Read Two Numbers And Print The Total Of
The Two.
Determining the input, output, processing and storage
The next step in defining the problem is to break it down into
its main components:
1. Inputs - the data you are provided with or have to obtain from the
user. Some words that help you to identify the inputs are: read, input,
enter, given, accept
2. Outputs - the results that should be produced
3. Processing - the tasks that must be performed, i.e. what must be
done with the inputs to get the outputs
4. Storage - the data that must be stored
17. ANALYZE THE PROBLEM
The Program Must Read Two Numbers And Print The Total Of
The Two.
• Inputs - The word 'read' tells us that the inputs will be in the form of two
numbers. For reasons that will be explained later, it's helpful to give the
inputs names, so we'll call them numl and num2.
• Outputs - The desired result is the total, so we'll call the output 'total’.
• Processing - Reading the two numbers is processing and so is printing the
total. But is that everything? The total doesn't magically appear. You have
to do something to the inputs to obtain the total. So there is an in-
between step that is implied - calculating the total.
• Storage - the data that must be stored
18. ANALYZE THE PROBLEM
The Program Must Read Two Numbers And Print The Total Of
The Two.
• Defining diagrams
• One way of illustrating the main components of a problem is by using
a defining diagram.
• A defining diagram is a table with three columns: 'Input', 'Processing'
and 'Output'.
• Consider the following problem statement:
Write a program that reads two numbers and prints the total.
• Even this simple statement requires some detective work to figure out
the input, output and especially the processing.
• the defining diagram would look like this:
Input Processing Output
Two Numbers, i.e.
numl, num2
Read two numbers
Total
Calculate the total
Print the total
19. DESIGN THE SOLUTION
Developing the algorithm that solves the
problem
Identify alternative ways to solve the problem
Select the best way to solve the problem from the list
of alternative solutions
List instructions that enable you to solve the problem
using selected solution
The algorithm is expressed a s flowchart or
pseudo-code
22. PROGRAM COMPONENTS
A few basic instructions appear in every language:
Input - Get data from the keyboard, a file, or some other device.
Output - Display data on the screen or send data to a file or other
device.
Math Perform basic mathematical operations like addition and
multiplication.
Conditional execution - Check for certain conditions and execute
the appropriate sequence of statements.
Repetition/Looping - Perform some action repeatedly, usually with
some variation.
23. WHAT IS DEBUGGING?
Programming errors are called bugs and the process of tracking them down and
correcting them is called debugging.
Three kinds of errors can occur in a program:
1. Syntax errors
A program can only be executed if it is syntactically correct; otherwise, the process fails and returns an
error message.
syntax refers to the structure of a program and the rules about that structure.
2. Runtime errors
So called because the error does not appear until you run the program.
These errors are also called exceptions because they usually indicate that something exceptional (and
bad) has happened.
3. Semantic errors
If there is a semantic error in the program, it will run successfully, in the sense that the computer will
not generate any error messages, but it will not do the right thing. It will do something else.
Specifically, it will do what the programmer told it to do.
But the written program does not solve the original problem. The meaning of the program (its
semantics) is wrong.