4_Computer%20Program
4_Computer%20Program
com
COMPUTER PROGRAM
1. Introduction to Algorithm
Algorithm means the logic of a program. It is a step-by-step description of how to
arrive at a solution of a given problem.
(Or)
An algorithm is a description of a procedure which terminates with a result. Simple
algorithms can be implemented within a function.
Properties of an algorithm
No ambiguity
There should not be any uncertainty about which instruction to execute next.
The algorithm should conclude after a finite number of steps.
The algorithm should be general.
Example:
Biggest among two numbers
Addition of N numbers
Finding Factorial of a number
Finding Fibonacci series
TalentSprint©2015
www.talentsprint.com
Quality of Algorithm
The primary factors that are often used to judge the quality of an algorithm are
time requirement, memory requirement, and accuracy of solution.
Characteristics of an Algorithm
In algorithms each and every instruction should be precise
In algorithms each and every instruction should be unambiguous
The instructions in an algorithm should not be repeated infinitely
Ensure that the algorithm will ultimately terminate
The algorithm should be written in sequence
It looks like normal English
The desired result should be obtained only after the algorithm terminates
Types of Algorithm
1. Normal English Program
2. Flowchart
3. Pseudo code
4. Decision table
TalentSprint©2015
www.talentsprint.com
Advantages
Logic Flowcharts are easy to understand. They provide a graphical
representation of actions to be taken.
Logic Flowcharts are well suited for representing logic where there is
intermingling among many actions.
Disadvantages
Logic Flowcharts may encourage the use of GoTo statements leading to
software design that is unstructured with logic that is difficult to decipher.
Without an automated tool, it is time-consuming to maintain Logic
Flowcharts.
Logic Flowcharts may be used during detailed logic design to specify a
module.
TalentSprint©2015
www.talentsprint.com
However, the presence of decision boxes may encourage the use of GoTo
statements, resulting in software that is not structured. For this reason, Logic
Flowcharts may be better used during Structural Design.
Only one flow line should enter a decision symbol, but two or three flow
lines, one for each possible answer, should leave the decision symbol.
TalentSprint©2015
www.talentsprint.com
Write within standard symbols briefly. As necessary, you can use the
annotation symbol to describe data or computational steps more clearly.
If the flowchart becomes complex, it is better to use connector symbols to
reduce the number of flow lines. Avoid the intersection of flow lines if you
want to make it more effective and better way of communication.
Ensure that the flowchart has a logical start and finish.
It is useful to test the validity of the flowchart by passing through it with a
simple test data.
The standard symbols should only be used.
The arrowheads in the flowchart represent the direction of flow of control in
the problem.
The usual direction of the flow of procedure is from top to bottom or left to
right. The flow lines should not cross each other.
TalentSprint©2015
www.talentsprint.com
TalentSprint©2015
www.talentsprint.com
3. Pseudo Code: “Pseudo” means imitation of false and “code” refers to the
instruction written in the programming language. Pseudo code is programming
analysis tool that is used for planning program logic.
Guidelines:
Statements should be in simple English
Must produce a solution for the specified problem
It should be concise
Each instruction should be written in separate line and express one action.
Capitalize keywords such as READ, PRINT and so on.
Instruction should be written from top to bottom, with one entry and one
exit. Should allow easy transition from design to coding in programming
language.
Benefits:
Language Independent
Easy to develop a program from pseudo code than flowchart. Easy to
translate into programming language
It is compact
Limitations:
No visual representation of program logic
No accepted standards for writing pseudo codes
Cannot be compiled or executed
No real form or syntax rules
Examples:
Finding a number is prime or not
TalentSprint©2015
www.talentsprint.com
TalentSprint©2015
www.talentsprint.com
TalentSprint©2015
www.talentsprint.com
Selection Control Structure: Selection logic is used for selecting the process path
out of two or more alternative paths in the program logic. It uses three control
structures called if…then, if… then…else and switch…case. Selection control
structure allows the program to make a chance between alternate paths, when it is
true or false.
Selection Control Structure: Selection logic is used for selecting the process path
out of two or more alternative paths in the program logic. It uses three control
structures called if…then, if… then…else and switch…case. Selection control
structure allows the program to make a chance between alternate paths, when it is
true or false.
Example: Largest of two numbers
TalentSprint©2015
www.talentsprint.com
TalentSprint©2015