KEMBAR78
2. Algorithms and Problem Solving in Java.pptx
Algorithms
&
Problem
Solving 1
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Learn about problem solving skills
Explore the algorithmic approach for problem
solving
Learn about algorithm development
Become aware of problem solving process
Objectives
2
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Programming is a process of problem solving.
Problem solving techniques involve:
Analyzing the problem.
Outlining the problem requirements.
Designing steps (algorithm) to solve the
problem
Algorithm:
Step-by-step problem-solving process with
solution achieved in finite amount of time.
A procedure for solving a problem in terms
of the actions to execute and the order in
which these actions execute. 3
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Problem Solving
A useful point of view concerning
computers and computer programs in
problem solving is:
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 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. 4
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Problem Solving
A computer cannot solve a problem on its
own. One has to provide step by step
solutions of the problem to the computer.
The task of problem solving is not that of
the computer. It is the programmer who
has to write down the solution to the
problem in terms of simple operations
which the computer can understand and
execute.
In order to solve a problem by the
computer, one has to pass though certain
stages or steps and this are:
5
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Problem Solving Process
1.Understanding the problem:
 Involves understanding the problem to be solved
in
totally.
 Before the next stage or step, one should be
absolutely
sure about the objectives of the given problem.
2.Analyzing the problem:
Involves at looking different ways of solving the
problem and evaluating each of them, after
understanding thoroughly the problem to be
solved.
The idea here is to search an appropriate solution
to the problem under consideration. The end
Problem Solving Process
6
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
3.Developing the solution:
 Here the overview of the sequence of
operations that was the result of analysis stage
is expanded to form a detailed step by step
solution to the problem under consideration.
4. Coding and Implementation:
 The last stage of the problem solving is the
conversion of the detailed sequence of operations
in to a language that the computer can
understand.
 Each step is converted to its equivalent
instruction or instructions in the computer
language that has been chosen for the
implementation.
Problem Solving Process
7
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
The idea behind the computer program.
Stays the same independent of:
Which kind of hardware it is running on
Which programming language it is written in
Solves a well-specified problem in a general
way.
Is specified by:
Describing the set of instances (input) it
must work on.
Describing the desired properties of the
output.
8
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
What ’s in an
Algorithm?
 Before a computer can perform a task, it
must have an algorithm that tells it what
to do.
Informally: “An algorithm is a set of
steps that
define how a task is performed.”
Formally: “An algorithm is an ordered
set of unambiguous executable steps,
defining a terminating process.”
 Ordered set of steps: structure!
Executable steps: doable!
Unambiguous steps: follow the
directions! 9
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
What ’s in an
Algorithm?
 Correct: Always returns the desired output
for all legal instances of the problem.
 Unambiguous: Not open to more than one
presentation.
 Precise: Marked by exactness and
accuracy of expression or detail.
 Efficient: Achieving maximum productivity
with minimum wasted effort or expense. Can
be measured in terms of time and space. Time
tends to be more important.
10
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Properties of Algorithms
Finiteness: An algorithm must terminate in a
finite
number of steps.
Effectiveness: Each step must be effective, in
the sense that it should be primitive easily
convert able into program statement) can be
performed exactly in a finite amount of time.
Generality: The algorithm must be
complete in itself so that it can be used to
solve problems of a specific type for any
input data.
Input/output: Each algorithm must take zero,
one or more quantities as input data produce
11
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Properties of Algorithms
Every problem solution starts with a plan.
That plan is called an algorithm.
 The development of an algorithm (a plan)
is a key
step in solving a problem.
 Once we have an algorithm, we can translate
it into a computer program in some
programming language.
 Algorithm development process consists
of five major steps:
Algorithm Development Process
12
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Step 1: Obtain a description of the problem.
 This step starts with the developer
(someone who finds a way to solve the
problem) creating an algorithm that will
solve the client's problem.
 The client (someone who wants to find a
solution to a problem) is responsible for
creating a description of the problem.
During problem description, its common to
find one or more of the following types of
defects:
 The description relies on unstated
assumptions,
Algorithm Development Process
13
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
During problem description, its common to
find one or more of the following types of
defects:
 The description relies on unstated
assumptions,
 The description is ambiguous,
 The description is incomplete, or
 The description has internal contradictions.
 These defects are seldom due to carelessness
by the client but it’s developer's responsibility
to identify defects in the description of a
problem, and to work with the client to
remedy those defects.
Algorithm Development Process
14
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Step 2: Analyze the problem.
 The purpose of this step is to determine both
the starting and ending points for solving the
problem.
When determining the starting point, we
should
start by seeking answers to the following
questions:
What data are available?
Where is that data?
What formulas pertain to the problem?
What rules exist for working with the data?
Algorithm Development Process
15
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
When determining the ending point, we need
to describe the characteristics of a solution. In
other words, how will we know when we're
done? Asking the following questions often
helps to determine the ending point:
What new facts will we have?
What items will have changed?
What changes will have been made to
those items?
What things will no longer exist?
Algorithm Development Process
16
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Algorithm Development Process
Step 3: Develop a high-level algorithm.
 An algorithm is a plan for solving a
problem, but
plans come in several levels of detail.
It's usually better to start with a high-
level algorithm that includes the
major part of a solution, but leaves the
details until later.
An everyday example to demonstrate a
high-level algorithm would be:
 Problem: I need a send a birthday card to my
brother, Mark.
 Analysis: I don't have a card. I prefer to buy
30
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Algorithm Development Process
 High-level algorithm:
Go to a store that sells greeting
cards Select a card
Purchase a
card Mail the
card
 This algorithm is satisfactory for daily use,
but it lacks details that would have to be
added if it were
for a computer to carry out the solution.
These details include answers to
questions such as:
 "Which store will I visit?"
 "How will I get there; walk, take a bus, 18
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Step 4: Refine the algorithm by adding
more detail.
A high-level algorithm shows the major
steps that
need to be followed to solve a problem.
 Our goal is to develop algorithms that will lead
to computer programs, we need to consider the
capabilities of the computer and provide
enough detail so that someone else could use
your algorithm to write a computer program
that follows the steps in your algorithm.
Algorithm Development Process
19
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
In every problem, we adjust the level of detail
to
match the ability of the programmer.
Most of our programs will move from a high-
level to a detailed algorithm in a single step,
but this is not always reasonable. For larger,
more complex problems, it is common to go
through this process several times, developing
intermediate level algorithms as we go.
 This technique of gradually working from a
high- level to a detailed algorithm is often
called stepwise refinement, which is the
process for developing a detailed algorithm by
gradually adding detail to a high-level
Algorithm Development Process
20
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Step 5: Review the algorithm.
Involves working through the algorithm step by
step to determine whether or not it will solve
the problem.
 The following questions can be asked whenever
we
review an algorithm:
 Does this algorithm solve a very specific
problem or does it solve a more general
problem? If it solves a very specific problem,
should it be generalized?
 For example, an algorithm that computes the
area of a circle having radius 5.2 meters (formula
π*5.22) solves a very specific problem, but an
Algorithm Development Process
21
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Algorithm Development Process
Can this algorithm be simplified?
One formula for computing the perimeter of a
rectangle is:
length + width + length + width
A simpler formula would be:
2.0 * (length + width)
22
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Algorithm Development Process
Is this solution similar to the solution of
another problem? How are they alike? How
are they different?
For example, consider the following two
formulae:
Rectangle area = length * width
Triangle area = 0.5 * base * height
Similarities: Each computes an area.
Each multiplies two measurements.
Differences: Different measurements are
used. The triangle formula contains 0.5.
Hypothesis: Perhaps every area formula
involves multiplying two measurements.
23
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
A single algorithm can be represented in
many ways:
Formulas: F = (9/5)C + 32
Words: Multiply the Celsius by 9/5 and add
32.
Flow Charts.
Pseudo-code – is an informal language that
helps programmers develop algorithms.
In each case, the algorithm stays the same;
the implementation differs!
Representation of Algorithms
24
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
A flow chart is a step by step diagrammatic
representation of the logic paths to solve a
given problem.
 Or a visual or graphical representation of
an
algorithm.
 The flowcharts are pictorial representation of
the methods to be used to solve a given
problem and help a great deal to analyze the
problem and plan its solution in a systematic
and orderly manner.
A flowchart when translated in to a proper
computer
Flow Charts
25
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
1. The flowchart shows the logic of a
problem displayed in pictorial fashion
which felicitates easier checking of an
algorithm.
2. The Flowchart is a good means of
communication to other users. It is also a
compact means of recording an algorithm
solution to a problem.
3. The flowchart allows the problem solver to
break the problem into parts. These parts
can be connected to make a master chart.
4. The flowchart is a permanent record of the
solution
Advantages of Flow Charts
26
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
 The following symbols are used when
drawing flowcharts as per conventions
followed by International Standard
Organization (ISO).
1. Oval: Rectangle with rounded sides is
used to
indicate either START/STOP of the
program.
2. Input and output indicators:
Parallelograms are used to represent input
and output operations. Statements like
INPUT, READ and PRINT are represented in
Flow Charts Symbols
27
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
3. Process Indicators: Rectangle is used to
indicate any set of processing operation such
as for storing arithmetic operations.
4. Decision Makers: The diamond is used for
indicating the step of decision making and
therefore known as decision box. Decision
boxes are used to test the conditions or ask
questions and depending upon the answers,
the appropriate actions are taken by the
computer.
Flow Charts Symbols
28
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
5. Flow Lines: Flow lines indicate the direction
being followed in the flowchart. Every line
must have an arrow on it to indicate the
direction.
6. On- Page connectors: Circles are used to join
the different parts of a flowchart. In a
complicated problems, a flowchart may run
in to several pages. The parts of the flowchart
on different pages are to be joined with each
other. The parts to be joined are indicated by
the circle.
Flow Charts Symbols
20
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
7. Off-page connectors: This connector
represents a break in the path of flowchart
which is too large to fit on a single page. It is
similar to on-page connector. The connector
symbol marks where the algorithm ends on
the first page and where it continues on the
second.
Flow Charts Symbols
30
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Draw a flowchart for adding the integers from
1 to 50
and print the sum.
Start
sum = 0
n = 1
is n>50?
No
Flow Charts - Example
sum =
sum+n
n = n+1
Prin
t
Su
m
Sto
p
31
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Pseudocode is like a programming language
but its rules are less stringent.
Written as a combination of English and
programming constructs.
Based on selection (if, switch) and
iteration (while, repeat) constructs in
high-level programming languages.
Pseudocode does not execute on computers.
Rather, it helps the programmer "think out" a
program before attempting to write it in a
programming language but designed using
these high level language primitives.
Pseudocode
32
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Example: The sequential search
algorithm in pseudocode
Pseudocode
33
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Example Algorithm
Suppose we want to find the average of three
numbers, the algorithm (pseudo code) is as
follows:
Step 1: Start
Step 2: Get the first number (e.g. 32)
Step 2: Get the second number (e.g. 27)
Step 3: Get the third number (e.g. 100)
Step 4: Add the three numbers together to
calculate the total (e.g. 159)
Step 5: Divide the total by 3 to calculate the
average (e.g. 53)
Step 6: Print the average of the three numbers.
Step 7: Stop
34
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Example Algorithm
The flow chart to find the average of three
numbers, will be as follows:
35
9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
Problem-Solving Execution Cycle
TUESDAY, SEPTEMBER 22,
2015
Computer
By: Ambrose Njeru [BSc,
Msc 3

2. Algorithms and Problem Solving in Java.pptx

  • 1.
    Algorithms & Problem Solving 1 9/11/2018 BY:AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 2.
    Learn about problemsolving skills Explore the algorithmic approach for problem solving Learn about algorithm development Become aware of problem solving process Objectives 2 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 3.
    Programming is aprocess of problem solving. Problem solving techniques involve: Analyzing the problem. Outlining the problem requirements. Designing steps (algorithm) to solve the problem Algorithm: Step-by-step problem-solving process with solution achieved in finite amount of time. A procedure for solving a problem in terms of the actions to execute and the order in which these actions execute. 3 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE Problem Solving
  • 4.
    A useful pointof view concerning computers and computer programs in problem solving is: 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 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. 4 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE Problem Solving
  • 5.
    A computer cannotsolve a problem on its own. One has to provide step by step solutions of the problem to the computer. The task of problem solving is not that of the computer. It is the programmer who has to write down the solution to the problem in terms of simple operations which the computer can understand and execute. In order to solve a problem by the computer, one has to pass though certain stages or steps and this are: 5 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE Problem Solving Process
  • 6.
    1.Understanding the problem: Involves understanding the problem to be solved in totally.  Before the next stage or step, one should be absolutely sure about the objectives of the given problem. 2.Analyzing the problem: Involves at looking different ways of solving the problem and evaluating each of them, after understanding thoroughly the problem to be solved. The idea here is to search an appropriate solution to the problem under consideration. The end Problem Solving Process 6 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 7.
    3.Developing the solution: Here the overview of the sequence of operations that was the result of analysis stage is expanded to form a detailed step by step solution to the problem under consideration. 4. Coding and Implementation:  The last stage of the problem solving is the conversion of the detailed sequence of operations in to a language that the computer can understand.  Each step is converted to its equivalent instruction or instructions in the computer language that has been chosen for the implementation. Problem Solving Process 7 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 8.
    The idea behindthe computer program. Stays the same independent of: Which kind of hardware it is running on Which programming language it is written in Solves a well-specified problem in a general way. Is specified by: Describing the set of instances (input) it must work on. Describing the desired properties of the output. 8 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE What ’s in an Algorithm?
  • 9.
     Before acomputer can perform a task, it must have an algorithm that tells it what to do. Informally: “An algorithm is a set of steps that define how a task is performed.” Formally: “An algorithm is an ordered set of unambiguous executable steps, defining a terminating process.”  Ordered set of steps: structure! Executable steps: doable! Unambiguous steps: follow the directions! 9 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE What ’s in an Algorithm?
  • 10.
     Correct: Alwaysreturns the desired output for all legal instances of the problem.  Unambiguous: Not open to more than one presentation.  Precise: Marked by exactness and accuracy of expression or detail.  Efficient: Achieving maximum productivity with minimum wasted effort or expense. Can be measured in terms of time and space. Time tends to be more important. 10 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE Properties of Algorithms
  • 11.
    Finiteness: An algorithmmust terminate in a finite number of steps. Effectiveness: Each step must be effective, in the sense that it should be primitive easily convert able into program statement) can be performed exactly in a finite amount of time. Generality: The algorithm must be complete in itself so that it can be used to solve problems of a specific type for any input data. Input/output: Each algorithm must take zero, one or more quantities as input data produce 11 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE Properties of Algorithms
  • 12.
    Every problem solutionstarts with a plan. That plan is called an algorithm.  The development of an algorithm (a plan) is a key step in solving a problem.  Once we have an algorithm, we can translate it into a computer program in some programming language.  Algorithm development process consists of five major steps: Algorithm Development Process 12 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 13.
    Step 1: Obtaina description of the problem.  This step starts with the developer (someone who finds a way to solve the problem) creating an algorithm that will solve the client's problem.  The client (someone who wants to find a solution to a problem) is responsible for creating a description of the problem. During problem description, its common to find one or more of the following types of defects:  The description relies on unstated assumptions, Algorithm Development Process 13 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 14.
    During problem description,its common to find one or more of the following types of defects:  The description relies on unstated assumptions,  The description is ambiguous,  The description is incomplete, or  The description has internal contradictions.  These defects are seldom due to carelessness by the client but it’s developer's responsibility to identify defects in the description of a problem, and to work with the client to remedy those defects. Algorithm Development Process 14 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 15.
    Step 2: Analyzethe problem.  The purpose of this step is to determine both the starting and ending points for solving the problem. When determining the starting point, we should start by seeking answers to the following questions: What data are available? Where is that data? What formulas pertain to the problem? What rules exist for working with the data? Algorithm Development Process 15 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 16.
    When determining theending point, we need to describe the characteristics of a solution. In other words, how will we know when we're done? Asking the following questions often helps to determine the ending point: What new facts will we have? What items will have changed? What changes will have been made to those items? What things will no longer exist? Algorithm Development Process 16 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 17.
    Algorithm Development Process Step3: Develop a high-level algorithm.  An algorithm is a plan for solving a problem, but plans come in several levels of detail. It's usually better to start with a high- level algorithm that includes the major part of a solution, but leaves the details until later. An everyday example to demonstrate a high-level algorithm would be:  Problem: I need a send a birthday card to my brother, Mark.  Analysis: I don't have a card. I prefer to buy 30 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 18.
    Algorithm Development Process High-level algorithm: Go to a store that sells greeting cards Select a card Purchase a card Mail the card  This algorithm is satisfactory for daily use, but it lacks details that would have to be added if it were for a computer to carry out the solution. These details include answers to questions such as:  "Which store will I visit?"  "How will I get there; walk, take a bus, 18 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 19.
    Step 4: Refinethe algorithm by adding more detail. A high-level algorithm shows the major steps that need to be followed to solve a problem.  Our goal is to develop algorithms that will lead to computer programs, we need to consider the capabilities of the computer and provide enough detail so that someone else could use your algorithm to write a computer program that follows the steps in your algorithm. Algorithm Development Process 19 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 20.
    In every problem,we adjust the level of detail to match the ability of the programmer. Most of our programs will move from a high- level to a detailed algorithm in a single step, but this is not always reasonable. For larger, more complex problems, it is common to go through this process several times, developing intermediate level algorithms as we go.  This technique of gradually working from a high- level to a detailed algorithm is often called stepwise refinement, which is the process for developing a detailed algorithm by gradually adding detail to a high-level Algorithm Development Process 20 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 21.
    Step 5: Reviewthe algorithm. Involves working through the algorithm step by step to determine whether or not it will solve the problem.  The following questions can be asked whenever we review an algorithm:  Does this algorithm solve a very specific problem or does it solve a more general problem? If it solves a very specific problem, should it be generalized?  For example, an algorithm that computes the area of a circle having radius 5.2 meters (formula π*5.22) solves a very specific problem, but an Algorithm Development Process 21 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 22.
    Algorithm Development Process Canthis algorithm be simplified? One formula for computing the perimeter of a rectangle is: length + width + length + width A simpler formula would be: 2.0 * (length + width) 22 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 23.
    Algorithm Development Process Isthis solution similar to the solution of another problem? How are they alike? How are they different? For example, consider the following two formulae: Rectangle area = length * width Triangle area = 0.5 * base * height Similarities: Each computes an area. Each multiplies two measurements. Differences: Different measurements are used. The triangle formula contains 0.5. Hypothesis: Perhaps every area formula involves multiplying two measurements. 23 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 24.
    A single algorithmcan be represented in many ways: Formulas: F = (9/5)C + 32 Words: Multiply the Celsius by 9/5 and add 32. Flow Charts. Pseudo-code – is an informal language that helps programmers develop algorithms. In each case, the algorithm stays the same; the implementation differs! Representation of Algorithms 24 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 25.
    A flow chartis a step by step diagrammatic representation of the logic paths to solve a given problem.  Or a visual or graphical representation of an algorithm.  The flowcharts are pictorial representation of the methods to be used to solve a given problem and help a great deal to analyze the problem and plan its solution in a systematic and orderly manner. A flowchart when translated in to a proper computer Flow Charts 25 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 26.
    1. The flowchartshows the logic of a problem displayed in pictorial fashion which felicitates easier checking of an algorithm. 2. The Flowchart is a good means of communication to other users. It is also a compact means of recording an algorithm solution to a problem. 3. The flowchart allows the problem solver to break the problem into parts. These parts can be connected to make a master chart. 4. The flowchart is a permanent record of the solution Advantages of Flow Charts 26 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 27.
     The followingsymbols are used when drawing flowcharts as per conventions followed by International Standard Organization (ISO). 1. Oval: Rectangle with rounded sides is used to indicate either START/STOP of the program. 2. Input and output indicators: Parallelograms are used to represent input and output operations. Statements like INPUT, READ and PRINT are represented in Flow Charts Symbols 27 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 28.
    3. Process Indicators:Rectangle is used to indicate any set of processing operation such as for storing arithmetic operations. 4. Decision Makers: The diamond is used for indicating the step of decision making and therefore known as decision box. Decision boxes are used to test the conditions or ask questions and depending upon the answers, the appropriate actions are taken by the computer. Flow Charts Symbols 28 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 29.
    5. Flow Lines:Flow lines indicate the direction being followed in the flowchart. Every line must have an arrow on it to indicate the direction. 6. On- Page connectors: Circles are used to join the different parts of a flowchart. In a complicated problems, a flowchart may run in to several pages. The parts of the flowchart on different pages are to be joined with each other. The parts to be joined are indicated by the circle. Flow Charts Symbols 20 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 30.
    7. Off-page connectors:This connector represents a break in the path of flowchart which is too large to fit on a single page. It is similar to on-page connector. The connector symbol marks where the algorithm ends on the first page and where it continues on the second. Flow Charts Symbols 30 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 31.
    Draw a flowchartfor adding the integers from 1 to 50 and print the sum. Start sum = 0 n = 1 is n>50? No Flow Charts - Example sum = sum+n n = n+1 Prin t Su m Sto p 31 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 32.
    Pseudocode is likea programming language but its rules are less stringent. Written as a combination of English and programming constructs. Based on selection (if, switch) and iteration (while, repeat) constructs in high-level programming languages. Pseudocode does not execute on computers. Rather, it helps the programmer "think out" a program before attempting to write it in a programming language but designed using these high level language primitives. Pseudocode 32 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 33.
    Example: The sequentialsearch algorithm in pseudocode Pseudocode 33 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 34.
    Example Algorithm Suppose wewant to find the average of three numbers, the algorithm (pseudo code) is as follows: Step 1: Start Step 2: Get the first number (e.g. 32) Step 2: Get the second number (e.g. 27) Step 3: Get the third number (e.g. 100) Step 4: Add the three numbers together to calculate the total (e.g. 159) Step 5: Divide the total by 3 to calculate the average (e.g. 53) Step 6: Print the average of the three numbers. Step 7: Stop 34 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 35.
    Example Algorithm The flowchart to find the average of three numbers, will be as follows: 35 9/11/2018 BY: AMBROSE NJERU [BSC, MSC COMPUTER SCIENCE
  • 36.
    Problem-Solving Execution Cycle TUESDAY,SEPTEMBER 22, 2015 Computer By: Ambrose Njeru [BSc, Msc 3