Sitemap

14 Important Algorithms

3 min readSep 8, 2022

--

Here’re the most common algorithms every programmer should be familiar with!

Let’s take a closer look at them 👀

1) Binary Search

Checks each array element for the target value until a match is found!!

Pros

  • It is a much faster algorithm
  • It is efficient
  • It is a simple algorithm to understand

Cons

  • It can be used only when data is sorted

2) Breadth First Search (BFS)

Explores the neighbor nodes (graph) before moving to the next-level ones

Pros

  • It will find the solution at any cost if there is one!!
  • Solution with minimal cost can be found by BFS if there are multiple solutions in the question

Cons

  • Takes time to execute
  • Memory consumption is more

Application Of BFS:-

  • Use to find the shortest path

3) Depth First Search (DFS)

Explores nodes as far as possible along each branch before backtracking

Pros

  • Time and Space complexity is less as compared to BFS

Cons

  • Not sure that it’ll give you the result

Application Of DFS:-

  • Use to find path b/w two given vertices

4) In, Pre, Postorder Tree Traversals

Iterative and Recursive solutions to traverse the tree data structure

Tree Traversals

Tree Data Structure

⭐Inorder Traversal

It goes like Left -> Root -> Right

SO (4->2->5->1->3)

Use of Inorder:-

Inorder traversal gives nodes in non-decreasing order

⭐Preorder Traversal

It goes like Root -> Left -> Right

Get Rahul Das’s stories in your inbox

Join Medium for free to get updates from this writer.

So (1->2->4->5->3)

Use of Preorder:-

Preorder traversal is used to create a copy of the tree.

⭐Postorder Traversal

It goes like Left -> Right -> Root

So (4->5->2->3->1)

Use of Postorder:-

Postorder traversal is used to delete the tree

5) Insertion, Selection, Merge, Quick, Counting, Heap Sort

These algorithms effectively sort given array using different techniques

Link for more knowledge about sorting algorithm:-

Insertion Sort

Selection Sort

Merge Sort

Quick Sort

Counting Sort

Heap Sort

6) Kruskal’s Algorithm

Constructs a minimum spanning tree out of a connected, weight graph.

7) Floyd Warshall Algorithm

Returns the shortest paths b/w every pair of vertices in the graph.

8) Dijkstra’s Algorithm

It is an algorithm for finding the shortest paths b/w nodes in a graph.

9) Bellman Ford Algorithm

Unlike Dijkstra’s Algorithm, it can handle the edges of the negative weight in the graph

10) Kadane’s Algorithm

Finds a contiguous subarray within an array that has the largest sum

11) Lee Algorithm

It is one possible solution for maze routing problems

12) Flood Fill Algorithm

Determines the area connected to a given node in a multi-dimensional array

13) Topological Sorting in a Directed Acyclic Graph

Is a linear ordering of vertices of a directed graph that is for Directed Acyclic Graph(DAG)

14) Union Find Algorithm

Works with a disjoint-set data structure to perform some operation

2 useful operations are:-

  • Find- This can be used for determining if two elements are in the same subset
  • Union- Join two subsets into a single subset

Thanks for reading 🙏🏻😇

Rahul

--

--

Rahul Das
Rahul Das

Written by Rahul Das

Am I not supposed to insert pretentious hypes here?