Module 2 - Problem Solving With Computers Workshop
Module 2 - Problem Solving With Computers Workshop
10) explain the need for developing the logic of a computer program
Concepts related to problem solving
A problem is a state of difficulty that needs to be resolved while problem solving is a systematic approach or
process to resolve a computerised solution. It is a cognitive process that can be best achieved by following a
framework of activities.
A solution is the management of a problem in a way that successfully meets the goals set for treating.
An algorithm is a finite set of well defined instructions or step-by-step description of the procedure written in
human readable language for solving a given problem
A computer program is a set of instructions which direct the computer system to perform user specified task.
Also it an essential component of the computer system.
Role of an algorithm in the problem
solving process
➔ Provides a step-by-step guide to the problem solver
➔ Complete description of the solution
➔ Usually, a computer programmer first writes an algorithm and then translates it into the code of some
programming language.
➔ Sometimes, the designer of the program first makes a flowchart to solve a problem and then encodes
the flowchart into an algorithm
Importance of an algorithm in the
problem solving process
➔ Algorithms are used in every part of computer science
➔ Algorithm help software developers create efficient and error free programs.
➔ Algorithms are independent of programming language used
➔ Each algorithms can be express in different programming languages and executed on different
computers
Problem Solving Methods
The three problem solving methods as stated in the syllabus modular programming or top-down also called the
divide and conquer approach, bottom up and step-wise refinement.
Modular programming or top down design also known as divide and conquer approach in programming involves
continuously breaking or dividing a problem into successively smaller problem sets or sub-problems. Each module is
then further broken down into a set of tasks, then each task is broken down into a set of actions.
Features of this strategy is cohesion and coupling. Cohesion can be described as the arrangement of functions or
modules in a system, but in relation to performing a particular task well. Coupling is a measure of how interconnected
or functionally dependent the modules are written in a system.
Bottom up approach works by starting with individual components and building up to the larger system. This
approach is characterised by breaking down a large problem/project into smaller more manageable task, starting
with the details and working towards the bigger picture.
Step wise refinement the process of breaking down a programming problem into a series of steps. You start with a
general set of steps to solve the problem, defining each in turn. Once you have defined each of the steps you then
break the problem down into a series of smaller sub-steps.
Ensure you can draw these the syllabus says you should be
represent solutions using hierarchy chart
Modular Programming or Top Down
Design (Divide and Conquer)
Bottom Up Approach
Step Wise Refinement
Stages of the Problem Solving Process
Continued
Problem Definition - the first step is to be clear on what is the problem to be solved. Thus, to define the problem
the issue is to be solved must be explicitly stated, the boundaries conceptualised and also unambiguously
stated. If there is no clear and concise definition of what is the problem to be solved, then no correct solution
can be created.
Problem Analysis - the second step is to analyse the problem. Here, we see what data we have been given and
how we can use that data to achieve the goal. In this step we also look at the processing requirements to
transform the inputs into the required outputs.
Identify and Evaluate Alternative Solutions - after analysis the next logical step is to find solutions to the
problem. Some of the practical solutions to the problem may involve looking at solutions that were already built
for the problem you currently face or just developing your own-solution to the same problem.
Select and Justify the Optimal Solution - This can be done by rating each possible solution in a comparison
chart to check for suitability with regards to the scope of the problem being solved, the cost and the degree of
the stakeholder satisfaction with the proposed solution. In this step all of the possible solutions identified to
solve the problems are evaluated and the best choice selected. The selection may depend on a range of
factors such as affordability.
Implementation and Review - This involves representing the solution to the problem as an algorithm and
developing the algorithm into a functioning piece of software. Additionally, the completed solution is tested for
correctness to see if it meets the requirements outlined by stakeholders.
Properties of Algorithms that are well
designed
➔ General solution to a problem
➔ Clearly defined and unambiguous steps
➔ Finite number of steps
➔ Flow of control from one process to another
Ways of Representing Algorithms
Narrative
A narrative is a plain English description of an algorithm. It is the least formal way to represent an algorithm,
but it can be useful for communicating a high-level overview of the algorithm to a non-technical audience.
Here is a narrative of the algorithm for finding the average of two numbers:
Pseudocode is a more structured way to describe an algorithm. It uses programming language constructs such as
loops, conditional statements, and functions. However, pseudocode is not meant to be compiled or executed by a
computer.
Example:
Start
Declare price, newPrice, discountPrice as float
Declare product as string
Display (“Enter the name of the product”)
Read product
Display (“Enter the price of an item”)
Read price
//calculating the discount price
discountPrice = price * 0.15
newPrice = price - discountPrice
//printing the result
Display (“The finall cost is of”, product)
Display (“The new price is”, newPrice)
STOP
Flowchart
A flowchart is a graphical representation of an algorithm. It uses boxes and arrows to show the flow of control
through the algorithm.
Flowcharts are a visual way to represent algorithms. They use a variety of symbols to represent different steps
in the algorithm, such as input, output, decision making, and looping. Flowcharts can be helpful for
understanding the overall flow of an algorithm, but they can be difficult to create and maintain for complex
algorithms.
Constructs used in Programming
Programs are developed from the following:
1) Input statements
2) Output statements
3) Control Structures
a) Sequence
b) Selection
c) Iteration
4) Assignment Statements
Syntax
Input Statements
Read/Input <variable>
Eg: Read price
Output statements
Output/Display/Print/Write(“the variable is”, <variable>)
Eg: Display (“The new price is”, newPrice)
Selection Control Structure
1) IF-THEN Construct
IF <Condition> THEN
<instructions that will be carried out if the condition is true>
ENDIF
IF <Condition> THEN
<statements that will be carried out if the condition is true>
ELSE
<statements that will be carried out if the condition is false>
ENDIF
ENDIF
ENDIF
ENDIF
Continued
4) Case Statements Switch (Number)
{
Case <variable> Case 8: printf(“Eight”);
C1: <Statements to be executed> Break;
C2: <Statements to be executed> Case 7: printf(“Seven”);
C3: <Statements to be executed> Break;
C4: <Statements to be executed> Case 6: printf(“Six”);
C5: <Statements to be executed> Break;
Default: printf(“Try Again!”);
}
Iterative Structures
1) While Loop
WHILE <condition> DO
<Action to be taken if condition is true>
ENDWHILE
Eg:
ENDWHILE
Continued
2) For Loop
https://docs.google.com/document/d/15c1_IR0HErNyzfTw75TXoLA1rI9g4U3h
rA5qnNi0wdU/edit
Answers to questions
References
Duncan, O. (2022). Computer Science for CAPE: Units 1 & 2 . LMH Publishers.
https://www.tutorialspoint.com/system_analysis_and_design/system_analysis_and_design_strategies.htm
LearnLearn. (2023, November 4). Learn Learn - Computer science lessons & resources . https://learnlearn.uk/