0% found this document useful (0 votes)
15 views9 pages

The Problem Solving Process

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

THE PROBLEM SOLVING PROCESS

In any field of study, problem-solving is a fundamental skill, and in computer science, this skill is
applied using computers. Whether the problem arises from the real world or an abstract concept, a
systematic approach is essential for finding solutions. Since computers are our tools for problem-
solving, it's crucial to understand how they process information. Typically, a computer with a CPU
(Central Processing Unit) follows a model where it takes input, processes it, and then produces
output. This basic model can be expanded to multiple CPUs in modern computers, but the core
principles of input, processing, and output remain the same. Understanding this model is the first
step toward effectively using computers to solve problems.

Computer as a Model of Computation

In problem-solving, we apply the model of computation where we start with some input
information, process it, and produce the desired output as the solution. While this basic model
works well for simple problems, more complex problems often require multiple iterations of the
input/process/output stages. These iterations produce intermediate results that help solve parts of
the problem before reaching the final solution.

The essence of problem-solving lies in how we handle the "process" part of this model. Therefore,
understanding and mastering this stage is crucial. Here's a simple definition of problem-solving
within this context:

Definition 1-1: Problem Solving is the sequential process of analyzing information related to a given
situation and generating appropriate response options.

To illustrate how this model works, consider a straightforward example:

Example: Calculate the average grade for all students in a class.

Input: Collect all the grades, either by typing them in via the keyboard or by reading them from a
storage device like a USB flash drive.

Process: Sum all the grades and calculate the average.

Output: Display the average grade on a monitor, print it, or save it back to a storage device.

This simple example shows how the problem can be solved by following the input, process, and
output steps. As we dive deeper into problem-solving, we'll explore how to handle more complex
scenarios using this fundamental model.
Understanding the Problem

The first step in solving any problem is to ensure you fully understand it. This means identifying the
data provided, understanding what it represents, and knowing the expected output.

Key Questions to Consider:

 Input Data: What data is available, and in what format?


 Missing Information: Is any data missing? How should it be handled?
 Output Requirements: What needs to be produced, and in what format?
 Processing: What operations need to be performed on the data?

Example:

If you're asked to calculate the average grade for a class:

Input: Some grades might be numerical (e.g., 85, 90) and others in letter form (e.g., A-, C+).

Missing Data: Some students might not have grades due to absence.

Output: The result could be a number, letter grade, or graph.

To solve the problem, we must first understand the format of the grades:

The grades could be numbers ranging from 0 to 100 (e.g., 73 or 73.42), or they could be letter grades
like A to F.

The format matters because different types of data (numbers vs. letters) require different methods
of calculation.

We also need to address missing grades. If a student doesn’t have a grade, how should we handle it?
For example, if a student was absent, do we:

Include them with a grade of 0?

Exclude them from the average?

Next, we need to decide on the output format. Should the average be a:

Whole number (e.g., 80),

Real number (e.g., 79.5), or Letter grade?


Lastly, it's important to understand the processing involved. What calculations or operations are
needed to process the data? This will guide how we approach solving the problem.

Formulating a Model
Once the problem is understood, the next step is to figure out how to process the available data.
This often involves breaking the problem into smaller, more manageable parts and using
mathematical formulas to get the desired result.

Definition
Formulating a model involves creating a formula or approach to process the input data. This
model helps us compute the result accurately. If no standard formula exists, we must develop
one.

Example: Computing an Average


Let’s consider the example of calculating the average grade for a group of students. If the input
grades are numbers (e.g., 𝑥₁, 𝑥₂, …, 𝑥ₙ), the formula to compute the average is straightforward:

Average₁ = (𝑥₁ + 𝑥₂ + ⋯ + 𝑥ₙ) / n

Here, the grades are added up and divided by the number of students, resulting in a grade
between 0 and 100.

Handling Letter Grades


However, if the grades are in letter format (e.g., A+, B-, C), simple addition and division won’t
work. We must first convert the letter grades to numbers. For instance, we can assign values as
follows:

A+ = 12, A = 11, A- = 10
B+ = 9, B = 8, B- = 7
C+ = 6, C = 5, C- = 4
D+ = 3, D = 2, D- = 1
F=0

Once converted, we can apply a similar formula for calculating the average:

Average₂ = (𝑦₁ + 𝑦₂ + ⋯ + 𝑦ₙ) / n

where 𝑦₁, 𝑦₂, …, 𝑦ₙ are the numerical equivalents of the letter grades.
Output Representation
The output can then be formatted as required:

If the output should be a percentage, you can use the first average directly or convert the second
formula’s result:

Average (as percentage) = (Average₂ / 12) × 100

If the output should be a letter grade, you can use a lookup table to map the final number back
to a letter grade.

Develop an Algorithm

Having understood the problem and formulated a model, it is time to come up with a precise

plan of what the computer is expected to do.

Definition : Algorithm is a precise sequence of instructions for solving a problem.

Let’s use a simple math problem to develop an algorithm.

Example: Finding the Sum of Two Numbers

Step 1: Start

Step 2: Input the first number (A).

Step 3: Input the second number (B).

Step 4: Add the two numbers (A + B).

Step 5: Display the result.

Step 6: End

Two commonly used representations for an algorithm is by using


(1) pseudo code, or (2) flowcharts.
Pseudocode

Pseudocode is a way to describe an algorithm using plain language and simple structures. It’s a
rough draft of a program's logic, written in a way that's easy to understand without worrying
about specific programming language syntax.

a simple pseudocode example for adding two numbers:

1. Start
2. Input number1
3. Input number2
4. Sum = number1 + number2
5. Output Sum
6. End

simple pseudocode example for checking if a number is even or odd:

1. Start
2. Input number
3. If number modulo 2 equals 0
a. Output "Even"
4. Else
a. Output "Odd"
5. End

Here's a very simple pseudocode for calculating the average of three


numbers:

1. Start
2. Input number1
3. Input number2
4. Input number3
5. Average = (number1 + number2 + number3) / 3
6. Output Average
7. End

Test case

A test case is a set of conditions or variables used to determine whether a system or software
application behaves as expected. It typically includes a set of inputs, execution conditions, and
expected results.

Test Steps:

Sample Test case for calculating the average of three numbers

1. Input number1 = 10
2. Input number2 = 20
3. Input number3 = 30
4. Click on the "Calculate Average" button
Expected Result: The output should be 20.

Actual Result: (To be filled in after running the test)

Status: (To be filled in after running the test)

Writing the Program

Once the algorithm is defined, the next step is to convert it into a form that a computer can
execute. This process is known as writing the program, coding, or implementing an
algorithm.

Steps to Writing a Program

1. Understand the Algorithm:


o Ensure that you have a clear and precise algorithm outlining the steps to solve
the problem.
o The algorithm should include all necessary inputs, operations, and outputs.
2. Translate Algorithm to Pseudocode:
o Before coding, convert the algorithm into pseudocode, which is a simplified,
human-readable representation of the steps.
o Pseudocode helps in visualizing the logic without worrying about syntax.
3. Implement in Code:
o Translate the pseudocode into a specific programming language. This
involves:
 Defining Variables: Initialize variables as needed.
 Input Handling: Write code to capture user inputs or read data.
 Processing Logic: Implement the core algorithm steps in code.
 Output Handling: Display or return results to the user.
4. Testing and Debugging:
o After writing the code, test it with various inputs to ensure it works as
expected.
o Debug any issues or errors that arise during testing.

Key Points

Coding: Refers to writing the actual code that implements the algorithm.

Source Code: The written program in a specific programming language.

Implementation: The process of translating an algorithm into executable code.


Sample Code :

# Step 1: Initialize sum

sum = 0

# Step 2: Input three numbers

number1 = float(input("Enter the first number: "))

number2 = float(input("Enter the second number: "))

number3 = float(input("Enter the third number: "))

# Step 3: Calculate sum

sum = number1 + number2 + number3

# Step 4: Compute the average

average = sum / 3

# Step 5: Print the average

print("The average is:", average)

Testing the Program

Introduction

Once a program has been written and compiled, the next critical step is to ensure that it performs
the intended task correctly. Testing the program involves running it with various inputs to verify its
accuracy and reliability.

Key Steps in Testing the Program

Running the Program:

Running a program is the process of executing the compiled code on a computer.

If the program runs correctly, the expected output should be displayed.

Testing for All Cases:


It's possible that a program may work correctly for some inputs but fail for others.

Therefore, a program should be tested with a variety of input data to cover all possible scenarios.

Handling Errors:

If the output is incorrect, it could be due to:

The algorithm not being properly implemented in the program.

A flaw in the algorithm itself, which does not account for certain situations.

Bugs:

Definition: Bugs are errors in a program that cause it to produce incorrect or undesirable results.

Bugs can occur due to:

Misinterpretation of the algorithm.

Errors in the sequence of instructions.

Oversights that cause the program to handle specific input cases incorrectly.

Debugging:

Definition: Debugging is the process of finding and fixing errors (bugs) in the program.

It involves systematically testing different cases to locate the issues and correcting them.

Evaluating the Solution

Introduction

After a program produces results, it is important to evaluate those results in the context of the
original problem. This step ensures that the output is not only correct but also meaningful and
in the required format.

 Reconsider the Original Problem: Ensure the program’s output aligns with the original
problem and is in the correct format.

 Interpreting the Results: Present the results in a clear and meaningful way that aids
decision-making, using tools like charts if needed.
 Adjusting the Solution: If necessary, add more steps or data to fully solve the problem or
improve the solution’s effectiveness.

 Efficiency Considerations: Evaluate the program’s performance and make improvements


if it’s too slow or uses too many resources.

 User Responsibility: It’s up to the user or programmer to ensure the solution truly solves
the problem; further adjustments may be needed.

You might also like