An algorithm is a set of instructions for solving a problem in a finite number of steps. The algorithm is said to terminate or halt in a finite number of steps if it always produces a result or a decision, and it never runs into an infinite loop.
An algorithm is usually expressed in a programming language. In Python, for example, the algorithm for finding the largest number in a list can be written as:
def largest(nums):
max = nums[0]
for i in nums:
if i max:
max = i
return max
The algorithm is implemented as a function, largest, …