0% found this document useful (0 votes)
3 views73 pages

Problem Solving Techniques and Tools

Uploaded by

spartansheik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views73 pages

Problem Solving Techniques and Tools

Uploaded by

spartansheik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 1

Problem Solving

Presenter Name
01 Problem Solving 04 Flowchart

Syllabus 02 Problem Analysis Chart 05 Pseudocode

03 Developing an Algorithm
INTRODUCTION TO PROBLEM SOLVING
• Computers are seen everywhere around us, in all spheres of life, in the field of
education, research, travel and tourism, weather forecasting, social networking,
e-commerce etc.
• Computers have now become an indispensable part of our lives. We use them
for doing various tasks in a faster and more accurate manner.
• A computer can perform a wide range of tasks, but it cannot operate on its own.
A computer needs to be instructed to perform a task.
• Precise step-by-step instructions should be given by us to solve the problem.
• In order to instruct a computer correctly, the user must have clear understanding
of the problem to be solved.
INTRODUCTION TO PROBLEM SOLVING
• Once the problem is well-defined and a method of solving it is developed, then
instructing the computer to solve the problem becomes relatively easier task.
• Thus, the success of a computer in solving a problem depends on how correctly
and precisely we define the problem, design a solution (algorithm) and
implement the solution (program) using a programming language. Thus, problem
solving is the process of identifying a problem, developing an algorithm for the
identified problem and finally implementing the algorithm to develop a computer
program.
STEPS FOR PROBLEM SOLVING

• Suppose your mobile phone suddenly stops connecting to the internet. You
might not know the exact reason immediately. First, you check if the Wi-Fi or
mobile data is turned on.
• If that does not solve the issue, you might restart the phone or try reconnecting
to the network. If the problem persists, you take the phone to a technician.
• The technician will examine the device, identify the root cause - whether it is a
software issue or a hardware fault - plan the required steps, and then fix the
problem.
• This example clearly shows that solving a problem often involves several logical
and ordered steps.
• When problems are straightforward and easy, we can easily find the solution. But
a complex problem requires a methodical approach to find the right solution.
• In other words, we have to apply problem solving techniques.
• Problem solving begins with the precise identification of the problem and ends
with a complete working solution in terms of a program or software.
Key steps required for solving a problem using a computer are,

 Analysing the problem


 Developing an Algorithm
 Coding
 Testing and Debugging
Analysing the problem

• It is important to clearly understand a problem before we begin to find the


solution for it.
• If we are not clear as to what is to be solved, we may end up developing a
program which may not solve our purpose.
• Thus, we need to read and analyse the problem statement carefully in order to
list the principal components of the problem and decide the core functionalities
that our solution should have.
• By analysing a problem, we would be able to figure out what are the inputs that
our program should accept and the outputs that it should produce.
Developing an Algorithm

• It is essential to device a solution before writing a program code for a given


problem.
• The solution is represented in natural language and is called an algorithm. We
can imagine an algorithm like a very well-written recipe for a dish, with clearly
defined steps that, if followed, one will end up preparing the dish.
• We start with a tentative solution plan and keep on refining the algorithm until
the algorithm is able to capture all the aspects of the desired solution.
• For a given problem, more than one algorithm is possible and we have to select
the most suitable solution.
Coding

• After finalising the algorithm, we need to convert the algorithm into the format
which can be understood by the computer to generate the desired solution.
• Different high level programming languages can be used for writing a program.
It is equally important to record the details of the coding procedures followed
and document the solution.
• This is helpful when revisiting the programs at a later stage.
Testing and Debugging

• The program created should be tested on various parameters. The program


should meet the requirements of the user.
• It must respond within the expected time. It should generate correct output for all
possible inputs.
• In the presence of syntactical errors, no output will be obtained. In case the
output generated is incorrect, then the program should be checked for logical
errors, if any.
• Software industry follows standardised testing methods like unit or component
testing, integration testing, system testing, and acceptance testing while
developing complex applications.
• This is to ensure that the software meets all the business and technical
requirements and works as expected.
• The errors or defects found in the testing phases are debugged or rectified and
the program is again tested. This continues till all the errors are removed from
the program.
• Once the software application has been developed, tested and delivered to the
user, still problems in terms of functioning can come up and need to be resolved
from time to time.
• The maintenance of the solution, thus, involves fixing the problems faced by the
user, answering the queries of the user and even serving the request for
addition or modification of features.
PROBLEM ANALYSIS CHART

• A Problem Analysis Chart (PAC) is a structured tool used to break down a problem
into key components.
• It helps to systematically understand the problem, identify necessary data, and
develop a structured approach to solve it.
• In the context of algorithms and flowcharts, PACs serve as the initial step in
problem solving by organizing information that will be used to visualize and
implement the solution.
To easily analyze the problem, a Problem Analysis Chart (PAC) was introduced.
This chart have four sections. They are,
The given data
• The required result
• The processing involved
• A list of solution alternative
• The Problem Analysis Chart breaks the problem into smaller parts. It helps us to
bring a logical sequence to our thought process and help us arrive at better
solutions.
Example Problem: A program is required to find average of five
numbers.
Advantages of a Problem Analysis Chart

Problem Analysis Chart has numerous advantages, particularly in the context of


designing and developing computer programs. The key benefits include,
Enhanced Problem Comprehension: It facilitates a systematic breakdown of the
problem into key components such as inputs, outputs, processing steps, and
potential solution strategies, thereby promoting a deeper understanding of the
problem.
Early Identification of Requirements: The chart clearly outlines the data required
(inputs) and the expected results (outputs), ensuring that all necessary elements
are identified before the implementation phase begins.
Structured Planning and Organization: It aids in organizing the problem-solving
process in a logical and structured manner, serving as a blueprint for the actual
program development.
Development of Analytical Thinking: By encouraging a step-by-step approach to
problem-solving, the chart supports the development of critical and analytical
thinking skills, which are essential in programming.
Reduction of Programming Errors: A well-constructed problem analysis chart
minimizes the risk of logical errors and omissions by clarifying the entire process
prior to coding.
Simplified Testing and Debugging: It provides a reference point that can be used
to trace and verify the correctness of the program during testing and debugging
stages.
Support for Teaching and Documentation: The chart is a valuable pedagogical
tool, making it easier for educators to explain programming concepts. It also
enhances the quality of project documentation by clearly presenting the problem-
solving approach.
Exploration of Multiple Solution Approaches: By including alternative methods
for solving the problem, the chart encourages creativity and flexibility in program
design.
Relationship Between PACs, Algorithms, and Flowcharts

PACs, algorithms, and flowcharts are interconnected in problem-solving,


• PACs provide a structured approach to analyse the problem by identifying
inputs, outputs, processes, and alternative solutions.
• Flowcharts visually represent the steps and decision points outlined in the PAC,
making it easier to understand and communicate the solution process.
• Algorithms are step-by-step procedures derived from the PAC and visualized
through flowcharts. They provide a logical sequence of operations to solve the
problem.
• By integrating PACs, algorithms, and flowcharts, we can systematically analyse
problems, visualise the solution process, and implement efficient solutions.
• This structured approach enhances our problem-solving skills and ensures that
solutions are well-organized, efficient, and easy to understand.
• The interactive activity demonstrates how a simple algorithm can be visualised
and implemented, reinforcing the concepts of PACs and flowcharts in a practical
context.
ALGORITHMS

• An algorithm is an ordered sequence of well-defined, finite, and unambiguous sequence of


instructions designed to complete a specific task.
• It is a step by step procedure for solving any problem.
• An algorithm is an English-like representation of the logical procedure used to address the
problem.
• For a particular task, multiple algorithms may exist, they differ by their time complexity and
space requirements.
• The programmer chooses the most appropriate algorithm based on the efficiency and
suitability for the task at hand.
• An algorithm can be implemented using various programming languages and methods,
depending on the application's requirements.
• An algorithm is independent of any specific programming language.
Why Do We Need an Algorithm?

• A programmer writes a program to instruct the computer to do certain tasks as


desired.
• The computer then follows the steps written in the program code. Therefore, the
programmer first prepares a roadmap of the program to be written, before
actually writing the code.
• Without a roadmap, the programmer may not be able to clearly visualise the
instructions to be written and may end up developing a program which may not
work as expected.
• Such a roadmap is nothing but the algorithm which is the building block of a
computer program.
• Writing an algorithm is mostly considered as a first step to programming. Once
we have an algorithm to solve a problem, we can write the computer program for
giving instructions to the computer in high level language.
• If the algorithm is correct, computer will run the program correctly, every time.
• So, the purpose of using an algorithm is to increase the reliability, accuracy and
efficiency of obtaining solutions.
Developing an algorithm

• It is essential to device a solution before writing a program code for a given


problem.
• The solution is represented in natural language and is called an algorithm. We
can imagine an algorithm like a very well-written recipe for a dish, with clearly
defined steps that, if followed, one will end up preparing the dish.
• We start with a tentative solution plan and keep on refining the algorithm until
the algorithm is able to capture all the aspects of the desired solution.
• For a given problem, more than one algorithm is possible and we have to select
the most suitable solution.
Guidelines for Writing Algorithms

There are some guidelines to keep in mind for writing algorithms. They are,

• An algorithm should be clear, precise and well defined.


• It should always begin with the word ‘Start’ and end with the word ‘Stop’.
• Each step should be written in a separate line.
• Steps should be numbered as Step 1, Step 2, and so on.
Example: Algorithms to find the greatest among
three numbers
Algorithm 1
Step 1:Start.
Step 2:Read the three numbers A, B, C.
Step 3:Compare A and B. If A is the greatest perform step 4 else perform step 5.
Step 4:Compare A and C. If A is the greatest, output “A is the greatest” else output
“C is the greatest”.
Step 5:Compare B and C. If B is the greatest, output “B is the greatest” else output
“C is the greatest”.
Step 6:Stop.
Algorithm 2
Step 1:Start.
Step 2:Read the three numbers A, B, C.
Step 3:Compare A and B. If A is the greatest, store A in MAX, else store B in MAX.
Step 4:Compare MAX and C. If MAX is the greatest, output “MAX is the greatest”
else output “C is the greatest”.
Step 5:Stop.
Properties of an Algorithm
Finiteness: An algorithm must be terminated after a finite number of steps.
Definiteness: Each step of an algorithm must be precisely defined.
Input: The data must be present before any operations can be performed on it.
The initial data is supplied by a READ instruction. A variable can be given initial
value using the SET instruction.
Example: READ A, B
SET N=0
Output: After executing all the steps of the algorithm at least one output must be
obtained. The WRITE statement is used to print messages and variables.
Effectiveness: The operations to be performed in the algorithm can be carried out
manually in finite intervals of time.
Advantages of an Algorithm

• It is a simple to understand step by step solution of the problem.


• It is easy to debug.
• It is independent of programming languages.
• It is compatible to computers, because each step of an algorithm can be easily
coded into its equivalent high-level language.
Building Blocks of an Algorithms
The algorithms can be constructed from basic building blocks. The building blocks
are,
• Statements
• State
• Control flow and
• Functions
Statements / Instructions
• An algorithm is a sequence of instructions to accomplish a task or solve a problem.

• An instruction describes an action. When the instructions are executed, a process evolves which
accomplishes the intended task or solves the given problem.
• The algorithm consists of finite number of statements. It must be in an ordered form.
• The time taken to execute all the statements of the algorithm should be finite and within a reasonable limit.
State
• Computational processes in the real-world have state. As a process evolves, the
state changes.
• In an algorithm the state of a process can be represented by a set of variables.
The state at any point of execution is simply the values of the variables at that
point.
• As the values of the variables are changed, the state changes.
• State is a basic and important abstraction. An algorithm starts from the initial
state with some input values. As actions are performed, its state changes. It
ends with a final state.
• During computational process the state is stored in one or more the data
structures.
Control Flow
An algorithm is a sequence of statements. However, after executing a statement,
the next statement to be executed need not be the next statement in the algorithm.
The statement to be executed next may depend on the state of the process. Thus,
the order in which the statements are executed may differ from the order in which
they are written in the algorithm.
This order of execution of statements is known as the control flow.
There are three important control flow statements to alter the control flow
depending on the state. They are,
• Sequence Control Flow
• Selection Control Flow
• Iteration (Looping) Control Flow
These control flows allow the program to make choices, change direction or
repeat actions.
i) Sequence Control Flow
In sequential control flow, a sequence of statements is executed one after another
in the same order as they are written. The instructions in sequence control flow are
executed exactly once.
Example: Algorithm to find the sum of two numbers.
Step 1: Start
Step 2: Read two numbers A and B
Step 3: Calculate sum = A + B
Step 4: Print the sum value
Step 5: Stop.
This algorithm performs the steps in a purely sequential order.
ii) Selection Control Flow
In selection control flow, a condition of the state is tested, and if the condition is true, one statement
is executed; if the condition is false, an alternative statement is executed.
Example: Algorithm to find the greatest among three numbers.
Step 1: Start.
Step 2: Read the three numbers A, B, C.
Step 3: Compare A and B. If A is the greatest perform step 4 else perform step 5.
Step 4: Compare A and C. If A is the greatest, print “A is the greatest” else print “C is the greatest”.
Step 5: Compare B and C. If B is the greatest, print “B is the greatest” else print “C is the greatest”.
Step 6: Stop.
iii ) Iteration (Looping) Control Flow
In iteration control flow a set of statements are repetitively executed based upon a
condition. If a condition evaluates to true, the set of statements (true block) is
executed again and again. As soon as the condition becomes false, the repetition
stops. This is also known as looping statement or iteration statement.
Example: Algorithm to find the sum of first 100 integers.
1. Start
2. Assign sum = 0, i = 0.
3. Calculate i = i + 1 and sum = sum + i
4. Check whether i>= 100, if no repeat step 3. Otherwise go to next step.
5. Print the value of sum
6. Stop
Functions
In some cases, algorithms can become very complex. The variables of an algorithm and
dependencies among the variables may be too many. Then, it is difficult to build algorithms
correctly.
In such situations, we break an algorithm into parts, construct each part separately, and then
integrate the parts to the complete algorithm.
Any complex problem will become simpler if the problem is broken smaller and the smaller
problems are solved.
A function is a block of organized, reusable code that is used to perform a similar task of some kind.
Functions avoid the repetition of some codes over and over. It helps easy debugging, testing and
understanding of the program.
Functions reduce program size and the program development time.
Functions provide better modularity and high degree of reusability for the problems.
FLOWCHART

A flowchart is a diagrammatic representation of the logic for solving a task.


A flowchart is drawn using boxes of different shapes with lines connecting them to show the flow of
control.
The purpose of drawing a flowchart is to make the logic of the program clearer in a visual form.
The logic of the program is communicated in a much better way using a flowchart. Since flowchart
is a diagrammatic representation, it forms a common medium of communication.
Flowchart Symbols
A flowchart is drawn using different kinds of symbols. Every symbol used in a flowchart is for a
specific purpose.
Developing a Flowchart
Developing a flowchart is the process of visually representing the steps involved
in solving a problem or performing a task using standardized symbols. It helps in
understanding, analyzing, and communicating the logic of a program or process.
Steps in Developing a Flowchart
• Understand the Problem: Clearly define the task or process that needs to be
represented.
• Identify the Inputs and Outputs: Determine what information is needed (input)
and what result is expected (output).
• List the Key Steps: Break down the process into individual, logical steps.
• Decide the Flow Direction: Typically from top to bottom or left to right.
• Select Appropriate Symbols:
• Use standard flowchart symbols
• Oval – Start or End
• Rectangle – Process or action step
• Diamond – Decision or condition
• Parallelogram – Input or Output
• Arrows – Indicate flow of logic

• Draw the Flowchart:


• Connect the steps in the correct order using arrows.
• Ensure the logic flows smoothly and clearly.
• Review and Revise:

• Check for accuracy, completeness, and clarity.


• Revise if necessary to improve readability or correctness.
Guidelines for Preparing a Flowchart
Certain rules that must be followed while drawing a flowchart are given below.
• There can be only one start and one stop symbol in a flowchart.
• Only one flow line can be used with the start and stop symbol.
• Direction of flow of information in a flowchart must be from top to bottom or from left to right.
Relevant symbols must be used while drawing a flowchart.
• Only one flow line should come out from a process symbol.
• If the flowchart becomes complex, it is better to use connector symbols to
reduce the number of flow lines.
• The flow lines should not cross each other.
• Ensure that the flowchart has a logical start and finish.
• It is useful to test the validity of the flowchart by passing through it with a simple
test data.
Sequence Control Structure

In sequential control structure, a sequence of


statements is executed one after another in the
same order as they are written. The
instructions in sequence control flow are
executed exactly once
Selection Control Structure

In selection control structure, the condition is tested, and if


the condition is true, one set of statements are executed; if
the condition is false, an alternative set of statements are
executed.
This flowchart compares three numbers and finds the
maximum of the three numbers. A decision is taken based
upon a condition, which decides the next path to be followed,
i.e., if A is greater than B then the true path is followed, else
the false path is followed. Another decision is again made,
while comparing MAX with C.
Iterative Control Structure
In iteration control flow, a set of statements are repetitively executed
based upon a condition. If a condition evaluates to true, the set of
statements (true block) is executed again and again. As soon as the
condition becomes false, the repetition stops. This is also known as
looping statement or iteration statement.
Example
This flowchart finds the sum of first 100 integers (1+2+3+ ….. +100).
In the decision box, the value of i is compared with 100. If it is false,
a loop is created, which ends when the condition becomes true.
Advantages of Flowchart
• The symbols used in a flowchart are self-explanatory. This makes a flowchart easier to
understand.
• Being a graphical representation, flowcharts better communicate the problem-solving logic to the
users.
• With the help of a flowchart, a problem can be analysed in an effective way.
• It also helps in monitoring, data collection and identifies areas for improvement or increase in
efficiency.
Limitations of Flowchart
• In case of large programs, the flowcharts may continue too many pages. This makes them difficult to
understand.

• It takes a lot of time to represent a program diagrammatically.


• Any changes or modification in a flowchart usually requires redrawing the entire flowchart. It is a challenging
job.
PSEUDOCODE
• A pseudocode is another way of representing an algorithm.
• Pseudocode is a short, readable and formally styled English language used for explaining an
algorithm.
• Pseudocode does not include details like variable declarations, subroutines etc. It is a short
hand way of describing a computer program.
• Using Pseudocode, it is easier for a programmer or a non-programmer to understand the
general working of the program, because it is not based on any programming language.
• It is used to give a sketch of the structure of the program, before the actual coding. It is not
machine readable.
• Pseudocode cannot be compiled or executed. There is no standard for the syntax of
Pseudocode.
Developing a Pseudocode

Pseudocode is written using structured English.


The programmers may use their own style for writing the Pseudocode, which can be easily
understood. It never uses the syntax of any programming language.
Pseudocode uses some keywords to denote programming process. Some of them are as follows.

Input: INPUT, GET, READ and PROMPT


Output: OUTPUT, PRINT, DISPLAY and SHOW
Processing: COMPUTE, CALCULATE, DETERMINE, ADD, SUBTRACT, MULTIPLY and DIVIDE
Initialize: SET and INITIALISE
Incrementing: INCREMENT
The Keywords should be capitalized.
There are three control structures used in Pseudocode. They are,

a. Sequence control structure


b. Selection control structure and
c. Iteration control structure
Sequence Control Structures

In sequence control structure, the statements are executed one after another in the same order as
they are written from top to bottom. The statements in sequence control structure are executed
exactly once.
Selection Control Structure

In selection control structure, the condition is tested, and if the condition is true, one set of
statements are executed; if the condition is false, an alternative set of statements are executed.
There are two main selection structures: They are,
1. IF-THEN-ELSE statement
2. CASE statement
The IF-THEN-ELSE statement:
In IF-THEN-ELSE selection structure, if the condition is true, the THEN part is executed.
Otherwise, the ELSE part is executed.
The CASE statement
The case statement is used, when many numbers of conditions to be checked. In a case
statement, depending on the expression, one of the conditions is true. Based on the value, the
corresponding statements are executed. If no match for the expression occurs, then the default
option is executed.

The CASE structure compares the value of the variable. When it matches, the statement block of
that particular case is executed.
Iterative Control Structures
In iterative control flow, a set of statements are repetitively executed based upon a condition. If a
condition evaluates to true, the set of statements (true block) is executed again and again. As soon
as the condition becomes false, the repetition stops. This is also known as looping statement or
iteration statement.
There are two iterative control structures. They are, WHILE and DO-WHILE.
In WHILE loop, the condition is executed at the beginning of the loop. If the condition is false then
the loop will not be executed.

In DO- WHILE loop, the condition is executed at the end of the loop, so the loop is executed at least
once irrespective of the loop.
• The WHILE loop and DO-WHILE loop, execute the statements while the condition is true.
• The difference is, in WHILE loop the condition is checked at the start of the loop, whereas, in
DO-WHILE loop the condition is checked at the end of the loop.
• So, the DO-WHILE loop executes the statements at least once, even if the condition is false.
Advantages of Pseudocode

• Before writing codes in a high level language, a pseudocode of a program helps in representing
the basic functionality of the intended program.
• By writing the code first in a human readable language, the programmer do not miss out any
important step.
• Pseudocode helps the programmers to review the steps to confirm that the proposed
implementation is going to achieve the desire output.
• A Pseudocode is closer to the programming code. Thus, it can be easily converted into the
actual program.
Limitations of Pseudocode
• It is difficult to understand and manipulate Pseudocode as compared to algorithm and flowchart.
• As there are no specific standards for writing Pseudocode, it becomes hard to maintain
consistency.
Thank You

You might also like