# Digital Analysis and Algorithms

Analysis of Algorithm:

INTRODUCTION – ANALYZING CONTROL STRUCTURES-AVERAGE CASE ANALYSIS-SOLVING RECURRENCES.

ALGORITHM

Informal Definition:

An Algorithm is any well-defined computational procedure that takes some value or set of values as Input and produces a set of values or some value as output. Thus algorithm is a sequence of computational steps that transforms the i/p into the o/p.

Formal Definition:

An Algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition, all algorithms should satisfy the following criteria.

1.INPUT Zero or more quantities are externally supplied. 2.OUTPUT At least one quantity is produced.

3.DEFINITENESS Each instruction is clear and unambiguous. 4.FINITENESS If we trace out the instructions of an algorithm, then for all cases, the algorithm terminates after a finite number of steps. 5.EFFECTIVENESS Every instruction must very basic so that it can be carried out, in principle, by a person using only pencil & paper.

Issues or study of Algorithm:

•How to device or design an algorithm creating and algorithm. •How to express an algorithm definiteness.

•How to analysis an algorithm time and space complexity. •How to validate an algorithm fitness.

•Testing the algorithm checking for error.

Algorithm Specification:

Algorithm can be described in three ways.

1.Natural language like English:

When this way is choused care should be taken, we should ensure that each & every statement is definite.

2. Graphic representation called flowchart:

This method will work well when the algorithm is small& simple.

3.Pseudo-code Method:

In this method, we should typically describe algorithms as program, which resembles language like Pascal & algol.

Pseudo-Code Conventions:

1.Comments begin with // and continue until the end of line.

2.Blocks are indicated with matching braces {and}.

3.An identifier begins with a letter. The data types of variables are not explicitly declared.

4.Compound data types can be formed with records. Here is an example, Node. Record

{

data type – 1 data-1;

.

.

.

data type – n data – n;

node * link;

}

Here link is a pointer to the record type node. Individual data items of a record can be accessed with and period.

5.Assignment of values to variables is done using the assignment statement. := ;

6.There are two Boolean values TRUE and FALSE.

Logical Operators AND, OR, NOT

Relational Operators =, =, !=

7.The following looping statements are employed.

For, while and repeat-until

While Loop:

While < condition > do

{

.

.

.

}

For Loop:

For variable: = value-1 to value-2 step step do

{

.

.

.

}

repeat-until:

repeat

.

.

.

until

8.A conditional statement has the following forms.

If then

If then

Else

Case statement:

Case

{

: :

.

.

.

: :

: else :

}

9.Input and output are done using the instructions read & write.

10.There is only one type of procedure:

Algorithm, the heading takes the form,

Algorithm Name (Parameter lists)

As an example, the following algorithm fields & returns the maximum of ‘n’ given numbers:

1.algorithm Max(A,n)

2.// A is an array of size n

3.{

4.Result := A[1];

5.for I:= 2 to n do

6. if A[I] > Result then

7. Result :=A[I];

8. return Result;

9.}

In this algorithm (named Max), A & n are procedure parameters. Result & I are Local variables.

Next we present 2 examples to illustrate the process of translation problem into an algorithm....

Please join StudyMode to read the full document