You are on page 1of 4

Algorithm & Programming

CAPES NOTES

Objective #7: Explain the concept of algorithm

An algorithm is a sequence of precise instructions for solving a problem in a finite


amount of time. An algorithm must be precise, unambiguous, give the correct solution in all and
eventually end.

Objective # 8: Identify the necessary properties of ‘well designed’ algorithms

Properties including:
 A general solution to the problem in a finite number of steps – There should be an exact
number of steps to be taken and has an end.
 Clearly defined and unambiguous- Every instruction should be precisely described and
clearly specified.
 Flow of control from one process to another- The instructions to be performed should
be performed from top to bottom/ in order.

Objective # 9: Identify ways of representing algorithms

Ways of representing algorithm


 Narrative- This type of algorithm involves, telling a story of how the problem will be
solved. It goes in-depth and produce more details than that of pseudocode.

 Flowcharts-
Flowcharts refer to graphical or symbolic representation of an algorithm or process. It is
the diagrammatic representation of the step-by-step solution to a given problem. Each
step in the process is represented by a different symbol and contains a short description of
the process step. The flow chart symbols are linked together with arrows showing the
process flow direction. A flowchart typically shows the flow of data in a process,
detailing the operations/steps in a pictorial format which is easier to understand than
reading it in a textual format. A flowchart describes what operations (and in what
sequence) are required to solve a given problem.

 Pseudocode-
Pseudocode is an artificial and informal language that helps programmers develops
algorithms. Pseudocode is an imitation computer program written using Mathematical
notations and English like statements, to describe the logics to solve a problem or carry
Algorithm & Programming

out a procedure. A pseudocode is used in place of symbols or flowcharts. It is used as a


guide to code the solution to the problem in a high language.

Objective # 10: Develop algorithms to represent problem solution


Control Structures

A structure is a basic unit of programming logic. A structure can be a sequence, a selection or a


loop (that is, repetition). The body of the algorithm is comprised of various structures.

Sequential structures are:

1. Input statements, for example,


a. Get num1, num2
b. Read price, tax-rate
c. Accept guess

2. Output statements, for example,


a. Print total-cost
b. Display average

3. Statements involving arithmetic operations, such as:


a. Sum = num1 + num2
b. Average = sum  2

4. Statements that assign values to variables, such as:


a. Count = 0
b. Maximum = 20

Selection structures are:

IF or IF-then-else statements. They allow decisions to be made, based on some condition that
evaluates to true. In the case of if-then-else, alternatives are executed if the condition is false.

a. If (A > B) then
Display A
b. If (age >= 50)
Print “Old”
Else
Print “Young”
Algorithm & Programming

Repetition or Loop structures allow statements to be repeated a fixed number of times or until
some condition evaluates to false. If the number of repetitions is known beforehand, the loop
structure is called a counted loop. For example,

c. Repeat 10 times:
Print “I am good-looking”
End-repeat

If the exact number of repetitions is unknown beforehand and is based upon some condition, then
the loop is called a conditional loop. For example,

d. While (price  0) do
Read price
Total = total + price
End-while

Objective # 11: Explain the concept of programming

A program is a list of instructions that is executed by a computer to accomplish a particular task.


Programming is instructing a computer to do something for you with the help of a programming
language.
A programming language is a set of rules that provides a way of telling a
computer what operations to perform.

 Stages in programme development- Check SDLC

 Programming paradigms
Programming paradigm refers to the fundamental style of computer programming. It serves as a
pattern or model for a programming language.
The main Paradigms are:
Programming Paradigms Description Programming Language
1. Imperative/ Algorithmic Commands show how the  FORTRON
computation takes place, step by  BASIC
step.  C
2. Functional Control flow is expressed by  Haskell Python
Algorithm & Programming

combining function calls, rather  Miranda


than by assigning value to  ML
variables.  LISP

3. Object-Oriented Computation is effected by  Java


sending messages to objects;  C++
objects have state and behavior.  Eiffel
4. Procedural Imperative programming with  Pascal
procedural calls.  C
5. Declarative /Logic The programmer states only  SQL
what the result should look like,  Mercury
not how to obtain it.  PROLOG

Objective #12: Outline the interrelationship(s) between algorithms and programming


Algorithms as precursor to program development

Algorithms present solution to a problem in natural language/ algorithmic language format. It


does not deal with machine specific details. Program development on the other hand, is the
implementation of an algorithm to be run on a specific computer or operating system.

You might also like