Program Design Tools

Introduction to Algorithm


The term "algorithm" is used for describing the sequence of actions leading to the solution of the given problem. The field of mathematics known as the theory of algorithms is dedicated to the study of the properties, methods of recording, the creation of new algorithms and the application of different algorithms.

Basic requirements to the algorithms used in computer science are the following:
  • Discreteness: the algorithm should lead to the solution of the assigned problem, introducing the solution of the problem as a sequence of actions.
  • Finiteness: the number of steps of the algorithm must be finite.
  • Efficiency: the algorithm must be such that a solution could be found in a finite and reasonable time.
  • Certainty (or precision): algorithm's steps have to allow unambiguous interpretation. Each algorithm has to be devised for a certain performer. In order that the performer could solve the problem according to the given algorithm, it is necessary that it would be able to understand and perform each action instructed by the algorithm. Any action of the algorithm must be strictly defined and described in each case.
  • Effectiveness: the algorithm must produce concrete results. Moreover, the message that the problem has no solution means the result. 
  • Versatility: the algorithm must be developed so that it could be used to solve similar problems (For example, the rules of addition and multiplication of numbers are suitable for any numbers and not for any specific ones.). 
The algorithm defines the order of steps that are initiated to solve a particular problem.

We are solving the problem by the algorithm shown below. In this algorithm we first take two numbers. If the first number is smaller than the second number then it printed else if the second number is smaller than it is printed. If both the conditions are false then it is printed that both the numbers are equal.

Example: The algorithm find the smaller of two numbers.

(1) Take the two numbers a and b
(2) Compare a and b
(3) If a is smaller, display a
(4) Else display b
(5) Exception if a and b are equal
(6) Display a and b are equal
  

Introduction to Flowchart

It is the graphical representation of the problem. In this method we create the graphical representation of the problem given. 


The flowchart for find the smaller of two numbers 

In this flow chart we first take two numbers. If the first number is smaller than the second number then it printed else if the second number is equal to the first number then it is printed that both the numbers are equal. If both the conditions are false then the second number is printed. 


Flowchart symbols

There are some symbol used for following any problem statement using flowchart.


Pseudo code  

It is method in which the problem is divided into smaller steps so that the problem becomes easier to analyze and to solve like in the algorithms but it is a bit more compact. The numbering is not there in pseudo code and it is basically very much like the code that we will use in program.

In below pseudo code, we check whether the first number is smaller than the second number. If it is then it printed else if the second 
number is smaller than it is printed. If both the conditions are false then it is printed that both the numbers are equal.  

If a < b? yes --> display a
     no
If b < a? yes --> display b
     no
display "a and b are equal"
Exit;
  

Comments

Popular posts from this blog

Lab Assignment (Programming and Problem Solving) SPPU BE First Year.

Examples of Flowchart and Pseudo Code

Unit 4