What is an Algorithm in Programming | DSA Tutorials YASH PAL, 11 February 20205 May 2026 Algorithm in Programming – In programming, an algorithm is a step-by-step method for solving a problem. In other words, we can say that an algorithm has a finite sequence of instructions. And in order to solve a particular problem, we need a precise and step-by-step method. Not in terms of programming, but in our daily lives, we need a step-by-step plan to do any work.What is an Algorithm in ProgrammingThe word algorithm comes from the name of the 9th century Persian mathematician Muhammad ibn Musa al-Khwarizmi, whose works introduced Indian numerals and algebraic concepts as step-by-step calculations. The word algorism originally referred only to the rules of performing arithmetic using Arabic numerals, but evolved via European Latin translation of al-Khwarizmi’s name into algorithm by the 18th century. At present, the word algorithm includes all definite procedures for solving problems or performing tasks.The term ALGORITHM refers to the logic of a program. It is the step-by-step description of the method to arrive at a solution of the given problem. An algorithm is a finite set of steps defining the solution of a particular problem. An algorithm can be expressed in English-like language, called pseudo-code. The pseudo-code is straightforward. There may be many ways to solve a particular problem, and each procedure of writing to solve that problem is known as designing an algorithm.Each algorithm will involve a particular data structure, so we may not always use the most efficient algorithm. Graphical representation, called a flow chart, is another way to solve the problem. The efficiency of implementation of the algorithm depends upon speed, size, and resource consumption. Algorithms that are definite and effective are also called computational procedures. One important example of a computational procedure is the operating system of a digital computer. This procedure is designed to control the execution of jobs in such a way that when no jobs are available. It does not terminate but continues in a waiting state until a new job is entered.Evaluating AlgorithmInput: An algorithm takes one or more quantities as input. It means algorithms may or may not require input, and the input quantities can be more than one. The input refers to the data (facts, figures, numbers) provided to the algorithm, on which the computation is performed. For example, if there is an algorithm for adding three numbers, it requires the three numbers as input.Output: An algorithm essentially produces an output. It can give more than one value or a set of values as a result. For example, an algorithm for adding three numbers will give the sum as a result of the calculation; this is the output.Effectiveness: Every step of the algorithm must be so simple or basic that a person can perform the complete algorithm using only a pen and paper. Though most of the time an algorithm is intended to be converted into a computer program, simple steps ensure that the algorithm can be understood and carried out by anybody. The objective of an algorithm is to provide a breakup of a difficult task into a sequence of simpler steps.Finiteness (Termination): An algorithm must terminate at some point for all cases, after some finite number of steps. The algorithm cannot go on forever; otherwise, we will never get the result. It must stop somewhere, like when the result is ready or the task is finished. Also, there can be a different sequence of steps followed for different cases of input. The algorithm must terminate for all these cases.Definiteness: Each step must be unambiguous. If the steps are confusing, the whole aim of writing an algorithm fails. Each step must do something; it must proceed in the direction of the result.Correctness: An algorithm must achieve what we expect it to do. If you demand an algorithm for addition, and I provide you with an algorithm for multiplication, will you be satisfied? The same thing is implied here; an algorithm must do what we think it should do.Expressing AlgorithmWe need some way to express the steps comprising an algorithm. An algorithm can be represented in different ways: a flowchart, pseudocode, simple English sentences, a computer program, etc. The representation used depends on how precisely we want to describe the algorithm.For the purpose of representing algorithms in this book, we will use the following conventions:Every algorithm has a name.The input/s provided to the algorithm are written in parentheses along with their names.Any assignment statement is expressed using the assignment operation “:=”. Like, if we wish to assign the value 5 to variable a, then it is written as a: = 5.The symbol // means a comment. Comments are not part of the algorithm; they are not carried out. They are included in the pseudocode to clarify the meaning of some operations.A conditional statement is written using an If-Then statement and an If-Then-Else statement. End If is used to mark the end of an If statement.Loops are represented by a While-End While structure, or a For-End For structure. The syntax is For <variable>: = <initial value> To <final value> Step <size>.Array indices are expressed within square brackets, as Arr[i]. Two-dimensional arrays are declared as A[1…n], and an element is represented as Arr [i,j].Results are returned using the Return<value> statement.For example, consider an algorithm for finding the sum of n numbers, stored in any array. The algorithm in simple English sentences is:Step 1: Take n numbersStep 2: Set the sum to zero.Step-3: Repeat step 4 for the first number to the nth numberStep 4: Add the number to the sumStep 5: Return sumNow, let us convert this algorithm into pseudocode using the conventions. The pseudocode will look like the following algorithm:Sum (Nums, n)//Nums is an array of numbers//n is the size of array// Initialize sum to zero1. sum : = 02. For i : = 1 to n3. sum : = sum + Nums[i] //Add ith number to current sum4. End For5. Return sumAlgorithm meaning in programmingAn algorithm is a finite set of instructions that, when followed by these instructions, can accomplish a particular task. In addition, all algorithms must satisfy the following criteria while solving a particular programming problem:Input – Zero or more quantities are externally supplied.Output – At least one quantity is produced.Definiteness – Each instruction is unambiguous.Finiteness – If we trace out the instructions of an algorithm, then for all cases, the algorithm terminates after a finite number of steps.Effectiveness – Every instruction must be very basic so that it can be carried out, in principle, by a person using only a pencil and paper.An algorithm is a well-defined list of steps for solving a particular problem. The time and space it uses are two major measures of the efficiency of an algorithm. The complexity of an algorithm is the function that gives the running time or space in terms of the input size.How to obtain an Algorithm in programmingTo obtain an algorithm or to write an algorithm, we need three things: input, a sequence of instructions to process the input, and the last result of the algorithm.Inputa sequence of instructions to process the input.ResultFigure 1: Algorithm in ProgrammingFormat of Algorithm PresentationThe format for the presentation of an algorithm consists of two parts – The first part is a paragraph that tells the purpose of the algorithm, identifies the variables that occur in the algorithm and lists the input data. The second part consists of the list of steps that are to be executed.For example, to make a recipe for making potato bonds, we need a step-by-step process we first need the list of ingredients, and then the making method and then the expected result will come.Ingredients – Potatoes 250 grams, chopped onions, finely chopped green chillies, gram flour, oil for frying, water for the batter, salt, etc…Algorithm MethodStep 1: Boil potatoes till cooked, peel and mash them until they are soft. Step 2: Mix fried onions, green chillies, and salt with the mashed potatoes. Step 3: Take little portions of the mixture and make small balls.Step 4: Mix gram flour, water, and a little salt and beat well till a smooth and creamy batter is obtained. Step 5: Dip the potato balls in the batter. Take out and deep fry in oil on a low fire.Step 6: Take out when the balls are fried to a golden brown colour. Result – Potato bonds are ready.In the above example, the Ingredients work as an input. and the method is working as a sequence of instructions. And then the result comes out as our potato bonds are ready.Characteristics of AlgorithmAn algorithm has the following five basic characteristicsFirst: an algorithm begins with instructions to accept inputs. These inputs are processed by the subsequence and sequence of instructions in the algorithm. Second: The sequence of instructions specified in the algorithms must be precise and unambiguous. and not be vague. Third: Each instruction must be sufficiently basic such that it can be carried out by a person with paper and pencil. Fourth: The total time consumed by the algorithm must be finite. Five: An algorithm must produce one or more outputs.Let’s take another technical example.A step-by-step procedure to find the average number of vowels in a passage.Step 1: Let the number of characters = 0Step 2: Let the number of vowels = 0Step 3: Repeat Steps 4, 5, 6, and 7 until no more characters are left in the passage. Step 4: Read one character from the passage.Step 5: Add 1 to some characters.Step 6: If the character is any one of the letters A, E, I, O, U, a, e, I, o, u, add 1 to the number of vowels.Step 7: Move to the next character. Step 8: Average Number of vowels = Number of vowels / Number of charactersStep 9: Write the average number of vowels and several characters.Step 10: Stop.And in the above process to find the average number of vowels in a passage is an algorithm because it has several inputs, a finite number of sequences and instructions and terminates on a condition and has a sufficient output.Data Structures & Algorithms Tutorials for Beginners Data Structures Tutorials DSA Tutorials