You are currently viewing How to Write an Algorithm in Programming Language?

How to Write an Algorithm in Programming Language?

How to Write an Algorithm in Programming Language?

Algorithm in Programming Language

An Algorithm in Programming Language is the best way to represent the logic before implementing it. An Algorithm is a simple way to write our logic in the form of a language like English so that everyone can understand the logic before implementing the actual coding.

Qualities of a good Algorithm

  • Input and output should be defined precisely.
  • Each step in the algorithm should be clear and unambiguous.
  • The algorithm should be most effective among many different ways to solve a problem.
  • An algorithm shouldn’t have computer code. Instead, the algorithm should be written in such a way that, it can be used in similar programming languages.

Examples of Algorithms In Programming

Here is the example to find the largest value from the given list.

Algorithm LargestNumber
  Input: A list of numbers L.
  Output: The largest number in the list L.
  if L.size = 0 return null
  largest ← L[0]
  for each item in L, do
    if item > largest, then
      largest ← item
  return largest
  • “←” denotes assignment. For instance, “largest ← item” means that the value of the largest changes to the value of the item.
  • “return” terminates the algorithm and outputs the following value.

Another example to generate 4 characters Hash Value: 4 Characters Hash Value Algorithm.
Please refer Wikipedia link to know more about the Algorithm in Programming Language.