# 5 Algorithms that Software Engineers Should Know

Algorithms are the building blocks of programming, yet there is this common notion that you can be a software engineer without learning them. While most programming languages today have the ability to implement algorithms without coding, understanding how to create certain algorithms is more than necessary.

Giant companies like *Facebook & Google* have been using complicated algorithms for targeting ads based on specific criteria and interests. Lately, Facebook has been sued by the US Department of Housing and Urban Development for targeting ads based on race, gender, and religion. While it promised to change this, its algorithm did the same thing, anyway.

The direct impact of not understanding algorithms also affects businesses. Ayima’s Kickstart guide to digital marketing covers in detail how Google’s ranking algorithms favor large brands, this means that it is much harder for smaller businesses to get noticed. Essentially, algorithms are directly affecting a lot of different industries.

So, whether you’re a seasoned or an aspiring software engineer, here are five algorithms that you should know by heart:

#### 1. Tree Traversal

Trees are an abstract data type that is nonlinear and organized through relationships or hierarchies. A tree traversal algorithm is a process of visiting every node in a tree at least once. There are two general types of tree traversal algorithms:

- Breadth First Search: This algorithm traverses the tree data structure layer by layer starting from the top root node. It traverses all the nodes of the
*nth*layer before moving to the*nth+1*layer, it’s normally used to find the shortest path of 2 nodes. Typical examples of this algorithm:*Navigation systems, Search Engine Crawlers, Peer to Peer networks*. - Depth First Search: This algorithm also starts from the root node, however, it goes as deep as possible down one path before backing up and trying a different one. It’s like walking through a corn maze, you explore one path, hit a dead end, and go back and try a different one. Typical examples of this algorithm:
*Solving puzzle which has only one solution, Topological sorting*.

#### 2. Recursive Algorithms

Recursive algorithms are functions that call itself directly or indirectly until the base condition is true. The idea in recursive algorithms is to turn a problem into smaller problems and include a base condition that stops the recursion. It simplifies your traversal code, makes it cleaner and gets rid of code repetition.

#### 3. Sorting Algorithms

One of the most fundamental algorithms a developer must understand is sorting. This algorithm rearranges a given array or list according to a comparison operator. There are tons of sorting algorithms and every one of them is different in terms of speed, complexity, and efficiency.

Bubble Sort is one of the most commonly used algorithms, as it’s simple and easy to implement, but it can become slow as the arrays get longer. Choosing which to use largely depends on the volume and the structure of your array.

#### 4. Hashing Algorithms

Hashing algorithms convert input values like a string, or your password for example, to a compressed numerical value – also known as a hash value. These algorithms are mostly used for public encryption keys to secure a string from being uncovered by brute force. For example, BlockGeeks’s guide to hashing shows how the cryptocurrency Bitcoin uses an SHA-256 hashing algorithm that converts inputs in 256 numerical characters.

This secures the cryptocurrency by making it almost impossible for hackers to determine the original input from the public key.

#### 5. Shortest Path Algorithms

These algorithms are used to find a path between two vertices or nodes in a graph. The commonly used one is *Dijkstra’s* algorithm. This algorithm is used in undirected and weighted graphs which has values on its edges. It’s based on the principle of relaxation where the approximated distance is gradually replaced until the actual shortest distance is reached. What’s great about Dijkstra’s algorithm is that you only have to use it once and you can revisit the results over and over.

Software engineers who understand the basics of algorithms produce efficient and maintainable code which improves a team’s SDLC. While it’s important to memorize these algorithms, understanding how they solve real-world problems is more valuable. When you’re familiar with picturing complex scenarios in terms of simple data structures, coding will come naturally.

## Leave a Reply