Introduction to problem solving
Introduction to problem solving
Problem - Meaning
Why is problem solving important? Good problem solving skills empower you not
only in your personal life but are critical in your professional life. In the current
fast-changing global economy, employers often identify everyday problem solving
as crucial to the success of their organizations. For employees, problem solving can
be used to develop practical and creative solutions, and to show independence and
initiative to employers.
There are 6 steps that you should follow in order to solve a problem:
1. Understand the Problem
2. Formulate a Model
3. Develop an Algorithm
4. Write the Program
5. Test the Program
6. Evaluate the Solution
Examples of PS:
Example 1: A simple example on input/process/output. Calculate the average
grade for all students in a class.
Input: get all the grades … perhaps by typing them in via the keyboard or by
reading them from a USB flash drive or hard disk.
Process: add them all up and compute the average grade.
Output: output the answer to either the monitor, to the printer, to the USB flash
drive or hard disk … or a combination of any of these devices. To solve the
problem, we need to understand the problem. Thus, these questions???????
● What input data/information is available?
● What does it represent?
● What format is it in?
● Is anything missing?
● Do I have everything that I need?
● What output information am I trying to produce?
● What do I want the result to look like … text, a picture, a graph … ?
● What am I going to have to compute?
In the example,
● The input is a bunch of grades
● We need to understand the format of the grades
● Each grade might be a number from 0 to 100
● It may be a letter grade from A to F
● If it is a number, the grade might be a whole integer like 73 or it may be a
real number like 73.42
● Need to consider missing grades, if we do not have the grade for every
student (e.g.,some were away during the test) ????
● Understand what the output should be (output a whole or real number or a
letter grade??????)
● Display results using charts
The need to understand the processing part of the problem. Break the problem into
smaller problems that require some kind of simple mathematical computations in
order to process the data since we are going to compute the average. So, what is the
model (or formula) for computing the average of a bunch of numbers? If there is
no such “formula”, then, there is a need to develop one. Sometimes, we can look
up certain formulas in a book or online if we get stuck. To come up with a model,
we need to fully understand the information available to us.
Assuming that the input data is a bunch of integers or real numbers x1,x2,…,xn
representing a grade percentage, we can use the following computational model:
Average1 = (x1 + x2 + x3 + … + xn) / n
where the result will be a number from 0 to 12. The next is formulating an
algorithm.
Example 3: Some students in a class plan to host an event and decide to share the
expenses among them. So, making up plans including budgets, noting all activities,
risks, alternatives, etc. is also a kind of problem solving.
The problems that we want to solve can come from any real-world problem or
perhaps even from the abstract world. We need to have a standard systematic
approach to solving problems. The three basic purposes include:
1.Seeking information
2.Generating new knowledge
3.Making decisions
Introduction
One common problem in science has been the overload that occurs when the
demand on working memory exceeds its capacity. Solution to this overload is to
help students build strategies that decrease a task's demand on working memory.
These strategies have been described as the tricks for simplifying problems.
Problem solvers go through certain steps while working on a problem. These may
be more or less as follows;
● Begin by reading the problem
● Perhaps more than once
● Then write down hopefully, the key information
● Reread the question or a part of the question
● Draw a picture to help represent the question
● Then try something
● Try something else
● Look at where it leads
These strategies are algorithms that automate individual steps in solving problems.
Thus,
gradually exploring or playing with the question individuals get closer and closer
to the answer.
Algorithm
Algorithm is the set of step-by-step measures or rules followed to complete a given
task or solve a particular problem. It is “a process that performs some sequence of
operations in order to solve a given problem”. The set of rules must be
unambiguous and have a clear stopping point. Note that there might be other ways
to solve a problem; as a result, there may be more than one algorithm for a
problem. Algorithms are used in calculation, data processing, and many other
fields. They are essential because algorithms provide the organized procedures that
computers require.
Example of Algorithm
Problem to solve: Write an algorithm to read two numbers and find their sum.
Inputs to the algorithm (accept two inputs):
● First num1
● Second num2
Expected output:
● Sum of the two numbers
Algorithm:
Step1: Start
Step2: input the first num1.
Step3: input the second num2.
Step4: Sum = num1+num2
Step5: Print Sum
Step6: End
Characteristics of an Algorithm
● Precision: the steps are precisely stated or defined accurately.
● Uniqueness: results of each step are uniquely defined and only depend on
the input and the result of the preceding steps.
● Finiteness: An algorithm always stops after a finite number of steps.
● Input: An algorithm must have some form of input.
● Output: An algorithm must produces some output
● Unambiguous: Each step in an algorithm should have only one
interpretation.
Types of Algorithm
Algorithms are classified according to what they are being used to achieve. The
basic types of computer science algorithms include:
● Divide and conquer algorithms – divide the problem into smaller
subproblems of the same type; solve those smaller problems, and combine
those solutions to solve the original problem.
● Brute force algorithms – try all possible solutions until a satisfactory
solution is found.
● Randomized algorithms– use a random number at least once during the
computation to find a solution to the problem.
● Greedy algorithms – find an optimal solution at the local level with the
intent of finding an optimal solution for the whole problem.
● Recursive algorithms– solve the lowest and simplest version of a problem
then, solve increasingly larger versions of the problem until the solution to
the original problem is found.
● Backtracking algorithms – divide the problem into subproblems, each which
can be attempted to be solved; however, if the desired solution is not
reached, move backwards in the problem until a path is found that moves it
forward.
● Dynamic programming algorithms – break a complex problem into a
collection of simpler sub problems, and then solve each of those sub
problems only once, storing their solution for future use instead of
re-computing their solutions.
Importance of Algorithm
Algorithmic thinking is vital in many different fields. Some of the benefits are:
● Allows students to breakdown problems and conceptualize solution in
distinct steps
● Being able to understand and implement an algorithm necessitates students
to exercise planned assessment and reasoning abilities.
● By using an algorithm, decision making becomes a more rational process.
● Makes PS process more efficient and consistent
Introduction
A flowchart is a visual representation of an algorithm, workflow or process,
showing the steps as boxes of various kinds, and their order by connecting them
with arrows. This diagrammatic representation illustrates a solution model to a
given problem. Flowcharts are used in analyzing, designing, documenting or
managing a process or program in various fields. Like other types of diagrams,
they help visualize what is going on and thereby help understand a process, and
perhaps also find flaws, bottlenecks, and other less-obvious features within it. Each
shape represents a step of the solution process and the arrow represents the order or
link among the steps. There are many different types of flowcharts, and each type
has its own repertoire of boxes and notational conventions. Common alternative
names include: flowchart, process flowchart, functional flowchart, process map,
process chart, functional process chart, business process model, process model,
process flow diagram, workflow diagram, business flow diagram.
A well-made flowchart can be used to break big ideas into small, bite-sized pieces
that are expressed visually, so knowing how to make one is sort of like having a
universal language. Being able to flowchart makes it possible to communicate with
any stakeholder or audience, because visuals are typically easier to understand than
words. For this reason, flowcharts are a valuable type of business diagram but can
also be used for more technical fields like manufacturing or software engineering.
Process
It represents a process,
action, or a single step.
As pointed out earlier, flowcharts illustrate where data are being input and output,
where information is being stored, what decisions need to be made, and which
people need to be involved. In addition to the basic flowchart conventions, rules,
and symbols, there are intermediate flowchart symbols that help describe a process
with even more detail.
Algorithm Flowchart
1. A method of representing the 1. Flowchart is a diagrammatic
step-by-step logical procedure for solving representation of an algorithm. It is
a problem constructed using different types of boxes
and symbols.
3. These are particularly useful for small 3. These are useful for detailed
problems representations of complicated programs
4. For complex programs, algorithms 4. For complex programs, Flowcharts
prove to be inadequate prove to be adequate
Advantages of Flowcharts
1. It is the most efficient way of communicating the logic of the system.
2. It acts as a guide for a blueprint during the program design.
3. It also helps in the debugging process.
4. Using flowcharts we can easily analyze the programs.
5. flowcharts are good for documentation.
Sample Flowcharts
1. Draw a flowchart to find the square of a number
Algorithm
Step 1: Start
Step 2: Input number num.
Step 3: Square = num*num
Step 4: Print Square
Step 5: End
Flowchart
Algorithm
Step 1: Start
Step 2: Input number num
Step 3: Check if num%2== 0
Step 4: Print Even
Step 5: Else
Step 6: Print Odd
Step 7: End
Flowchart
Conclusion
Flowcharts are simple diagrams that map out a process, so that that can easily be
communicated to other people. They are typically used to define and analyze a
process, build a step-by-step picture of it, and then standardize or improve it.
To draw a flowchart, identify the tasks and decisions that you make during a
process, and write them down in order. Then, arrange these steps in the flow chart
format, using the appropriate symbols.
Finally, check and challenge your flowchart to make sure that it accurately
represents the process, and that it shows the most efficient way of doing the job.
Pseudocode
Introduction
As developers, programmers or data scientists, we often go through many stages,
from getting an idea to reaching a valid, working implementation of it. We need to
design/ validate an algorithm, apply it to the problem at hand, and then test it for
various input datasets. In the initial state of solving a problem, it helps a lot if we
could eliminate the hassle of having to be bound by the syntax rules of a specific
programming language when we are designing or validating an algorithm. By
doing this, we can focus our attention on the thought process behind the algorithm,
how it will/ won’t work instead of paying much attention to how correct our syntax
is. Here is where pseudocode comes to the rescue. Pseudocode is often used in all
various fields of programming, whether it be app development, data science, or
web development. Pseudocode is a technique used to describe the distinct steps of
an algorithm in a manner that is easy to understand for anyone with basic
programming knowledge.
Although these 6 constructs are the most often used, as you can theoretically use
them to implement any algorithm. You might find yourself needing some more
based on your specific application.
Pseudocode Examples
1. Write a pseudocode that reads two numbers and multiplies them together and
print out their product.
READ 𝑛𝑢𝑚1 , 𝑛𝑢𝑚2
SET product to 𝑛𝑢𝑚1* 𝑛𝑢𝑚2
Write product
2. Write a pseudocode that tells a user that the number they entered is not a 5 or a
6.
READ num
IF (num = 5)
WRITE "your number is 5"
ELSE IF (num = 6)
WRITE "your number is 6"
ELSE
WRITE "your number is not 5 or 6"
END IF
3. Write a pseudocode that performs the following: Ask a user to enter a number. If
the number is between 0 and 10, write the word blue. If the number is between 10
and 20, write the word red. if the number is between 20 and 30, write the word
green. If it is any other number, write that it is not a correct color option.
WRITE "Please enter a number"
READ color_num
IF (color_num >0 and color_num <= 10)
WRITE blue
ELSE IF (color_num >0 and color_num <= 10)
WRITE blue
ELSE IF (color_num >0 and color_num <= 10)
WRITE blue
Else
WRITE "not a correct color option"
END IF