Академический Документы
Профессиональный Документы
Культура Документы
Algorithm
Algorithm
An Algorithm refers to the logic of
program. Step by step description to arrive at the solution. Designed in such manner that if the steps are executed in the specified sequence, the desired result will be obtained.
Algorithm: A sequence
of instructions describing how to do a task (or process)
C Program
Definition of Algorithm
In Computer Science Algorithm means, a precise method usable by computer for achieving the solution of a problem. It is the list of procedure or steps for solving a problem or to arrive at the solution.
supposed to; Feasible - each step can be executed in reasonable time Efficient - the algorithm uses as little running time and memory space as possible within the limits of an acceptable development time.
Properties of Algorithm
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
Rules of Algorithm
It should have an input. Steps of algorithm should be executable
by the computer. Time taken by steps must be finite and small. It must produce an output after executing the steps. Should be written in very simple language.
if an algorithm can be written for it. While writing an algorithm we can identify The step-by-step procedure The major decision points The variables necessary to solve
the
problem
Problem is reduced into a series of smaller
problems of more manageable size. Decision making becomes a more rational process. With the use of an algorithm, the same specified steps are used for performing the tasks that makes the process more consistent and reliable.
Examples of Algorithm
A cooking recipe Assembly instructions for a model The rules of how to play a game
VCR instructions
Description of a martial arts technique Directions for driving from A to B A knitting pattern A car repair manual
Algorithm Example 1
Algorithm Example 2
To find largest of numbers. five
FindLargest Refined
Generalization of FindLargest
FindLargest Algorithm
1) Start 2) Read 5 numbers 3) Set largest to first number 4) if the next number is greater than largest then Set Largest to next number 5) Repeat Step (4) for 4 times 6) Display largest 7) End
Exercise
1. Write an algorithm to convert the temperature the temperature in Centigrade to Temperature in Fahrenheit. 2. Write an algorithm to display the sum of first ten natural numbers.
Three Constructs
Any algorithm can be developed using three constructs Sequence Decision Repetition
Sequence Construct
A series of steps or statements that are executed in the order they are written. do action 1 do action 2 do action N
Decision Construct
Defines one or more courses of action
depending on the evaluation of a condition. A condition is an expression that is either true or false. if condition is true do action 1 else do action 1 end if
Repetition Construct
Allows one or more statements to be repeated as long as a given condition is true. These statements will make up what is known as the body of a loop. While (condition is true) do action 1 do action 2 do action N End_while
Exercise
1. Write an algorithm to display the sum of first ten natural numbers. 2. Write an algorithm to display the table of given number.