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

Lecture Unit 2

Intro to python

Uploaded by

hashimabdulatwif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lecture Unit 2

Intro to python

Uploaded by

hashimabdulatwif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

UNIVERSITY OF LUSAKA

SCHOOL OF SOCIAL SCIENCES AND TECHNOLOGY

LECTURE~UNIT 2: Problem Solving Processes 1


NAME: Longwani C Perry (Mr.)
CONTACT: +260 966589151
PROBLEM SOLVING PROCESS
§ In this course we are looking at gaining skills
that will allow us to solve problems involving the
use of computers via computer programs.

§ A problem in this course will be understood as a


task that has to be carried out or performed.

§ Specifically, focus will be on what we refer to as


computational problems.
PROBLEM SOLVING PROCESS
§ A computational problem is a problem that can
be solved step-by-step with a computer.

§ These problems usually have a well-defined


input, constraints, and conditions that the
output must satisfied.
PROBLEM SOLVING PROCESS
§ Here are some types of computational problems:

§ A decision problem is one where the answer


is yes or no. For example determining
whether a given number is a prime number
or not.

§ A search problem is one where the solution


consists of one or more values that satisfies a
given condition, for example, computing a
path on a map from one location to the other
PROBLEM SOLVING PROCESS
§ Here are some types of computational problems:

§ A counting problem is one where the answer is the


number of solutions to a search problem. For example a
problem where given a positive integer n, you are
required to count the number of prime factors of n

§ An optimization problem is one where the solution is


the "best" possible solution among possible solutions,
where the "best" can be defined in a different way such
as fastest route, most accurate value…etc.
PROBLEM SOLVING PROCESS
§ Here are some types of computational problems:

§ A function problem where a single output (of


a total function) is expected for every input,
but the output is more complex than that of a
decision problem, that is, it isn't just "yes" or
"no". One of the most famous examples is the
traveling salesman problem:
"Given a list of cities and the distances between each pair
of cities, find the shortest possible route that visits each city
exactly once and returns to the origin city."
PROBLEM SOLVING PROCESS
§ Therefore if we are going to think of solving
computational problems, we have to understand
computational thinking.
§ Computational Thinking is the prerequisite
skill for understanding the technologies of
the future.

§ Computational thinking is a thought process, rather


than a specific body of knowledge about a device
or language.
PROBLEM SOLVING PROCESS
§ Computational thinking is often associated with
computers and coding, but it is important to note
that it can be taught/learnt without a device.

§ It helps you to think in a way that will allow you


to access and understand the digital world
PROBLEM SOLVING PROCESS
§ There are four important qualities or features
(core components of computational thinking) on
which computational thinking depends on or is
based.

§ Decomposition

§ Pattern recognition

§ Abstraction

§ Algorithms
PROBLEM SOLVING PROCESS TOOLS & STRATEGIES
§ Decomposition : break down complex problems into
smaller, simpler problems.

§ Pattern recognition : make connections between


similar problems and experience

§ Abstraction : Present or focus on necessary details


on, leaving out the unnecessary ones.

§ Algorithms : Step by step descriptions of how to


carry out a certain task.
PROBLEM SOLVING STRATEGIES
§ Decomposition
§ Complex problems are broken down into several
problems that can be handled with relative ease

§ For example planning a birthday party, that


involves multiple steps. This type of task can
quickly become overwhelming without an
organized to-do list of smaller, more approachable
challenges
PROBLEM SOLVING STRATEGIES
§ Pattern recognition
§ To analyse similar objects or experiences and identify
commonalities or differences.

§ By finding what the objects or experiences have in common,


you begin to develop an understanding of trends and are
therefore able to make predictions.

§ Example investigating trees. What do all trees have in common?


What are the differences from one type to another? They all
have a trunk roots and branches. While there are many
differences between types of trees, these components are
present in all trees.
PROBLEM SOLVING STRATEGIES & TOOLS
§ Abstraction
§ Abstraction is focusing on the information that is
relevant and important. It involves separating core
information from extraneous details.

§ the conceptof abstraction with literature can be a


summary behind a novel that helps you to identify the
main idea and key details.
PROBLEM SOLVING STRATEGIES & TOOLS
§ Algorithms
§ Algorithmic thinking involves developing solutions to a
problem. Specifically, it creates sequential rules to follow in
order to solve a problem.

§ Example, making a sandwich. What should we do first?


Second? What if I put the cheese and lettuce on my sandwich
before I add the mayonnaise? Conversations about
sequence and order develop the foundations of algorithmic
thinking.
PROBLEM SOLVING PROCESS
§ Computer based problem solving is a
systematic process of:

§ Analysing

§ Designing

§ Implementing

§ using programming tools


PROBLEM SOLVING PROCESS : PHASES
1. Problem Analysis : understanding what the problem is
§ To help you better understand the problem, ask yourself:
§ What is/are the input(s) – data that is needed
§ What is/are the output(s) – data the is given as a
result of the processing or the communication done
signifying the completion of the task.

§ Collect enough information about the problem including


domain knowledge, special conditions or restrictions
with regards to the subject matter involving the problem

§ The product of this activity is the Problem specification


PROBLEM SOLVING PROCESS : PHASES
§ A problem specification also referred to as an input-output
specification outlines what input values are required to solve a
certain problem as well as the output to be expected upon
completion of the solution.
§ Examples:
Problem Specification: Calculation of average of two numbers
Input: number1(integer), number2 (integer)
Output: Average of number1 and number2 (floating-point)

Problem Specification: Solving quadratic equation


Input: A(floating point), B(floating-point), C(floating-point)
Output: X1(floating-point), X2 (floating-point) or
communication that the equation can not be solved
PROBLEM SOLVING PROCESS : PHASES
2. Program Design: This involves devising a plan (step by step) for
how you’ll solve the problem
§ During this phase you are required to specify step by step how the
input can lead to the expected output as indicated in a problem
specification.
§ Identify similar problems that you already know how to solve
§ This requires knowledge of the different types of instructions on can
work with in coming up with a solution to a computational problem

§ The product of this phase can be either of the following items:


§ Algorithm
§ Flowchart
§ Pseudocode
PROBLEM SOLVING PROCESS : PHASES
3. Implementation : Writing code (programming) that according
to the design from the previous phase
§ This in this phase there are a number of activities
involved including: Programming/Coding, Debugging
and Testing, Compilation and Execution

§ The product of this phase a computer program

4. Maintenance: The efforts of doing works on a computer


program that was ideally completed.
§ There are different types of maintenance including
corrective, preventive, perfective and adaptive
maintenance.
FLOWCHARTS, ALGORITHMS & PSEUDOCODE
§ Flowchart is basically a pictorial or diagrammatic
representation of a step by step process a computer
should follow to solve a problem.
§ It explains the sequence of operations to be
performed in order to solve a problem under
consideration.

§ To draw this diagram, standard symbols that


represent a certain logical step or instruction will be
utilised.
FLOWCHARTS, ALGORITHMS & PSEUDOCODE
§ Flowchart symbols are designed in such a way that
they help you to represent a certain type of logical
activity.

§ By logical activity we mean a certain type of


instruction that you can issue to a computer for it to:
§ perform a certain activity or action such as to
print something, calculate something or
making a certain choice amongst several
options.
FLOWCHARTS, ALGORITHMS &
PSEUDOCODE
§ These instructionsare categorized in what we call the
five main basic types of instructions that you can use to
write a computer program. These include:
§ Input instructions

§ Output instructions

§ Mathematical instructions

§ Decisional /Selection instructions

§ Looping/iterative/Repetitive instructions
FLOWCHARTS, ALGORITHMS & PSEUDOCODE
§ The previous instructions can be represented in a flow
chart using the stand symbols given below:
§ Output or Display

§ Input

§ Process or mathematical

§ Start/Begin or Stop/End

§ Decision/Selection (will be used for loops too)

§ Flow line
FLOWCHARTS, ALGORITHMS & PSEUDOCODE
§ Using flowcharts while solving any problem has
following advantages:
§ Effective Communication : Flowchartsare better way of
communicating the logic of the system/program.

§ Easy Debuggingand Efficient Testing : The Flowchart helps


in debugging and testing process.

§ Proper Documentation : Flowcharts


serves as a good
program documentation, which is needed for various
purpose.

§ Efficient
Program Maintenance : Maintenance of operating
programs becomes easy with the help of flowchart.
WHAT ARE ALGORITHMS?

§ An algorithm is a systematic (step by step)


process or method that is followed to solve
a well specified computational problem.

§ Algorithms provide a very good tool for


solving computation problems just like flow
charts diagrams.
WHAT ARE ALGORITHMS?
§ Usually we use “pseudo-code” to describe
algorithms

§ Algorithms can be implemented in any


programming language
PROPERTIES OF AN ALGORITHM
§ It must be correct.

§ It is composed of a series of concrete steps.

§ There can be no ambiguity as to which step will

be performed next.
§ It must be composed of a finite number of steps.

§ It must terminate.

§ must be general (in terms of data structures

used)
WHY ARE ALGORITHMS IMPORTANT?
§ At the foundation of most of the computing
problem are algorithms.

§ As earlier indicated, an algorithm is a design so


they play a major role in implementations of
simple and complex problems.

§ Algorithms are applied practically used in most


of the fields other than software development
APPLICATION OF ALGORITHMS IN THE REAL
WORLD
§ Computer Vision (image detection and video
analysis…. Etc)

§ Cryptography and information security (application in


e-commerce of technologies such RSA, AES, SSL,… etc.)

§ Web and internet (searching of content over the


internet)

§ Artificial Intelligence (AI) and Machine Learning (ML)


APPLICATION OF ALGORITHMS IN THE
REAL WORLD
§ Linear and integer programming (scheduling of
air crew, generation of fixture in sports leagues,
timetable making …etc.)

§ Mail delivery and trash collection ( determining


shortest path, efficient routes….etc.)
WRITING AN ALGORITHM
§ Example 1:
a. Draw a flowchart for a program that is able to
determine a student’s final grade and indicate
whether the student has passed or failed. The
final grade is calculated as the average of four
marks.

b. Convert your flowchart into an Algorithm

c. Convert your flowchart into Pseudocode


WRITING AN ALGORITHM

If …. else
Statement
WRITING AN ALGORITHM

§ Algorithm: If …. Else Statement


§ STEP 1: Request for the marks

§ STEP 2: Store the value provided in M

§ STEP 3: Calculate their average by adding the numbers of M and

dividing by number of Ms
§ STEP 4: If the average is greater or equal to 50 print “PASS”

§ STEP 5: Otherwise, If the average is Less or equal to 50 print “FAIL”


WRITING PSEUDOCODE
§ Pseudocode:
Input M1,M2,M3,M4
GRADE = (M1+M2+M3+M4)/4
if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
WRITING AN ALGORITHM

Without
Repeat
Statement
But If statement
only
WRITING AN ALGORITHM

§ Algorithm: Without Repeat (If statement only)


§ STEP 1: Request for the marks

§ STEP 2: Store the value provided in M

§ STEP 3: Calculate their average by adding the numbers of M and

dividing by number of Ms
§ STEP 4: If the average is greater or equal to 50 print “PASS”
WRITING PSEUDOCODE
§ Pseudocode:
Input M1,M2,M3,M4
GRADE = (M1+M2+M3+M4)/4
if (GRADE < 50) then
Print “FAIL”
endif
WRITING AN ALGORITHM

With Repeat
Statement
But, If statement
only
WRITING AN ALGORITHM

§ Algorithm: With Repeat


§ STEP 1: Request for the marks

§ STEP 2: Store the value provided in M

§ STEP 3: Calculate their average by adding the numbers of M and

dividing by number of Ms
§ STEP 4: If the average is greater or equal to 50 print “PASS”

§ STEP 5:Otherwise, repeat STEP 1


WRITING PSEUDOCODE
§ Pseudocode:
loop:
Request for marks
Store the value in M
Calculate average: sum(M) / number_of_Ms
if average >= 50 then
Print "PASS" and End
end if
end loop
Questions????

Subscribe to my YouTube Channel !!!


For more ICT lessons

Perlongs Computing

41

You might also like