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

Introduction to Programming

Algorithm Development with Flowchart


ALGORITHM DEVELOPMENT PHASE
 Simply put, an algorithm is a set of instructions that describe
a method or a plan for solving a problem.

 An algorithm is a set of instructions for solving a problem or


sub problem in a finite amount of time using a finite amount
of data.

 These set of instructions must be unambiguous. This means


we aim to make what is ambiguous i.e. implicit in human
solution unambiguous i.e. explicit.

 Example of an ambiguous statement is: “stay away from the


bank”, the bank have different meanings e.g. bank of river, or
bank where money is kept, thus the statement “stay away
from bank” is ambiguous and such instruction should be
made explicit enough so that the computer can execute it.
Algorithm
Algorithm:
 a precisely specified procedure for
solving a problem or
a step-by-step method to solve a
problem or complete a task
Important Properties of Algorithms

 A good algorithm must be:


 Correct
 always returns the desired output for all legal instances of the
problem.
 Unambiguous
 Precise
 Efficient
 Can be measured in terms of
 Time
 Space
 Time tends to be more important i.e. tradeoff
Algorithm contd
 A good algorithm should have the following attributes:
 Definiteness; it should be well defined, that is every
steps should be definite
 Finiteness; it should terminate after finite number of
times
 Input; it may or may not have inputs
 Output; it must produce some result
 Efficiency ; an efficient algorithm should execute
faster, and take less memory space
CORRECTNESS OF ALGORITHM (start 02/06)

Goal of solving a mathematical problem is to produce an


answer to a problem, thus if the answer is correct
then the process or steps are correct. On the contrary
the goal of a computer problem solving is process
correctness.
This means if a process produces a correct result on a
certain data set, other data set will be used on the
same process in order to validate and test that the
process is correct.
Algorithm

 In writing algorithm we make use of symbols and action


keywords.
Algorithmic Symbols
 Symbol used in algorithm
= Equal to
# Not equal to
> Greater than
< Less than
 >= greater than or equal to
 <= Less than or equal to
 ↑ or ^ exponentiation
Algorithmic Action words
 Common Action Keywords
 Several keywords are often used to indicate
common input, output, and processing
operations in algorithm
 Input: READ,OBTAIN, GET, INPUT
 Output: PRINT, DISPLAY, SHOW, PUT
 Compute: COMPUTE, CALCULATE,
DETERMINE
 Initialise: SET, INIT
Algorithm Contd.

 Aim of programming methodology is:


 To develop a good algorithm programming methodology must be
followed.
Discussion

 Why do we study or write algorithm?


Programming Methodology
 Programming methodology is an organized, documented set of procedures and guidelines for
one or more phases of the software life cycle. such as analysis or design.

 Programming methodology is about good software engineering principles.

 This are the principles to understand in order to develop a good software system.

 Thus we have programming methodology which deals with how an algorithm is developed.

 In this course we want to learn programming language in line with program methodologies
that make you a good programmer.
Types of Programming Methodology

 We have two types of programming methodologies,


they are:
1. Top down design
2. Object oriented design (OOD)
 Top-down approach uses divide and conquer technique
where the problem is broken down into sub problems, such
that each sub problems or modules can be solved (i.e.
conquered) independently of the other. This methodology is
used by procedural languages like C. Each sub-problem forms
a procedure.
 An object oriented design is used majorly by object oriented
programming languages like Java, and C++. This breaks
problems down into objects.
PROGRAMMING METHODOLOGY
 Each of these methodologies can be expressed in any of these
forms:

 Diagramming notation for documenting the results of the


procedure (flowchart, UML design etc);

 step-by-step “cookbook” approach for carrying out the


procedure (pseudo code);

 and an objective set of criteria for determining whether the


results of the procedure are of acceptable quality e.g.
computational cost, time and space complexity etc.
Developing an algorithm
 As said earlier an
algorithm can be
represented as either a
flowchart or a pseudo
code.
Flowchart
Flowchart
A flow chart is a pictorial
representation of an algorithm in
which symbols are used to show the
various operations and decisions to be
followed in solving a problem.
In summary steps that must be
followed.
Flowchart Symbols
Flowchart symbol Explanation
Terminal symbol; indicate start/stop/End

Parallelogram indicate input to and output


From computer memory. An input/output block has one entrance and only one
exit

Rectangle indicate Processing : define the calculation require (e.g. computation


of tax, gross pay, etc in above example)

The diamond indicates a decision. It has one entrance and two and only two
exits. One exit is the action when the resultants is True and the other exit is the
action when the resultant is False

Connector : this is used for the purpose of junction. Some rimes the flow chart
can’t be completed on a single page and it require 2 or more pages, these
connector symbols is used.

flow lines ; used to connect the various


symbols. It define the logic of the
algorithm

Rectangle with lines down each side indicates the process of modules. They have
one entrance and only one exit.
This is called predefined process..
Flowchart
 This flowchart shows the
steps that may be taken in Start
solving the lamp problem.

End
Flowchart Steps

 Start from the first stage of problem solving process


 Draw the start symbol
 Draw the input symbol and indicates if the inputs (this step is optional)----
input is based on the identified input in problem solving process
 Based on processing requirement you may need the following symbols:
 Processing symbol for computation
 Decision symbol for making decisions

 Remember to use the arrows to show direction of flow of the steps


 The output will be the expected result
 Indicate the end symbol and use the necessary arrows to show how each
symbol moves to the end.
Group Work
 Design a flowchart for the followings:
 admission process
 hall registration process
 student registration process
 daily activities of Babcock student
Lab II
 Draw the flowchart for examples 1 and 2.
 The volume of a cylinder is given by
 V = π r2 h
 Write the pseudo code and draw the flowchart

 The area of a circle is given by the formula


Area = πr2
write the pseudo code and draw the flowchart.
Lab II Assignment
 Following the problem solving process find the sum,
product, difference, and quotient of any two numbers.

 Design the flowchart


Self Assessment

 Why do we study programming methodology?


 What is the relationship between programming methodology and
algorithm development?
Assignment

 Draw a flowchart to authenticate student before having access to


Babcock webpage.
 Draw a flowchart to add any two numbers
 Draw a flowchart to add any two numbers while each number must not
be greater than 10.
 Draw a flowchart to detect whether a number is even or odd.
QUIZ 18/9

 What is an algorithm?
 Specify the type of data to use the followings algorithm keywords for
 INPUT
 INIT
 SET

You might also like