In this problem, we are given an array of n elements. Our task is to create a program to count the number of operations to equalize an array using elements only.We need to count the number of adding or subtraction operations that will be performed to make all the elements of the array equal.Let’s take an example to understand the problem, Input: arr[] = {4, 0, 3, 1, 2}Output: 3Explanation: The equal value will be 2.The overall sum will be the same. We will be taking 1 from value at arr[3] and then adding it to value at arr[1].Then we will take 2 ... Read More
In this problem, we are given the coordinates of a polygon. Our task is to create a program to check whether the given polygon is equable or not.Equable Shape is the shape whose perimeter is equal to the area of the shape.Let’s take an example to understand the problem, Input: polygon[][] = {{0, 0}, {5, 7}, {2, 0}}Output: Not equableExplanation: Perimeter = 18.21Area = 7Solution Approach:The solution to the problem lies in find the area and perimeter of the shape and then compare both of them to check weather the given shape is an equable shape or not.Finding a perimeter using the coordinates is ... Read More
Enumeration of Binary Tree is counting the total number of distinct unlabeled binary trees of a given size (specific number of nodes). In this article, we will create a program to count the number of Binary Trees of n nodes.Based on labeling of nodes of binary tree, it is of two types:Labeled Binary TreeUnlabeled Binary TreeLabeled Binary Tree: It is a binary Tree in which the nodes of a tree are labeled with values.Different Type of Labeled Binary Tree for a given number of nodes :Number of nodes N = 2Similarly, We can find the number of distinct labeled binary Tree for ... Read More
Entringer Number is a special number which is equal to the number of permutations of {1, 2, 3, … n+1}, starting with K+1 which is updated by decreasing then increasing the values alternatively.The value of Entringer Number is formulated using, The recurrence relation, E(n, k) = E(n, k-1) + E(n-1, n-k)The base value is, E(0, 0) = 1E(n, 0) = 0We can find the Entringer number using, Let’s take an example to see valuesN = 5, k = 3E(5, 3) = 14Program to illustrate the working of our solution, ExampleLive Demo#include using namespace std; int EntringerNumber(int n, int k) ... Read More
In the binary file and data management, endianness is the sequence of bytes of a digital data inside the computer memory.In computer memory there are two type of endian order,Big-endian system stores the most significant byte of the data.Small-endian systems store the least significant byte of the data.
In this problem, we will understand the conversion of 2-D array to 1-D array. We will see how to store the elements of a 2-D array to a 1-D array.Here, the size of 1-D array is same as the total number of elements in 2-D array which is n*m.In programming there are two ways to store a 2-D array to 1-D array. They are−Row MajorColumn MajorRow Major: In row major, All the elements of a row are stored together then it moves to the next row.If an element of 2-D array of size nXm has an index (i, j) is stored ... Read More
Emirp number is a special type of number that is a prime number whose digits when reversed create another prime number (this prime number is different from the original one).Emirp is the reverse of prime. Some prime numbers that are not emirp are palindromic prime and single digit prime numbers. Some Emirp Numbers are 13, 17, 37, 733.Program to print all emirp numbers less than n.Here, we are given a number n, and we need to print all emirp numbers less than or equal to n.Let’s take an example to understand the problem, Input: n = 40Output: 13, 17, 31, 37Solution ApproachTo find all emirp numbers less ... Read More
Elo Rating Algorithm is a rating algorithm used to rank players in competitive games. The ranking of player of the competition is based on ranting which changes based on the performance of the player as follows, For a game between two players of different ratings. Let’s say there are two players competing against each other−Player1 Player2Rating of player1 is greater than player2.If player1 wins the game some player will be transferred from player1 to player2 and vice versa if player2 wins.But the amount of rating to be transferred for victory ... Read More
In this problem, we are given an array arr[] consisting of n number. Our task is to create a program to find the number of elements to be added so that all elements of a range are present in array. Problem Description: Here, we need to find the number of elements that are needed to be added to the array to make sure that all elements of a range are present in the array. The range is from smallestElement of array to largestElement of array. Let’s take an example to understand the problem, Input: arr[] = {5, 8, 3, 1, 6, 2}Output: 2Explanation:The range is from ... Read More
In this problem, we are given two arrays arr1[] and arr2[]. Our task is to create a program to find the elements of an array that are not divisible by any element of another array. Problem Description: Here, we need to find all elements from arr1 that are not divisible by any elements of arr2.Let’s take an example to understand the problem, Input: arr1[] = {17, 15, 5, 12, 8} arr2[] = {5, 4}Output: 17Explanation −Elements of arr1 and elements dividing them, 17 -> no element can divide it.15 -> 5 divides the element.5 -> 5 divides the element.12 -> 4 ... Read More