0% found this document useful (0 votes)
6 views

Module 2 - Problem Solving With Computers Workshop

This document outlines the objectives and concepts related to problem solving with computers, including the definition of problems, algorithms, and computer programs. It describes various problem-solving methods, stages of the problem-solving process, properties of well-designed algorithms, and ways to represent algorithms such as narratives, pseudocode, and flowcharts. Additionally, it covers programming constructs and provides review questions to reinforce learning.

Uploaded by

Shaun Davis
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)
6 views

Module 2 - Problem Solving With Computers Workshop

This document outlines the objectives and concepts related to problem solving with computers, including the definition of problems, algorithms, and computer programs. It describes various problem-solving methods, stages of the problem-solving process, properties of well-designed algorithms, and ways to represent algorithms such as narratives, pseudocode, and flowcharts. Additionally, it covers programming constructs and provides review questions to reinforce learning.

Uploaded by

Shaun Davis
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
You are on page 1/ 32

Module 2

Problem Solving With


Computers
Objectives
At the end of this lesson you should be able to:

1) explain concepts related to problem solving

2) apply approaches to problem solving

3) describe the stages of the problem solving process

4) identify the necessary properties of algorithms that are well designed

5) identify the different ways of representing algorithms

6) explain the constructs used in structured programming

7) interpret algorithms from case problems

8) analyse algorithms from case problems for correctness

9) develop algorithms from case problems; and

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.

A narrative description of an algorithm is similar to a recipe. It is written in a step-by-step format, and it is


easy to understand for people who are not familiar with programming.

Here is a narrative of the algorithm for finding the average of two numbers:

➔ Read the two numbers from the user.


➔ Add the two numbers together.
➔ Divide the sum by 2.
➔ Display the result to the user.
Pseudocode
Pseudocode is a mix of plain English and programming language constructs. It is used to describe the logic of an
algorithm without having to worry about the specific syntax of a particular programming language.

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

Eg: IF number > 5 THEN


Sum = number * number
ENDIF
Continued
2) IF-THEN-ELSE Construct

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

Eg: IF number < 0 THEN


neg_num = neg_num + 1 (neg_num++)
ELSE
pos_num = pos_num + 1 (pos_num++)
ENDIF
3) Nested If Statement
IF <condition> THEN
Statement 1 Continued
ELSE Example using C
IF <condition2> THEN
Statement2 printf(“Please enter your grade”);
ELSE scanf(“%d”, &grade);
IF <condition3> THEN if(grade >= 90)
Statement 3 printf(“You got an A+”);
IF <condition4> THEN Else if(grade >= 80)
Statement 3 printf(“You got a B”);
Else if(grade >= 70)
ELSE printf(“You got a C”);
Else if(grade >= 60)
Statement 4 printf(“You got a D”);
Else
printf(“You got an F”);
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:

WHILE Value <> -1 DO


<actions to be repeated>

ENDWHILE
Continued
2) For Loop

For <variable> = <Beginning value> TO <Ending value> DO


<Actions to be repeated>
ENDFOR

Eg: For tally = 1 to 10 DO


Print “Enter a value greater than 4”
Read value
ENDFOR
Review Questions
1) List three control structures used in creating problem
2) State and explain the steps in the problem solving process
3) State and explain the approaches to problem solving
4) State three properties of well designed algorithms
5) Explain the role of an algorithm
6) Discuss the importance of an algorithm
7) List the three ways of representing an algorithm
8) Discuss how you would choose a method of representing an algorithm
9) Differentiate problem and problem solving
10) Define a solution
11) Define a computer program
Past Paper Google Doc Link

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.

Design strategies . (n.d.).

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/

You might also like