Monday, 20 January 2014

The Repetition constructs-repeat and while

Repetition can be implemented using constructs like the repeat loop,while loop and if...then...goto... loop.The repeat loop is used to iterate or repeat a process or sequence of processes until some conditional becomes true.
It has the general form:

Repeat
          Process 1
          Process 2
          ..............
          ...............
          Process N
          until proposition
Here is an example:
Repeat
          Fill water in kettle
until Kettle is full

The process is 'Fill water in Kettle',the proposition is 'Kettle is full'.
The repeat loop does some processing before testing the state of proposition.
What happens though if in the above example the Kettle is already full?
If the Kettle is already full at the start of the Repeat loop,then filling more water will lead to an overflow.This is a drawback of Repeat construct.
In such case the while loop is more appropriate.The above example with the while lopp is shown as follows:

while Kettle is not full
         fill water in Kettle

Since,the decision about the Kettle being full or not is made before filling water,the possibility of an overflow is eliminated.The while loop find out whether some condition is true before repeating a process or a sequence of processes.
If the condition is false,the process or the sequence of process is not executed.The general form of while loop processes is not executed.
The general form of while loop is :

while proposition
begin
Process 1
Process 2
...............
...............
Process N
end

The if...then...goto is also used to repeat a process or a sequence of process until the given proposition is false.In the Kettle example,this construct would be implemented as follows:

  1. Fill some water in Kettle
  2. if Kettle not full then goto 1

So long as the proposition 'Kettle not full' is true,the process 'fill some water in Kettle' is repeated.
The general form of if...then...got.. is:
Process 1
Process 2
..............
..............
Process N
if proposition then goto Process 1

Termination:

The definition of algorithm cannot be restricted to procedure that eventually finish.Algorithms might also include procedures that could run forever without stopping.Such a procedure has been called a computational method by Knuth or calculation procedure or algorithm by Kleene.However,Kleene notes that such a method must eventually exhibit 'some object'.Minsky (1967) makes the observation that,if an algorithm has not terminated,then how can the following question be answered:"Will it terminate with correct answer?".Thus the answer is :undecideable.It can never be known,nor can the deisgner do an analysis beforehand to find it out.The analysis of algorithms for their likelihood of termination is called termination analysis.

Correctness:

The prepared algorithm need to be verified for its correctness.Correctness means how easily its logic can be argued to meet the algorithm's primary goal.This requires the algorithm to be made in such a way that all the elements in it are traceable to the requirements.
Correctness requires that all the components like the data structure,modules,external interfaces and module interconnections are completely specified.
In other words,correctness is the degree to which an algorithm performs its specified function.The most common measure of correctness is defects per Kilo Lines of codes(KLOC) that implements the algorithm,where defect is defined as the verified lack of conformance to requirements.

IF YOU NEED ANY MORE INFORMATION RELATED TO ALGORITHM,VISIT THIS LINK: HTTP://GOO.GL/YLJXYP

Please don't forget to share this information with your friends.

0 comments:

 

Subscribe to our Newsletter

Contact our Support

Email us: nerdprogrammergm@gmail.com

Our Team Memebers