Introduction to Problem Solving
Chapter 4
INTRODUCTION
TO PROBLEM SOLVLING
Problem
solving, in the context of developing programs, refers to analyzing a problem
with the intention of deriving a solution for the problem
Problem
Solving Cycle:
The
problem-solving cycle is a structured, iterative, 4-step process used to:
1. identify and
analyze the problem,
2. Find its solution and Develop
algorithm of the solution
3. Code the solution in a programming
language.
4. Test and Debut the coded solution.
And finally implement and maintain it.
Problem
Solving Using Decomposition
Decomposing
is a process of breaking down a big or complex problem into a set of smaller
sub-processes to allow us to describe, understand, or execute the problem
better. Decomposition involves:
- · Dividing
a task into a sequence of subtasks.
- · Identifying
elements or parts of a complex system.
Need
for Decomposition
Decomposition
is the process of breaking a complex problem into smaller, more manageable
sub-problems, which is essential in programming because large tasks are often
too intricate for a computer to process or a human to organize all at once. By
dividing a project into independent modules or functions, developers can reduce
the overall cognitive load, making the logic easier to understand, design, and
implement.
Designing
Algorithm:
Designing an
algorithm is the process of creating a step-by-step procedure or a
"recipe" to solve a specific computational problem efficiently. A
well-designed algorithm must be clear and unambiguous, meaning every
instruction has only one interpretation, and it must eventually terminate after
a finite number of steps.
Characteristics
of a Good Algorithm
·
Precision-
Its steps should be precisely defined
·
Uniqueness-
each step should uniquely contribute to the algorithms
·
Finiteness
–An algorithms should be finite.
·
Input –
An algorithms requires a specific type of input to work upon.
·
Output
– An algorithms produces output as per the stated objectives.
Components
of an Algorithm
Input: Input is the initial data or information provided to the
algorithm before it begins execution.
Processing: This component involves the specific operations, calculations,
and logic applied to the input data to transform it. It bridges the gap between
the initial input and the final result through step-by-step instructions.
Output: Output is the final result or information produced by the
algorithm after processing is complete.
Verifying
Algorithm
Verification
of an algorithm means to ensure that the algorithm is working as intended. It can be verified with sample input for
which we know the output.
Dry
Run
A dry run is
the process of a programmer manually working through their code to trace the
values of variable. If the programmer found that the value is not what it
should be, they are able to identify the section of code that resulted in the
error.
Characteristics
of Dry Run
• It is carried out during design,
implementation testing or maintenance.
• It is used to identify the logic errors in
a code.
• It cannot find the execution errors in a
code.
Flowchart:
Flowcharts are graphical representations of data, algorithms, or
processes, providing a visual approach to understanding code. They illustrate
step-by-step solutions to problems, making them useful for beginner
programmers. Flowchart consists of sequentially arranged boxes that depict the
process flow.
Symbols Used in
Flowchart:
Advantages & Disadvantages of Flow Chart
ADVANTAGES
·
It helps in analyzing the problems effectively.
·
It acts as a guide during the program development phase.
·
It help easy debugging of logical errors
DISADVANTAGES
·
A
lengthy flowchart may extend over multiple pages, which reduces readability.
·
Drawing
a flowchart is time consuming.
·
The
changes made to a single step may cause redrawing the entire flowchart
Pseudocode
Pseudocode
is a simplified, informal representation of a computer program's logic written
in plain, natural language (like English). It is not an actual programming
language and cannot be executed by a computer; instead, it serves as a
"blueprint" or "rough draft" to help programmers plan an
algorithm before writing real code.
Example – to
input 2 number and display the sum
1.
START
2.
INPUT
A, B
3.
TOTAL
= A + B
4.
PRINT
TOTAL
5.
END
Disadvantage of Pseudocode:
·
It
is not a visual tool like flowcharts.
·
Since
there is no accepted standard for pseudocode, so it varies from programmer to
programmer.
·
It
can only be tested on paper, there is no program available to test it.
·
It
is an information representation of an algorithm.
- Verification of an algorithm means to ensure that
the algorithm is working as intended.
It can be verified with sample input for which we know the output.
Comments
Post a Comment