Algorithm
An algorithm is a set of steps for
accomplishing a task or solving a problem.
Typically, algorithms are executed by
computers, but we also rely on algorithms
in our daily lives. Each time we follow a
particular step-by-step process, like making
coffee in the morning or tying our
shoelaces, we are in fact following an
algorithm.
In the context of computer science, an
algorithm is a mathematical process for
solving a problem using a finite number of
steps. Algorithms are a key component of
any computer program and are the driving
force behind various systems and
applications, such as navigation systems,
search engines, and music streaming
services.
What is an algorithm?
An algorithm is a sequence of instructions
that a computer must perform to solve a
well-defined problem. It essentially defines
what the computer needs to do and how to
do it. Algorithms can instruct a computer
how to perform a calculation, process data,
or make a decision.
The best way to understand an algorithm is
to think of it as a recipe that guides you
through a series of well-defined actions to
achieve a specific goal. Just like a recipe
produces a replicable result, algorithms
ensure consistent and reliable outcomes for
a wide range of tasks in the digital realm.
And just like there are numerous ways to
make, for example, chocolate chip cookies
by following different steps or using slightly
different ingredients, different algorithms
can be designed to solve the same
problem, with each taking a distinct
approach but achieving the same result.
Algorithms are virtually everywhere around
us. Examples include the following:
● Search engines rely on algorithms to
find and present relevant results as
quickly as possible
● Social media platforms use algorithms
to prioritize the content that we see in
our feeds, taking into account factors
like our past behavior, the popularity of
posts, and relevance.
● With the help of algorithms, navigation
apps determine the most efficient route
for us to reach our destination.
Note
It is important to keep in mind that we
cannot call a set of instructions an algorithm
unless it has all the following properties:
● It must be correct. In other words, it
should take a given problem and
provide the right answer or result, even
if it stops working due to an error.
● It must consist of clear, practical steps
that can be completed in a limited time,
whether by a person or the machine that
must execute the algorithm. For
example, the instructions in a cookie
recipe might be considered sufficiently
concrete for a human cook, but they
would not be specific enough for
programming an automated
cookie-making machine.
● There should be no confusion about
which step comes next, even if
choices must be made (e.g., when using
“if” statements).
● It must have a set number of steps
(not an infinite number) that can be
managed using loops (statements
describing repeated actions or
iterations).
● It must eventually reach an endpoint
and not get stuck in a never-ending
loop.
How do algorithms work?
Algorithms use a set of initial data or input,
process it through a series of logical steps
or rules, and produce the output (i.e., the
outcome, decision, or result).
are doing so. While it may seem to come
naturally to us, for example, deciding what
to wear in the morning is a complex
decision involving many steps. If you had to
write down your process in detail, you
would end up with an algorithm, which
could look something like this:
1. Identify which clothes are clean.
2. Consider the weather forecast for the
day.
3. Consider the occasion for which you
are getting dressed (e.g., work or school
etc.).
4. Consider personal preferences (e.g.,
style or which items match).
All of this can be represented with data,
either as words (e.g., “casual”) or numbers
(e.g., the temperature), which can serve as
input for your decision. The next step is
processing these input quantities. If you
had to write this down, it would include
statements like “If it’s below 50 degrees,
pick out a sweater and put it on” or “If it’s
sunny, grab sunglasses and put them on.”
After getting dressed, we step out of the
house, which is the output of our
getting-dressed algorithm.
In mathematics, algorithms are standard
methods for performing calculations or
solving equations because they are
efficient, reliable, and applicable to various
situations.
Example standard algorithm for addition
In mathematics, a standard algorithm
refers to a specific, well-defined set of steps
or procedures used to solve mathematical
problems of a particular type. Different
places in the world use different algorithms,
so every school system may teach this
concept differently. In the United States,
schools use a standard algorithm based on
place value and the properties of operations
for addition, subtraction, multiplication, and
division.
Suppose you want to add the numbers 345
and 278. You would follow a set of steps
(i.e., the standard algorithm for addition):
1. Write down the numbers so the
digits align.
2. Start from the rightmost digits (the
ones place) and add them together:
5 + 8 = 13. Write down the 3 and
carry over the 1 to the next column.
3. Move to the next column (the tens
place) and add the digits along with
the carried-over value: 4 + 7 + 1 =
12. Write down the 2 and carry over
the 1 to the next column.
4. Move to the leftmost column (the
hundreds place) and add the digits
along with the carried-over value: 3 +
2 + 1 = 6. Write down the 6.
The final result is 623
Navigation systems are another example of
the use of algorithms. Such systems use
algorithms to help you find the easiest and
fastest route to your destination while
avoiding traffic jams and roadblocks.
Example of algorithm: Navigation systems
The algorithms used in navigation systems
like Google Maps are essentially the brains
of these apps. These algorithms use a
wealth of data, including detailed maps and
live traffic updates, to determine the best
way to get where you want to go. They
consider factors like how far you need to
travel or which roads are busy.
If there are any unexpected problems, such
as accidents on a given route, algorithms
quickly recalculate and suggest alternate
routes to avoid delays; this ensures that
you don’t waste time in traffic. They also
provide you with step-by-step directions so
you know exactly where to turn. These
algorithms learn from how people use them
and therefore keep getting better at finding
the quickest routes.