×
Home Discussions Write at Opengenus IQ
×
  • DSA Cheatsheet
  • HOME
  • Track your progress
  • Deep Learning (FREE)
  • Join our Internship 🎓
  • RANDOM
  • One Liner

Algorithms

Algorithms have proven to be the most important domain over the last century which has reformed the way we do tasks. It is actively used to design industry systems and forms the building blocks of companies like Google. We cover all types of algorithms in depth

Algorithms

Divide numbers from 1 to n into two groups with minimum sum difference from O(2^N) to O(N)

For numbers from 1 to given n, we have to find the division of the elements into two groups having minimum absolute sum difference. We will explore two techniques Brute force which will take O(2^N) time complexity and Greedy algorithm which will take O(N) time complexity

Arvind Tatiparti
Algorithms

Using Bron Kerbosch algorithm to find maximal cliques in O(3^(N/3))

Bron–Kerbosch algorithm is an enumeration algorithm for finding maximal cliques in an undirected graph. Any n-vertex graph has at most 3^n⁄3 maximal cliques, and the worst-case running time of the Bron–Kerbosch algorithm (with a pivot strategy) is O(3^n⁄3).

Sadanand Vishwas Sadanand Vishwas
Algorithms

Centroid Decomposition of Tree

Centroid Decomposition is a divide and conquer technique which is used on trees. Given a tree with N nodes, a centroid is a node whose removal splits the given tree into a forest of trees, where each of the resulting tree contains no more than N/2 nodes.

Sadanand Vishwas Sadanand Vishwas
Algorithms

Clique in Graphs

A clique is a subset of vertices of an undirected graph G such that every two distinct vertices in the clique are adjacent; that is, its induced subgraph is complete. Cliques are one of the basic concepts of graph theory and are used in many other mathematical problems and constructions on graphs.

Sadanand Vishwas Sadanand Vishwas
Algorithms

Solving Vertex Cover Problem from O(2^n) to O(n^2)

Vertex Cover Problem is a known NP Complete problem. We will see Naive approach and Dynamic programming approach to solve the vertex cover problem for a binary tree graph and reduce the complexity from O(2^n) to O(n^2).

Sadanand Vishwas Sadanand Vishwas
Algorithms

Understanding pairing nodes in Graphs (Maximum Matching)

A maximal matching is a matching M of a graph G with the property that if any edge not in M is added to M, it is no longer a matching, that is, M is maximal if it is not a subset of any other matching in graph G. We cover Blossom, Hungarian and Hopcroft Karp algorithm

Sadanand Vishwas Sadanand Vishwas
Algorithms

Blossom Maximum Matching Algorithm

The blossom algorithm, sometimes called the Edmonds' matching algorithm, can be used on any graph to construct a maximum matching. The blossom algorithm improves upon the Hungarian algorithm by shrinking cycles in the graph to reveal augmenting paths. The blossom algorithm will work on any graph.

Sadanand Vishwas Sadanand Vishwas
Algorithms

Hungarian Maximum Matching Algorithm

The Hungarian maximum matching algorithm, also called the Kuhn-Munkres algorithm, is a O(V3) algorithm that can be used to find maximum-weight matchings in bipartite graphs, which is sometimes called the assignment problem. A bipartite graph can easily be represented by an adjacency matrix

Sadanand Vishwas Sadanand Vishwas
Algorithms

Hopcroft Karp algorithm

The Hopcroft–Karp algorithm is an algorithm that takes as input a bipartite graph and produces as output a maximum cardinality matching, it runs in O(E√V) time in worst case.

Sadanand Vishwas Sadanand Vishwas
Algorithms

Pigeonhole Sort

Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements and the number of possible key values are approximately the same.

Harshita Sahai Harshita Sahai
Algorithms

Cocktail Shaker Sort / Bidirectional bubble sort

Cocktail Sort is a variation of Bubble sort. The Bubble sort algorithm always traverses elements from left and moves the largest element to its correct position in first iteration and second largest in second iteration and so on. It traverses through a given array in both directions alternatively.

Harshita Sahai Harshita Sahai
Algorithms

Odd Even Sort / Brick Sort

Odd Even Sort uses parallel algorithm which is based on bubble sort technique. It is also known as Brick Sort. It has a best time complexity of O(N) whereas the worst case time complexity is O(N^2)

Harshita Sahai Harshita Sahai
Algorithms

Number of unique partitions of an integer

Given a positive integer, the problem is to find all the Unique Partitions of the number. We can understand the above problem using some basic examples. Naive approach takes O((N^N)log N) time complexity while Dynamic programming takes O(2^N)

Sajal Tikariha
Algorithms

Number of non unique Partitions of an Integer

The problem is to find number of non unique partitions of an integer. To solve this problem, we will explore naive approach O(N^N), Dynamic programming approach O(N^2) and Optimal approach O(log N)

Sajal Tikariha
Algorithms

Hamiltonian Cycle

A Circuit in a graph G that passes through every vertex exactly once is called a "Hamilton Cycle". The Worst Case complexity when used with DFS and back tracking is O(N!).

Avijit Chakraborty
Algorithms

Hamiltonian Path

Hamiltonian Path is a path in a directed or undirected graph that visits each vertex exactly once. The problem to check whether a graph (directed or undirected) contains a Hamiltonian Path is NP-complete, so is the problem of finding all the Hamiltonian Paths in a graph.

Harshita Sahai Harshita Sahai
Algorithms

Tile Stacking Problem

We demonstrate how we will reduce the time complexity from O((k+1)^(m+1)) to O(N * M * K) to O(N * M). We have infinite number of tiles of sizes 1 to m. The task is calculate the number of different stable tower of height n with restriction that you can use at most k tiles of each size in the tower

Sadanand Vishwas Sadanand Vishwas
Algorithms

Sleep Sort

Sleep Sort is time-based sorting technique. We create different threads for each individual element present in the array. The thread is then made to sleep for an amount of time that is equal to value of the element for which it was created. Time complexity is O(NlogN + max(input))

Lakshmi Angadi Lakshmi Angadi
Algorithms

Distance between two points in 2D space

Distance between two points is calculated by creating a right-angled triangle using the two points.The line between the two points is the hypotenuse (the longest side, opposite to the 90° angle). We used the Distance formula derived from Pythagorean theorem with a time complexity of O((log N)^2)

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Area of Polygon: Shoelace formula

Given coordinates of vertices of polygon, Area of Polygon is calculated using Shoelace formula described by Mathematician and Physicist Carl Friedrich Gauss where polygon vertices are described by their Cartesian coordinates in the Cartesian plane. The time complexity is O(N) with O(1) space

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Extended Euclidean Algorithm

We will demonstrate Extended Euclidean Algorithm. We will see how you can calculate the greatest common divisor in a naive way which takes O(N) time complexity which we can improve to O(log N) time complexity using Euclid's algorithm. Extended Euclidean Algorithm takes O(log N) time complexity

Arunesh Sarker
Algorithms

Multiple array range increments in linear time O(N)

Given an array a containing N integers, we perform M queries. Each query has three values START, END and a value D. For each query, the problem is to increment the values from the start to end index(both inclusive) in the given array by the given value d. An efficient algorithm takes O(N+M) time

Arvind Tatiparti
Algorithms

Sieve of Atkin

Sieve of Atkin is an algorithm used to find all prime numbers upto a given number (say N) and does so in O(N) time complexity. With a modified version with enumerating lattice points variation, the time complexity goes to O(N / log log N). It is computationally efficient than Sieve of Eratosthenes

Drishti singh
Algorithms

Area of Triangle: Heron's formula

We take a look at Heron's formula which will enable us to calculate the area of any triangle given the length of the three sides of that triangle. The advantage is that the area is calculated using arithmetic operations and hence, the time taken can be assumed to be constant,

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Circle Sort

Circle sort is a sorting algorithm in which diametrically opposite elements are compared to each other and swapped with an average time complexity of O(N log N) and space complexity of O(1). It is an unstable, recursive, parallelizable, in place sorting algorithm

Ankur Sanodiya
OpenGenus IQ © 2025 All rights reserved ™
Contact - Email: team@opengenus.org
Primary Address: JR Shinjuku Miraina Tower, Tokyo, Shinjuku 160-0022, JP
Office #2: Commercial Complex D4, Delhi, Delhi 110017, IN
Top Posts LinkedIn Twitter
Android App
Apply for Internship