REVIEWED BY
Jye Sawtell-Rickson | Jan 05, 2023

An algorithm is a set of instructions implemented by software engineers and data scientists to transform input data into output data through a computational series of arithmetic, decision making and repetition. Algorithms provide computers with a series of instructions that transform data into usable knowledge. Every algorithm is essentially trying to make a decision, often as part of a series of decisions, to ensure a computational input is processed and transmitted as usable data based on the task it’s trying to accomplish.

3 Examples of Algorithms

  1. Binary search algorithms take sorted arrays of data and return the index of the value for which you’ve searched. Essentially, this type of algorithm determines where a value exists within a specific set of data or if it exists within the data set at all.
  2. Merge sort algorithms operate in a divide-and-conquer manner, similar to binary search. Where the two differ, however, is that merge sorting separates all elements into individual elements, continuing until every individual element exists in an index of its own, and then merges the elements and sorts them in an understandable order based on the input.
  3. Adding/removing items from a linked list means you can restructure linked lists so that nodes can be inserted or deleted from a specific location. Engineers and computer scientists can locate exactly where the node that needs to be inserted or removed is located as well as the pointers where the desired change should be rearranged.

 

How Does an Algorithm Work?

An algorithm consists of a series of three steps: the input, the computation and the output.

An input is the data that is fed into an algorithm to begin the computation process.

The computation process then applies arithmetic, decision making and repetition to create “if x, then y” equations to ensure only the proper data is fed through to the output. Many algorithms use machine learning to use past knowledge in computational decision making.

The output process is the algorithm’s expression of its conclusion. This can be in the form of information displayed to a user, or much more commonly, as more data that becomes the input for another algorithm in a string of processes that enable a computer to make complex decisions in real time.

What’s an Algorithm? - David J. Malan | Video: TED-Ed

Related Reading on Built InWhy Is Logistic Regression a Classification Algorithm?

 

What Are Some Examples of an Algorithm?

Three key algorithms commonly used include binary search, merge sort and adding/removing from a linked list.

 

Binary Search

Binary search algorithms take sorted arrays of data and return the index of the value for which you’ve searched. Essentially, this type of algorithm determines where a value exists within a specific set of data or if it exists within the data set at all. There are five steps this algorithm will perform in its search:

  1. It finds the midpoint of the sorted array.
  2. It compares the midpoint of the data to the value being searched.
  3. The algorithm then searches the right half of the array if the midpoint is larger than the value.
  4. If the midpoint is smaller than the value, it will search the left half of the array.
  5. Finally, the steps repeat until the algorithm finds the midpoint value or determines it doesn’t exist in the data set.
Find out who's hiring.
See all Data + Analytics jobs at top tech companies & startups
View 2931 Jobs

 

Merge Sort

Merge sort algorithms operate in a divide-and-conquer manner, similar to binary search. Where the two differ, however, is that merge sorting separates all elements into individual elements, continuing until every individual element exists in an index of its own, and then merges the elements and sorts them in an understandable order based on the input.

Merge sort algorithms manage both the dividing and merging processes simultaneously to provide faster results to the user.

 

Adding/Removing From a Linked List

Linked lists utilize nodes and pointers as opposed to arrays, which allows some processes to perform much more efficiently. Nodes house a piece of data and a pointer that directs it to the next node, allowing data to consistently feed in a specific direction.

Linked lists can be restructured so that nodes can be inserted or deleted from a specific location. Engineers and computer scientists can locate exactly where the node that needs to be inserted or removed is located as well as the pointers where the desired change should be rearranged, allowing items to be removed from the middle of a collection without having to shift the remainder of the data structure in memory. This makes for more efficient insertions and deletions.

More on Lists From Built In ExpertsHow to Append Lists in Python

 

What Is the Best Way to Analyze an Algorithm?

In order to ensure an algorithm is as efficient as possible, there are several methods of analysis that check execution speed and memory usage across several use cases.

Algorithm analysis begins with counting the number of operations needed to determine an answer across different input variables. For example, a linear search algorithm, which searches for values in a list, will check every value on a given list to see if it matches the target value. Once the value is found, it immediately returns to the index. If no value is found, the equation returns -1.  The number of checks necessary to find the target value will determine the execution speed of the algorithm. This execution speed will vary depending on the target value and the values present in the list, so several values should be checked to determine a relative average speed.

Other variables are necessary to determine the actual running speed of an algorithm, such as the speed of the computer, the programming language and the translation of that language into machine code. To get an accurate measurement of how an algorithm will run on a particular device, it must be made to run. This is possible by implementing the algorithm in an actual programming language, and in JavaScript, using the searchList function. This function will tell the amount of time it takes an algorithm to search a specific length of numbers in a list in milliseconds. By measuring the efficiency of different types of algorithms for a given set of values, programmers and data scientists can determine the best algorithm to use for specific use cases.

Expert Contributors

Built In’s expert contributor network publishes thoughtful, solutions-oriented stories written by innovative tech professionals. It is the tech industry’s definitive destination for sharing compelling, first-person accounts of problem-solving on the road to innovation.

Learn More

Great Companies Need Great People. That's Where We Come In.

Recruit With Us