×
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

Conversion of Infix to Postfix Expression using Stack

To convert Infix expression to Postfix expression, we will use the stack data structure. By scanning the infix expression from left to right,if we get any operand, simply add it to the postfix form, and for the operator and parenthesis, add them in the stack maintaining the precedence of them.

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Binary Lifting with k-th ancestor and lowest common ancestor (LCA)

Binary Lifting is a technique used to find the k-th ancestor of any node in a tree in O(log N). This also leads to a faster algorithm in finding the lowest common ancestor (LCA) between two nodes in a tree. The technique requires preprocessing the tree in O(N log N) using dynamic programming.

Arshad G
Algorithms

Bipartite checking using Graph Colouring and Breadth First Search (BFS) [O(V+E) time]

The algorithm to determine whether a graph is bipartite or not uses the concept of graph colouring and BFS and finds it in O(V+E) time complexity on using an adjacency list and O(V^2) on using adjacency matrix. It is used to decode codewords and model situations in cloud computing and big data

Isha Gautam
Algorithms

Topological Sorting using Depth First Search (DFS)

We will implement Topological sorting using Depth First Search in linear time O(V+E). Topological Sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. It is useful in instruction scheduling and other

Saranya Jena Saranya Jena
Algorithms

String hashing

Hashing is an important technique which converts any object into an integer of a given range. Hashing is the key idea behind Hash Maps which provides searching in any dataset in O(1) time complexity. An efficient algorithm to hash a string is used to compare strings in O(1) time complexity

OpenGenus Tech Review Team OpenGenus Tech Review Team
Algorithms

Fermat's little theorem, a Probabilistic test for Primality

One of the most popular probabilistic algorithm for determining if a number is prime or not is based on Fermat's little theorem. The complexity of the algorithm is O(K log N) and fails only for Carmichael numbers which are composite numbers satisfying fermat little theorem starting with 561

Aswin G
Algorithms

Expectation Maximization Clustering Algorithm

Expectation Maximization Clustering algorithm is much more robust than K-Means, as it uses two parameters, Mean and Standard Deviation to define a particular cluster. This simple addition of calculating the Standard Deviation, helps the EM algorithm do well in a lot of fail cases of K-Means

Jash Sheth
Algorithms

Mean Shift Clustering Algorithm

Mean Shift clustering is an unsupervised clustering algorithm that groups data directly without being trained on labelled data. It is hierarchical in nature. It starts off with a kernel, which is basically a circular sliding window. The bandwidth the radius of this sliding window is pre-decided

Jash Sheth
Algorithms

Cartesian tree sorting

Cartesian tree sorting, also called Levcopoulos Petersson algorithm is an adaptive sorting algorithm, i.e. it performs much better on a partially sorted data. It needs two data structures a Cartesian tree and a priority queue. The algorithm here uses min-heap Cartesian tree to give a sorted sequence

Yash Aggarwal Yash Aggarwal
Algorithms

Activity Selection Problem using Greedy algorithm

For activity selection, Dynamic Programming Approach takes O(n^3) time while Greedy Approach takes O(N) time when unsorted and O(n log n) when sorted. It follows Greedy approach as at every step, we make a choice that looks best at the moment to get the optimal solution of the complete problem

Shreya Singh
Algorithms

Tarjan's Algorithm to find Strongly Connected Components

Tarjan's Algorithm is an efficient graph algorithm to find the strongly connected components in a directed graph in linear time by utilizing Depth First Search traversal of a graph. The key idea used is that nodes of strongly connected component form a subtree in the DFS spanning tree of the graph.

Pradyumn
Algorithms

Cycle Sort

Cycle sort is a comparison based sorting algorithm which forces array to be factored into the number of cycles where each of them can be rotated to produce a sorted array with O(N^2) time complexity It is an in-place and unstable sorting algorithm and is optimal in terms of number of memory writes

Kavita Bisht
Algorithms

Fibonacci Search

Fibonacci search is an efficient search algorithm based on divide and conquer principle using Fibonacci series that can find an element in the given sorted in O(log N) time complexity. It is better than Binary search as it is more cache friendly and uses only addition and subtraction operations.

Harshita Sahai Harshita Sahai
Algorithms

Bresenham Line Drawing Algorithm

Bresenham line drawing Algorithm is a Line Drawing Algorithm which calculates all intermediate points over the interval between start and end points, implemented with integer numbers and integer arithmetic such as addition, subtraction and avoids heavy operations like multiplication and division

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Sorting Algorithms

Comb Sort

Comb sort is a comparison based sorting algorithm and is an improvement to Bubble Sort by using the idea of killing the turtles. In Bubble Sort algorithm, the gap between the elements that are compared is always 1. Comb sort works on the same principles as Bubble Sort but uses a larger gap.

Shreya Singh
Dynamic Programming (DP)

Longest Bitonic Sequence

The problem we will solve is given a sequence an array of positive integers and have to find the length of longest bitonic subsequence. Using dynamic programming ideas, we will solve this on O(N^2) time complexity

Tanya Anand Tanya Anand
Sorting Algorithms

Heap Sort

Heapsort is an efficient in-place comparison based sorting algorithm with O(N log N) time complexity and uses a data structure to achieve it. It uses a complete Binary Heap data structure to sort the elements depending on whether the heap is Min Heap (ascending) or Max heap (descending).

P Arun Kumar P Arun Kumar
Sorting Algorithms

Radix Sort

Radix Sort is an efficient non-comparison based sorting algorithm which can sort a dataset in linear O(N) time complexity and hence, can be better than Quick Sort. It uses Counting Sort as a subroutine. It uses the fact that number of digits in an Integer is very less compared to the data

Kavita Bisht
Sorting Algorithms

Counting Sort

Counting sort is an algorithm for sorting integers in linear time. It can perform better than other efficient algorithms like Quick Sort, if the range of the input data is very small compared to the number of input data. It is a stable, non-comparison and non-recursive based sorting

Rohit Kumar Rohit Kumar
Algorithms

DDA (Digital Differential Analyzer) Line Drawing Algorithm

Digital differential analyzer is a line drawing algorithm that is based on incremental method which calculates all intermediate points over the interval between start and end points. It uses the concept that rate of change in a straight line in constant and is a linear time complexity O(N) algorithm

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Sorting Algorithms

Bucket Sort Algorithm

Bucket sort is a comparison sort algorithm that works by distributing the elements of an array into a number of buckets and then each bucket is sorted individually using a separate sorting algorithm. It is useful when the input is uniformly distributed over a range in linear time complexity

Saranya Jena Saranya Jena
Algorithms

Bresenham’s Circle Drawing Algorithm

Bresenham’s Circle Drawing Algorithm is a circle drawing algorithm that selects the nearest pixel position to complete the arc. The unique part of this algorithm is that is does only integer arithmetic which makes it faster than other algorithms using floating point arithmetic

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Cohen Sutherland Line Clipping Algorithm

Cohen Sutherland Algorithm is a linear time complexity line clipping algorithm that cuts lines to portions which are within a rectangular area. It eliminates the lines from a given set of lines which belongs outside the area of interest and clip those lines which are partially inside

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Number of arithmetic progression subsequences in a given set of numbers

The problem is that given an array of n positive integers. The task is to count the number of Arithmetic Progression subsequence in the array. This can be solved using dynamic programming in linear time complexity.

Tanya Anand Tanya Anand
Algorithms

Find the Longest Arithmetic Progression using Dynamic Programming

The problem we will solve is that given a set of integers in sorted order, find length of longest arithmetic progression in that set. This can be solved by brute force in O(N^3) while a dynamic programming approach with take O(N^2) time complexity.

Tanya Anand Tanya Anand
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