1 - Lectures Note Week2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

CSC120: Computer as a Problem-Solving

Tool
Topic 1:
Concept of Problem Solving
Lecture 1 Week2:
Lecturer
Dr. Ufuoma C. Ogude

Department of Computer Sciences


University of Lagos
1
Outlines of the Course Wk2-
7
 Concept of Problem solving
 Introduction to programming
 Concept & properties of Algorithm
 Fundamentals of programming (1): variable/variable naming
convention/data types in Python
 Fundamentals of programming (2): operators and expressions
 Fundamentals of programming (3): control structures

2
Concept of Problem Solving
 Classes of problem
 Problem Solving Tools
 Debugging Strategies

3
Ask Questions...
…to understand the problem
 What do I know about the problem?
 What is the information that I have to process
in order the find the solution?
 What does the solution look like?
 What sort of special cases exist?
 How will I recognize that I have found
the solution?

4
Problem Solving
 Problem solving The act of finding a solution to a
perplexing, distressing, vexing, or unsettled question
 Computers can solve problems by performing billions of
operations per second.
A programmer's job is to find solutions. They do this by
breaking down problems into easy-to-follow steps for
a computer

5
Concept of Problem Solving
 Problem solving is the act of
• defining a problem;
• determining the cause of the problem;
• identifying, prioritizing (ranking, ordering),
and selecting alternatives for a solution;
• and implementing a solution.

6
Problem Solving Tools
 Problem-solving is the process of transforming the description
of a problem into a solution by using our knowledge of the
problem domain and by relying on our ability to select and use
appropriate problem-solving strategies, techniques and tools.
 Programming is a problem solving activity. When we write a
program, we are actually writing an instruction for the
computer to solve something for us.
 Using a computer as a problem solving tool following steps are
involved.

7
Problems, Solutions, and Tools
 The following basic process is important because it can be used
to solve a wide variety of problems, including ones where the
solution will be written in some other programming language.
 A computer is a tool that can be used to implement a plan for
solving a problem.
 A computer program is a set of instructions for a computer.
These instructions describe the steps that that the computer
must follow to implement a plan.
 An algorithm is a plan for solving a problem.
 A person must design an algorithm.
 A person must translate an algorithm into a computer
program. 8
Problem Solving Process

9
Problem Solving Process
 Problem-Solving Process
Step 1: Identify the Problem

Step 2: Analyze the Problem

Step 3: Develop the Solutions

Step 4: Implement a Solution.

Step 5: Evaluate The Results.

Step 6: Standardize The Solution (and Capitalize on New

Opportunities)
10
Design of Algorithms
A person must translate an algorithm into a computer
program.

11
Debugging
 Debugging in problem solving
 Debugging is the process of fixing a bug in the software.
It refers to identifying, analyzing and removing errors.
This activity begins after the software fails to execute
properly and concludes by solving the problem and
successfully testing the software.
 Debugging is the process of finding and resolving bugs
(defects or problems that prevent correct operation)
within computer programs, software, or systems.

12
Debugging and Testing
 Debugging and Testing
Testing and debugging go together:
 Testing finds errors; debugging localizes and repairs them.
 Together these form the “testing/debugging cycle”: we test,
then debug, then repeat.
 Any debugging should be followed by a reapplication of all
relevant tests, particularly regression tests. This avoids
(reduces) the introduction of new bugs when debugging.
 Testing and debugging need not be done by the same people
(and often should not be).

13
Debugging Process
 Reproduce the problem.

 Describe the bug. Try to get as much input from the user

to get the exact reason.

 Capture the program snapshot when the bug appears. ...

 Analyse the snapshot based on the state and action. ...

 Fix the existing bug, but also check that any new bug does

not occur
14
Errors in Debugging
 A written program may have errors, some errors can be detected
by the language compilers and some errors cannot be identified by
the compiler and occured during the program run. Common types of
errors are
 Syntax Errors: Identified by compiler at the program
compilation time.
 Logical Errors: Not identified by the compiler at compile time
and identified at the execution time. e.g. misuse of operators
 So testing is the process of checking the program for its correct
functionality by executing the program with some input data set
and observing the output of the program.
15
Why Debugging is Hard
 There may be no obvious relationship between the external
manifestation(s) of an error and its internal cause(s).
 Symptom and cause may be in remote parts of the program.
 Changes (new features, bug fixes) in program may mask (or
modify) bugs.
 Symptom may be due to human mistake or misunderstanding
that is difficult to trace.
 Bug may be triggered by rare or difficult to reproduce input
sequence, program timing (threads) or other external causes.
 Bug may depend on other software/system state, things others
did to you systems weeks/months ago. 16
Assignment
 Explain with a detailed example
the Classes of problem.

17
Computer Problem-Solving Process

1. Understand the
Problem
2. Formulate a Model
3. Develop an Algorithm
4. Write the Program
5. Test the Program
6. Evaluate the Solution 18
Computer Problem-Solving: Example
Example: Calculate the average grade for all
students in a class.
1. 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.
2. Process: add them all up and compute the
average grade.
3. 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.

19
PS Step 1: Understand Problem
 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 ?
20
PS Step 2: Formulate a Model
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 100.

21
PS Step 3: Develop an Algorithm
 it is time to
come up with a
precise plan of
what we want
the computer to
do.
 An algorithm is a
precise sequence
of instructions
for solving a
problem.
 Easy here!
22
PS Step 4: Write the Program

23
PS Step 5: Test the Program

24
PS Step 6: Evaluate Solution

25

You might also like