Problem Solving Module Csc102
Problem Solving Module Csc102
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Problem-solving strategies defined
3.2 Importance of Understanding Multiple Problem-solving Strategies
3.3 Commonly Used Problem-Solving Strategies
3.3.1 Trial and Error
3.3.2 Algorithm and Heuristic
3.3.3 Means-Ends Analysis
3.4 Other Problem-solving Strategies
4.0 conclusion
1.0 INTRODUCTION
People face problems every day—usually, multiple problems throughout the day. Sometimes these
problems are straightforward, sometimes, the problems we encounter are more complex. For
example, say you have a work deadline, and you must mail a printed copy of a report to your
supervisor by the end of the business day. The report is time-sensitive and must be sent overnight.
You finished the report last night, but your printer will not work today. What should you do? First,
you need to identify the problem and then apply a strategy for solving the problem.
2.0 OBJECTIVES
By the end of this unit, you will be able to:
• define problem solving strategies
• define algorithm and heuristic and their role in problem solving
• describe typical common problem solving strategies
• explain some common roadblocks to effective problem solving.
Another useful heuristic is the practice of accomplishing a large goal or task by breaking it into a
series of smaller steps. Students often use this common method to complete a large research project
or long essay for school. For example, students typically brainstorm, develop a thesis or main topic,
research the chosen topic, organize their information into an outline, write a rough draft, revise and
edit the rough draft, develop a final draft, organize the references list, and proofread their work
before turning in the project. The large task becomes less overwhelming when it is broken down
into a series of small steps.
Table 1.1 summarized the four commonly used problem solving strategies
4.0 CONCLUSION
Of course, problem-solving is not a flawless process. There are a number of different obstacles that
can interfere with the ability to solve a problem quickly and efficiently. These include functional
fixedness, irrelevant information, and assumptions.
When dealing with a problem, people often make assumptions about the constraints and obstacles
that prevent certain solutions. Functional fixedness is the tendency to view problems only in their
customary manner. It prevents people from fully seeing all of the different options that might be
available to find a solution. It is important to distinguish between information that is relevant to the
issue and irrelevant data that can lead to faulty solutions. When a problem is very complex, the
easier it is to focus on misleading or irrelevant information.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Computer as a model of computation
3.2 Understanding the Problem
3.3 Formulating a Model
3.4 Developing an Algorithm
3.5 Writing the Program
3.6 Testing the Program
3.7 Evaluating the Solution
4.0 CONCLUSION
2.0 OBJECTIVES
By the end of this unit, you will be able to:
• Understand the computer as a model of computation
• Explain the problem solving process in detail
• Apply the problem solving paradigm to routine elementary problems
After some thought, we may decide to assign an integer number to the incoming letters as follows:
+ = 12 = 11 − = 10 +=9 =8 −=7 +=6 =5 − =4 +
Representation of Algorithms
There are two common methods of representing an algorithm flowchart and pseudocode.
Either of the methods can be used to represent an algorithm while keeping in mind the following:
• It showcases the logic of the problem solution, excluding any implementation details
• It clearly reveals the flow of control during execution of the program
Pseudocode
A pseudocode (pronounced Soo-doh-kohd) is another way of representing an algorithm. It is
considered as a non-formal language that helps programmers to write algorithm. It is a detailed
description of instructions that a computer must follow in a particular order. It is intended for human
reading and cannot be executed directly by the computer. No specific standard for writing a
pseudocode exists. The word “pseudo” means “not real,” so “pseudocode” means “not real code”.
Following are some of the frequently used keywords while writing pseudocode:
• INPUT
• COMPUTE
• PRINT
• INCREMENT
• DECREMENT
• IF/ELSE
• WHILE
• TRUE/FALSE
Advantages of Pseudocode
1. Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
2. Acts as a bridge between the program and the algorithm or flowchart. Also works as a rough
documentation, so the program of one developer can be understood easily when a pseudo code is
written out. In industries, the approach of documentation is essential. And that’s where a pseudocode
proves vital.
3. The main goal of a pseudo code is to explain what exactly each line of a program should do,
hence making the code construction phase easier for the programmer.
Example 1.1: Write an algorithm to find the square of a number. using both pseudocode and algorithm.
Before developing the algorithm, let us first identify the input, process and output:
• Input: Number whose square is required
• Process: Multiply the number by itself to get its square
• Output: Square of the number Algorithm to find square of a number.
Pseudocode
Step 1: INPUT a number and store it to num
Step 2: COMPUTE num * num and store it in square
Step 3: PRINT square
Example 1.2: Write an algorithm to display the sum of two numbers entered by user, using both pseudocode
and flowchart.
Pseudocode for the sum of two numbers will be:
INPUT num1
INPUT num2
COMPUTE Result = num1 + num2
PRINT Result
Example 1.4: Let us write an algorithm to check whether a number is odd or even.
• Input: Any number
• Process: Check whether the number is even or not
• Output: Message “Even” or “Odd”
Pseudocode of the algorithm can be written as follows:
PRINT "Enter the Number"
INPUT number
IF number MOD 2 == 0 THEN
PRINT "Number is Even"
ELSE
PRINT "Number is Odd"
Pseudocode
1. Set the sum of the grade values to 0.
For now, the details of how to produce the above source code will not be discussed. In fact, the
source code would vary depending on the programming language that was used. Learning a
programming language may seem difficult at first, but it will become easier with practice.
The computer requires precise instructions in order to understand what it is being asked to do. For
example, removing one of the semi-colon characters (;) from the program above, will make the
computer become confused as to what it’s being asked to do because the semi-colon characters (;)
is what it understands to be the end of an instruction. Leaving one of them off will cause the
program to generate what is known as a compile-time error.
Definition 1-3: Compiling is the process of converting a program into instructions that can be understood by
the computer.
The longer a program is, the more the likelihood of having multiple compile-time errors. One needs to
fix all such compile-time errors before continuing on to the next step.
4.0 CONCLUSION
The decision to get a solution to any exist problem involve a cycle that consist of the following
using a Computer as a model of computation, Understanding the Problem, Formulating a Model,
Developing an Algorithm, Writing the Program, Testing the Program and finally Evaluating the
Solution.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Brute-force Approach
3.2 Divide-and-conquer Approach
3.2.1 Example: The Merge Sort Algorithm
3.2.2 Advantages of Divide and Conquer Approach
3.2.3 Disadvantages of Divide and Conquer Approach
3.3 Greedy Algorithm Approach
3.3.1 Characteristics of the Greedy Algorithm
3.4 Randomized Approach
4.0 CONCLUSION
1.0 INTRODUCTION
Solving a problem involves finding a way to move from a current situation to a desired outcome.
To be able to solve a problem using computational approaches, the problem itself needs to have
certain characteristics:
• The problem needs to be clearly defined — this means that one should be able to identify the current
situation, the end goal, the possible means of reaching the end goal, and the potential obstacles
• The problem needs to be computable — one should consider what type of calculations are required, and
if these are feasible within a reasonable time frame and processing capacity
• The data requirements of the problem need to be examined, such as what types of data the problem
involves, and the storage capacity required to keep this data
• One should be able to determine if the problem can be approached using decomposition and abstraction,
as these methods are key for tackling complex problems
Once these features of the given problem are identified, an informed decision can then be made as to
whether the problem is solvable or not using computational approaches.
4.0 CONCLUSION
Solving problems is a key professional skill. Quickly weighing up available options and taking
decisive actions to select the best computational approach to a problem is integral to efficient
performance.
It is important to always get the problem solving process right, avoiding taking too little time to
define the problem or generate potential solutions. A wide range of computational techniques for
problem solving exist, and each can be appropriate given the peculiarity of the problem and the
individual involved. The important skills to attain are to assess the situation independently of any
other factors and to know when to trust your own instincts and when to ask for a second opinion
on a potential solution to a problem.