Algorithms Articles

Found 386 articles

Difference between JPEG and PNG

Mahesh Parahar
Mahesh Parahar
Updated on 14-Mar-2026 9K+ Views

JPEG and PNG are two widely used image file formats. JPEG uses a lossy compression algorithm, which reduces file size by discarding some image data. PNG uses a lossless compression algorithm, preserving all original image data without any quality loss. JPEG (Joint Photographic Experts Group) JPEG is best suited for photographs and images with smooth color gradients. It achieves smaller file sizes by discarding image data that the human eye is less likely to notice. The compression level is adjustable − higher compression means smaller files but more quality loss. JPEG does not support transparency. PNG (Portable ...

Read More

Matrix multiplication algorithm

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 27K+ Views

In this section we will see how to multiply two matrices. The matrix multiplication can only be performed, if it satisfies this condition. Suppose two matrices are A and B, and their dimensions are A (m x n) and B (p x q) the resultant matrix can be found if and only if n = p. Then the order of the resultant matrix C will be (m x q).AlgorithmmatrixMultiply(A, B): Assume dimension of A is (m x n), dimension of B is (p x q) Begin    if n is not same as p, then exit    otherwise define C ...

Read More

Operations on an Array in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Here we will see some basic operations of array data structure. These operations are −TraverseInsertionDeletionSearchUpdateThe traverse is scanning all elements of an array. The insert operation is adding some elements at given position in an array, delete is deleting element from an array and update the respective positions of other elements after deleting. The searching is to find some element that is present in an array, and update is updating the value of element at given position. Let us see one C++ example code to get better idea.Example#include #include using namespace std; main(){    vector arr;    //insert elements   ...

Read More

Binary Tree Traversals in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

In this section we will see different traversal algorithms to traverse keys present in binary search tree. These traversals are Inorder traversal, Preorder traversal, Postorder traversal and the level order traversal.Suppose we have one tree like this −The Inorder traversal sequence will be like − 5 8 10 15 16 20 23The Preorder traversal sequence will be like − 10 5 8 16 15 20 23The Postorder traversal sequence will be like − 8 5 15 23 20 16 10The Level-order traversal sequence will be like − 10, 5, 16, 8, 15, 20, 23AlgorithminorderTraverse(root): Begin    if root is not ...

Read More

Level Order Tree Traversal in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 579 Views

In this section we will see the level-order traversal technique for binary search tree.Suppose we have one tree like this −The traversal sequence will be like: 10, 5, 16, 8, 15, 20, 23AlgorithmlevelOrderTraverse(root): Begin    define queue que to store nodes    insert root into the que.    while que is not empty, do       item := item present at front position of queue       print the value of item       if left of the item is not null, then          insert left of item into que       end ...

Read More

Bernoulli Distribution in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 487 Views

The Bernoulli Distribution is a discrete distribution having two possible outcomes labeled by x = 0 and x = 1. The x = 1 is success, and x = 0 is failure. Success occurs with probability p, and failure occurs with probability q as q = 1 – p. So$$P\lgroup x\rgroup=\begin{cases}1-p\:for & x = 0\p\:for & x = 0\end{cases}$$This can also be written as −$$P\lgroup x\rgroup=p^{n}\lgroup1-p\rgroup^{1-n}$$Example#include #include using namespace std; int main(){    const int nrolls=10000;    default_random_engine generator;    bernoulli_distribution distribution(0.7);    int count=0; // count number of trues    for (int i=0; i

Read More

Binomial Distribution in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 504 Views

The Binomial Distribution is a discrete probability distribution Pp(n | N) of obtaining n successes out of N Bernoulli trails (having two possible outcomes labeled by x = 0 and x = 1. The x = 1 is success, and x = 0 is failure. Success occurs with probability p, and failure occurs with probability q as q = 1 – p.) So the binomial distribution can be written as$$P_{p}\lgroup n\:\arrowvert\ N\rgroup=\left(\begin{array}{c}N\ n\end{array}\right) p^{n}\lgroup1-p\rgroup^{N-n}$$Example#include #include using namespace std; int main(){    const int nrolls = 10000; // number of rolls    const int nstars = 100; // maximum ...

Read More

Convex Hull Example in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Here we will see one example on convex hull. Suppose we have a set of points. We have to make a polygon by taking less amount of points, that will cover all given points. In this section we will see the Jarvis March algorithm to get the convex hull.Jarvis March algorithm is used to detect the corner points of a convex hull from a given set of data points.Starting from left most point of the data set, we keep the points in the convex hull by anti-clockwise rotation. From a current point, we can choose the next point by checking ...

Read More

Activity Selection Problem

Ravi Ranjan
Ravi Ranjan
Updated on 21-Jul-2025 9K+ Views

Activity Selection Problem The activity selection problem is an example of a greedy algorithm where the maximum number of non-overlapping activities are selected from the given activity set. A person can complete one activity at a time. The activities are given in the form of their starting and completion times. In this article, we have an array of integers that stores the starting and completion time of each activity. Our task is to select the maximum number of non-overlapping activities from the given activity array. Scenario An example of the maximum activity ...

Read More

Partitioning Method (K-Mean) in Data Mining

sudhir sharma
sudhir sharma
Updated on 22-Jan-2024 7K+ Views

The present article breaks down the concept of K-Means, a prevalent partitioning method, from its algorithmic framework to its pros and cons, helping you better grasp this sophisticated tool. Let's dive into the captivating world of K-Means clustering! K-Means Algorithm The K-Means algorithm is a centroid-based technique commonly used in data mining and clustering analysis. How K-Means Works? The K-Means Algorithm, a principle player in partitioning methods of data mining, operates through a series of clear steps that move from basic data grouping to detailed cluster analysis. Initialization − Specify the number of clusters 'K' to be created. This ...

Read More
Showing 1–10 of 386 articles
« Prev 1 2 3 4 5 39 Next »
Advertisements