Chapter 1
Chapter 1
INTRODUCTION TO ALGORITHMS
To Make a computer do anything, we have to write a computer program.to write a
computer program, we have to tell the computer, step by step, exactly what we
want to do. The computer then “executes “the program, following each step
mechanically, to accomplish the end goal.
WHAT IS ALGORITHM?
An algorithm can be defined as a step by step-by-step procedure for
accompolishing a task.OR a sequence finite number of steps to solve a particular
problem,its has threebasic parts-input,logic,output.
Eg:write an algorithm to find the average of three subjects.
Step1:start
Step2:read the three numbers a,b,c.
Step3:compute
Avg=(a+b+c)/3
Step4:print the average of three numbers.
Step5:end.
Optional:
A SEQUENCE OF COMPUTATIONAL
INPUT
STEPS THAT TRANSFORM THE OUTPUT
INPUT INTO THE OUTPUT.
CHARACTERISTICS OF ALGORITHM:
1. INPUT:An Algorithm has zero or more “inputs”quantities that are given to
it initially before the algorithm begins,or dynamically as the algorithm runs.
2. OUTPUT: An Algorithm has one or more “output”quantities that have a
specified relation to the inputs.An Algorithm produces at least one or more
outputs.
3. UNAMGIGIOUS:An Algorithm should be clear and error-free.
4. FINITENESS: An Algorithm should always terminate after a number of
steps.If we trace out the instructions of an algorithm,then for all cases,the
algorithm terminates after a finite number of steps.
5. EFFECTIVENESS:Each Operation should be effective i.e,the operation
must be able to carryout in finite amount of time.
6. LANGUAGE INDEPENDENT:An Algorithm should be independent
of any programming language.