BIT 2104
Introduction to Programming and
Algorithms
LECTURE 2
Introduction to Computer Algorithms
9 February 2021 Introduction to Computer Algorithms 1
CONTENT
• Overview of computer algorithms
• Problem Solving with Computers
• Introduction to Algorithm
• Flow Charts
• Pseudo Code
9 February 2021 Introduction to Computer Algorithms 2
1. Overview of Computer
Programming and Algorithms
• What is Computer Programming Methodology?
• A Methodology is a system of methods with its
orderly and integrated collection of various
methods, tools and notations.
• A computer program is a series of instructions
written in the language of the computer which
specifies processing operations that the
computer is to carry out on data.
• It is a coded list of instructions that tell a
computer how to perform a set of calculations or
operations.
9 February 2021 Introduction to Computer Algorithms 3
Overview of Computer Programming
and Algorithms
• Programming is the process of producing a
computer program.
• Programming involves the following activities;
writing a program, compiling the program,
running the program, and debugging the
programs.
• The whole process is repeated until the
program is finished.
9 February 2021 Introduction to Computer Algorithms 4
2. Problem Solving with Computers
• There are a number of concepts of relevance to
problem solving using computers.
• Two particular concepts includes computability
and complexity.
• A problem is said to be computable if it can in
principle be performed by a machine.
• Some mathematical functions are not
computable.
• The complexity of a problem is measured in
terms of resources required, time and storage
9 February 2021 Introduction to Computer Algorithms 5
Problem Solving with Computers
• There are 6 steps involved in solving a
problem using a computer program:
1) Defining a Problem
2) Devising an Algorithm
3) Coding the Program
4) Debugging the Program
5) Running the Program
6) Analyzing the results
9 February 2021 Introduction to Computer Algorithms 6
Defining a Problem
• Step 1
• Define the Problem
• To state in the clearest possible terms the
problem one wish to solve.
• It is impossible to write a computer program
to solve a problem that has been ambiguously
or imprecisely stated
9 February 2021 Introduction to Computer Algorithms 7
Devising an Algorithm
• Step 2
• An algorithm is a step-by-step procedure for
solving the problem.
• Each of the steps must be a simple operation
which the computer is capable of doing.
• A universally-used representation of an algorithm
is a flowchart or flow diagram, in which boxes
representing procedural steps are connected by
arrows indicating the proper sequence of the
steps.
9 February 2021 Introduction to Computer Algorithms 8
Devising an Algorithm
• Step 2
• In many problems you will need to define a
mathematical procedure, expressed in strictly
numerical terms
• Since the use of computers to do higher level
analytic processes such as solving algebraic
equations or doing integrals in a non-numerical
fashion is relatively limited.
• The Algorithm can also be represented using
Pseudo-code
9 February 2021 Introduction to Computer Algorithms 9
Coding the Program
• Step 3
• Code the Program
• The steps in an algorithm, translated into a
series of instructions to the computer,
comprise the computer program.
• There are many languages in which
computer programs can be coded, each with
its own syntax, vocabulary, and special
features.
9 February 2021 Introduction to Computer Algorithms 10
Debugging the Program
• Step 4
• Most programs of any length don't work
properly the first time they are run and must
therefore be debugged.
• Often, after developing a program, errors and
ambiguities in the original statement of the
problem reveal themselves, calling for basic
revisions in the solution algorithm.
• This process in called debugging
9 February 2021 Introduction to Computer Algorithms 11
Running the Program
• Step 5
• Run the Program
• After the program has been fully debugged
one can run it, possibly using many sets of
input data.
• This step may take anywhere from a few
seconds to many hours depending on the
complexity of the problem and the speed of
the computer.
9 February 2021 Introduction to Computer Algorithms 12
Analyzing the Results
• Step 6
• Often the output from a computer program
requires considerable further analysis.
• In some cases, even though the program
worked perfectly, one may find that had
solved the “wrong" problem.
• There is an acronym well known to computer
users: GIGO, which stands for “garbage in,
garbage out."
9 February 2021 Introduction to Computer Algorithms 13
3. Introduction to Algorithms
• An Algorithm is a logical sequence of discrete
steps that describe a complete solution to a
given problem in a finite amount of time
independently of the software or hardware of
the computer.
• It is the set of rules that define how a
particular problem can be solved in finite
number of steps.
9 February 2021 Introduction to Computer Algorithms 14
Introduction to Algorithm
• Algorithms are very essential as they instructs
the computer what specific steps it needs to
perform to carry out a particular task or solve
a problem.
• Every algorithm should have the following five
characteristics: Input, Output, Definiteness,
Effectiveness and Termination.
9 February 2021 Introduction to Computer Algorithms 15
Introduction to Algorithms
• An Algorithm has the following properties:
• It must be precise and unambiguous
• It must give the correct solution in all cases
• It must eventually end.
9 February 2021 Introduction to Computer Algorithms 16
Efficiency of Algorithms
• The efficiency of an Algorithm means how fast it can
produce the correct results for the given problem.
• The Algorithm efficiency depends upon its time
complexity and space complexity.
• The complexity of an algorithm is a function that
provides the running time and space for data,
depending on the size provided by us.
• Two important factors for judging the complexity of
an Algorithm are:
9 February 2021 Introduction to Computer Algorithms 17
Efficiency of Algorithms
• Space complexity which refers to the amount of
memory required by the algorithm for it execution
and generation of the final output
• Time Complexity which refers to the amount of
computer time required by an algorithm for its
execution, which includes both the compile time and
run time.
9 February 2021 Introduction to Computer Algorithms 18
Efficiency of Algorithms
• The compile time of an algorithm does not depend
on the instance characteristics of the algorithm.
• The run time of an algorithm is estimated by
determining the number of various operation, such
as addition, subtraction, multiplication, division, load
and store executed by it.
9 February 2021 Introduction to Computer Algorithms 19
Analysis of Algorithm
• The analysis of an algorithm determines the amount
of resources, such as time and space required by it
for its execution.
• Generally, the algorithms are formulated to work
with the inputs or arbitrary length.
• Algorithm analysis provides theoretical estimates
required by an algorithm to solve a problem.
• The steps of an Algorithm, they can be presented
using Flow charts and pseudo-codes.
9 February 2021 Introduction to Computer Algorithms 20
4. Flow Charts
• A flow chart is a traditional means of showing
in diagrammatic form, the sequence of steps
to be undertaken in solving a problem.
• Flowcharts or flow diagrams are important tools
in writing a computer program.
• A flowchart allows one to plan the sequence of
steps in a program before writing it.
• The flowchart serves as a visual representation
which many programmers find indispensable in
planning any program of at least moderate
complexity
9 February 2021 Introduction to Computer Algorithms 21
Elements of Flow Charts
• A flowchart consists of a set of boxes, the
shapes of which indicate specific operations.
• The separate boxes are connected with arrows
to show the sequences in which the various
operations are performed.
• We use these standard symbols for flow charts
as shown in the next slide
9 February 2021 Introduction to Computer Algorithms 22
Elements of Flow Charts
• Process and Decision Symbols
9 February 2021 Introduction to Computer Algorithms 23
Elements of Flow Charts
• The flow or Path Symbols
9 February 2021 Introduction to Computer Algorithms 24
Elements of Flow Charts
• Input/output and Terminal Symbols
9 February 2021 Introduction to Computer Algorithms 25
Elements of Flow Charts
• Connector and description Symbols
9 February 2021 Introduction to Computer Algorithms 26
Stages of Flow Charts
• Program flowcharts are generally produced in
two stages representing different levels of details.
• Outline program flow chart
• It represents the first stage of turning the systems
flow charts into the necessary detail to enable
the programmer to write the programs.
• It represents the actual computer operations in
an outline only.
9 February 2021 Introduction to Computer Algorithms 27
Stages of Flow Charts
• Detailed program flow chart
• It is prepared from the outline charts and
contains the detailed computer steps
necessary to perform a particular task.
• It is from this charts that the programmer will
prepare the program code
9 February 2021 Introduction to Computer Algorithms 28
5. Pseudo Code
• Pseudo code is an alternative method of
representing an Algorithm to the flowcharts.
• Pseudo code is halfway between English and
programming language
• It is based upon a few simple grammatical
construction which avoid the ambiguities of
English but which can be easily converted into
computer programming language.
9 February 2021 Introduction to Computer Algorithms 29
Pseudo Code
• Pseudo code is an informal high-level description
of a computer programming algorithm
• It omits details that are not essential for human
understanding of the algorithm
• It is easier for humans to understand than
conventional programming language code
• It is compact and environment-independent
description of the key principles of an algorithm
• It resembles skeleton programs including dummy
code and can be compiled without errors.
9 February 2021 Introduction to Computer Algorithms 30
Pseudo Code
• Pseudo code assumes that programming
procedures no matter how complex may be
reduced to a combination of controlled
sequences, selection, or repetition of basic
operations.
• This gives rise to the control structures found
in pseudo-code shown in the next slide
9 February 2021 Introduction to Computer Algorithms 31
Pseudo Code
• Sequence Control Structure
9 February 2021 Introduction to Computer Algorithms 32
Pseudo Code
• Selection Control Structure
9 February 2021 Introduction to Computer Algorithms 33
Pseudo Code
• Repetition Control Structure
9 February 2021 Introduction to Computer Algorithms 34
Next Lecture
• Programming Methods
1) Top-down methodology
2) Bottom-up methodology
3) Structured programming Method
• Programming Paradigms
1) Imperative programming
2) Object-oriented programming
3) Functional programming
4) Logic Programming
9 February 2021 Introduction to Computer Algorithms 35