What is an algorithm?

An algorithm is a sequence of steps to solve a problem. Its purpose is to find the solution to a particular problem. The scope of an algorithm is not limited to mathematical or logical concepts.

Algorithms can be thought of as a procedure to a solve problem. Listed below are the criteria for a procedure to be an algorithm:

  1. The procedure must ultimately provide the solution to the problem being addressed. It should be finite.
  2. Each step in the sequence must be clear-cut and understandable.
  3. The algorithm must be effective.

Let’s learn by example. Here’s a trivial and simple example of an algorithm to make toast:

  1. Get bread from cupboard
  2. Remove toaster from drawer
  3. Put bread in toaster
  4. Turn on and sent temperature / timer
  5. When toast pops up add butter
  6. Eat and enjoy

When it comes to finding the solution to a problem, there can be multiple approaches. For instance, to find the GCD (Greatest Common Divisor) of two numbers, we can use the Euclidean algorithm, the Lehmer’s GCD algorithm and many other methods. Since a given problem can be solved in multiple ways, people often spend a great deal of time comparing algorithms to determine which one works best in a given situation.

In their book, Algorithms for Dummies, John Mueller and Luca Massaron provide a list of some common use cases of algorithms:

  1. Searching
    eg: finding a particular web page in the sea of web pages on the internet
  2. Sorting
    Sorting information or data is arranging in an ordered sequence.
    eg: when you arrange items on e-commerce sites in increasing order of price
  3. Transforming:
    Conversion of one sort of data to another
    eg: Shunting Yard Algorithm is used to convert an infix expression to postfix expression
  4. Scheduling
    According to Wikipedia, scheduling¬†is the method by which work is assigned to resources that complete the work. If it weren’t for scheduling algorithms, then your operating system wouldn’t have been able to efficiently allocate resources for specific tasks at the right times or run multiple tasks at the same time.
    eg: in the Shortest Remaining Time algorithm, the process will be allocated to the task which is closest to its completion
  5. Graph Analysis
    A graph is a non-linear data structure comprised of nodes and edges (which connect a pair of nodes). Graphs have innumerable real-life applications: social networks, recommendation engines, etc.
    eg: The breadth-first-search algorithm is used to find the shortest path between two nodes. An application of this could be the shortest route between a source and destination on Google Maps.
  6. Cryptography
    Encryption is a process of encoding messages to keep them secret, so only “authorized” parties can access the message. This is an important concept for the safe transfer of data between systems and protection against attacks and malicious penetration. Algorithms exist which analyze information and encrypt/decrypt the information.
    eg: Message Authentication Codes (MACs) can be used in providing authentication for the origin/source and integrity of messages.
  7. Pseudorandom Number Generation
    These algorithms use mathematical formulas to produce sequences of random numbers.
    eg: electronic games and simulations

This list is a tiny glimpse into the types of algorithms out there. New algorithms are made everyday and existing algorithms are continuously modified. The job of computer programmers is to identify which algorithms are suited for their projects or work.

*************************

Important resource: Here’s a list of algorithms: https://en.wikipedia.org/wiki/List_of_algorithms

Want to join on my learning journey? Feel Free to subscribe!

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: