Whether you dabble in data, have an existing degree, or are brand new to the discipline, this data science course is for you. No matter where you are in your career, our course takes you from foundational…

## Algorithm

- FAQ
- Courses
- Certifications
- Careers
- Jobs
- Companies
- Skills
- Articles

# What Is an Algorithm?

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

**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.**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.**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 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:

- It finds the midpoint of the sorted array.
- It compares the midpoint of the data to the value being searched.
- The algorithm then searches the right half of the array if the midpoint is larger than the value.
- If the midpoint is smaller than the value, it will search the left half of the array.
- Finally, the steps repeat until the algorithm finds the midpoint value or determines it doesn’t exist in the data set.

**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.

## 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.

## Expand Your Algorithm Career Opportunities

Boost your skill set and develop by learning more about algorithms with Udemy.

## Algorithm Certifications + Programs

These top software engineering certifications from Udacity could be the key to taking your next step.