Articles on Trending Technologies

Technical articles with clear explanations and examples

Aliquot Sequence in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 483 Views

Aliquot sequence is a special sequence of numbers. The sequence starts from the number itself and the next number of the sequence is the sum of the proper divisors of the previous terms.Let’s take an example of the sequence to learn the concept better −Input : 8 Output : 8 7 1 0 Explanation :    Proper divisors of 8 are 4, 2, 1. The sum is 7    Proper divisors of 7 are 1. The sum is 1    Proper divisors of 1 are 0. The sum is 0Perfect number is the number that has the aliquot sequence of ...

Read More

Anonymous classes in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 3K+ Views

Anonymous entity is anything that is defined without a name. A class with no name provided is known as an anonymous class in c++. An anonymous class is a special class with one basic property.As there is no name given to the class there is no constructor allocated to it, though a destructor is there for deallocating the memory block.The class cannot be used as an element of a function i.e. you cannot pass it as an argument or cannot accept values return from the function.The syntax for defining an anonymous class in c++class {    //data members    // ...

Read More

Bernoulli Distribution in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 506 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

Adding elements of an array until every element becomes greater than or equal to k in C++.

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 291 Views

Array − An array is a container of elements of the same data type, whose elements are 0 indexed.In this problem, we will use an array of integers. And check if all the elements are greater than the given number or not. Here we will check if all elements of the array are greater than or equal to a given number k. If not then we will add two minimum elements of the array and treat this sum as a single element. And then again check for the same condition for the new array. If the condition comes out to ...

Read More

Binomial Distribution in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 527 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

C++ Program for Cocktail Sort?

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

The Cocktail sort is another variation of bubble sort. In the bubble sort technique, it always searches from left to right, and finds the largest element at the end, in the second phase it finds the second largest element at the second last position. This sorting technique traverses in both directions alternatively. Let us see the algorithm to understand the idea.Algorithmcocktail(array, n)Begin    flag := true    start := 0, end := n-1    while flag is set, do       flag := false       for i in range start to end-1, do         ...

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

Alternate sorting of Linked list in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 421 Views

A linked list is a linear data structure that stores elements and also stores a pointer to the next data node.In this problem on the sorting of a linked list, the alternate sort means sorting in such a way that the 1st node contains data with the minimum value, the 2nd node contains data with maximum value, 3rd with the next minimum (second minimum value) and so on. This pattern of alternate maxima and minimas is created in alternate sorting of linked lists.Let’s take an example to understand the problem better −Input : 3 > 4 > 21 >67 > ...

Read More

Alternative Sorting in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 899 Views

Sorting the elements of an integer array in such a way that the first element is the maximum of the array and the second element of the sorted array is the minimum, the third one is the second minimum, the fourth one is the second maximum of the array and goes on.Let’s take an example to understand the concept better, Input : 4 1 8 2 9 3 7 Output : 9 1 8 2 7 3 4 Explanation : The elements in a sorted way is 1 2 3 4 7 8 9. Now, let’s create it in ...

Read More

C++ Program for Gnome Sort?

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

Here we will see how the gnome sort works. This is another sorting algorithm. In this approach if the list is already sorted it will take O(n) time. So best case time complexity is O(n). But average case and worst case complexity is O(n^2). Now let us see the algorithm to get the idea about this sorting technique.AlgorithmgnomeSort(arr, n)begin    index := 0    while index < n, do       if index is 0, then          index := index + 1       end if       if arr[index] >= arr[index -1], then ...

Read More
Showing 28801–28810 of 61,297 articles
Advertisements