What is an Algorithms

We learn about data structures and algorithms, introduction to algorithms, types of algorithm,  algorithms examples, algorithms book, what is algorithms in programming, geeksforgeeks algorithms, algorithms for beginners.

What is an Algorithms

An algorithm is a set of instructions which is followed by to write a particular program. Or an algorithm is also a well-defined list of steps for solving a particular problem.

Algorithms are mainly used to achieve software reuse. Once we have an idea or a blueprint of a solution, we can implement it in any high-level language like C, C++, or Java.

 The complexity of an algorithm is the function which gives the running time and/or space in terms of the input size.

An algorithm is a finite set of unambiguous instructions which, when executed, performs a task correctly. 

There are three characteristic features in this description of an algorithm. 

The number of steps required to perform the task should be finite.

Each of the instruction in the algorithm should be unambiguous in nature; meaning on the execution of each such instruction, the outcome should be definite and predictable. Finally, the algorithm should solve the problem correctly. In other words, on the execution of the algorithm, the objective should be fulfilled.

There are no defined rules to write an algorithm. However, most authors prefer to use English-like statements to represent the action that needs to be performed at each step. We will consider different examples to demonstrate each of the three logic constructs.

Algorithms and flowcharts are two such tools.  Thus, the logic represented using one of these tools may be used to write programs in any language of the programmer's choice. In fact, logic should always be independent of programming languages.

Programming logic constructs are of three Important types 

• Imperative statements (action)

• Conditional statements (decision-making)

• Iterative statements (repetition Loops)

The tools which we are talking about should be capable of representing each of these three kinds of constructs because a program comprises statements which fall into one of these three categories.  After all, it has been rightly said that well planned is half done.

EXAMPLE 1 (Use of imperative constructs)

Problem - Develop an algorithm to find the average of three numbers taken as input from the user.

Algorithm AVERAGE

Step 0 START Step 1 INPUT first number into variable A


Step 5 COMPUTE AVG = SUM / 3


Step 7 END


EXAMPLE 2 (Conditional construct)

Problem - Develop an algorithm to divide one number by another and find the quotient.

Algorithm DIVISION 

Step 0 START

Step 1 INPUT first number Into variable A

Step 2 INPUT second number into variable B

Step 3 IF B! =0 THEN

                          Q =A/B 

                           DISPLAY Q

             END IF 

Step 4  END

EXAMPLE 3 (Conditional construct)

Problem - Develop an algorithm to find the maximum of two numbers input by the user,

Algorithm MAXIMUM

Step 0 START 

Step 1 INPUT first number into variable A

Step 2 INPUT second number into variable B

Step 3 IF A > B THEN

                   MAX =A


             MAX =B

            END IF 


Step 5 END

EXAMPLE 4 (Iteration construct)

Problem - Develop an algorithm to find the sum of the first N natural numbers where N would be input by the user.

Algorithm SUM-N

Step 0 START

Step 1 INPUT N

Step 2 I=1

Step 3 SUM = 0

Step 4 REPEAT Steps (a) - (b) WHILE I<=N

                              (a) SUM =SUM + I




Step 6 END

20) Data Structures & Algorithms | What Is Data Structures?

What is data structures and algorithms, data structures tutorial, data structures types data structures interview questions, data structures in c, data structures in python, data structures in java, data structures and algorithms in java pdf.

Post a Comment