Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Arnab Chakraborty
Page 184 of 377
C/C++ Program to find Product of unique prime factors of a number?
In this section we will see how we can get the product of unique prime factors of a number in an efficient way. There is a number say n = 1092, we have to get product of unique prime factors of this. The prime factors of 1092 are 2, 2, 3, 7, 13. So the unique prime factors are {2, 3, 7, 13}, and the product is 546. Syntax int uniquePrimeProduct(int n); Algorithm To solve this problem, we have to follow this approach − Handle factor 2: When the number is divisible ...
Read MoreC/C++ Program for Finding the vertex, focus and directrix of a parabola?
A parabola is a U-shaped curve that can be described by a quadratic equation. In C programming, we can find key properties of a parabola including its vertex, focus, and directrix using mathematical formulas. The general equation of a parabola is − Syntax y = ax² + bx + c Where a, b, and c are coefficients and a ≠ 0. ...
Read MoreAbsolute distinct count in a sorted array?
In this article, we will learn how to count the number of elements whose absolute values are distinct in an array. For example, in the array {5, 5, 6, -5, 8, 2, -2, 1}, there are 8 elements total, but only 5 distinct absolute values: {5, 6, 8, 2, 1}. Note that -5 and 5 are considered the same since their absolute values are identical. Syntax int absoluteDistinctCount(int arr[], int n); Algorithm To solve this problem, we use a simple approach − 1. Create a boolean array to mark visited absolute values ...
Read MoreAbsolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array?
Here we will see how we can find the absolute difference between the sum of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking if a number is not divisible by any number between 2 to square root of that number. This process will take O(√n) amount of time for each number. Syntax int diffPrimeNonPrimeSum(int arr[], int n); Algorithm begin sum_p := sum of ...
Read MoreAbsolute Difference between the Product of Non-Prime numbers and Prime numbers of an Array?
Here we will see how we can find the absolute difference between the product of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a number is not divisible by any number between 2 to square root of that number. So this process will take O(√n) amount of time. Then get the product and try to find the absolute difference. Syntax int diffPrimeNonPrimeProd(int arr[], int n); bool isPrime(int n); Algorithm ...
Read MoreAbsolute difference between the first X and last X Digits of N?
Here we will see how to get the absolute difference between the first X and last X digits of a number N. To solve this problem, we first extract the last X digits using the modulus operator, then extract the first X digits by reducing the number's length. Finally, we calculate the absolute difference between these two values. Syntax int diffFirstLastDigits(int n, int x); Algorithm diffFirstLastDigits(N, X) begin p := 10^X last := N mod p len := length of the ...
Read MoreAbsolute difference between sum and product of roots of a quartic equation?
In this section we will see how to find the absolute difference between the sum of the roots and the product of the roots of a quartic equation. A quartic equation has the form ax4 + bx3 + cx2 + dx + e = 0. We can solve the equation and then calculate the sum and product of the roots using traditional methods, but that approach is time-consuming and inefficient. For a quartic equation, we have two important formulas − Sum of roots = -b/a Product of roots = e/a Therefore, we need to find ...
Read MoreA sorting algorithm that slightly improves on selection sort?
Two-way selection sort is an improved version of selection sort that processes the array from both ends simultaneously. Instead of finding only the minimum element in each pass, it finds both the minimum and maximum elements and places them at their correct positions from the left and right ends respectively. Syntax void twoWaySelectionSort(int arr[], int n); Algorithm begin for i := 0, and j := n-1, increase i by 1, and decrease j by 1, until i >= j, do min := minimum element from index i ...
Read MoreA Problem in Many Binary Search Implementations?
We know that the binary search algorithm is better than the linear search algorithm. This algorithm takes O(log n) amount of time to execute. Though most of the cases the implemented code has some problem. Let us consider one binary search algorithm function like below − Syntax int binarySearch(int array[], int start, int end, int key); Problem in Common Implementation Here is a common but problematic implementation of binary search − #include int binarySearch(int array[], int start, int end, int key){ if(start key) ...
Read MoreA permutation where each element indicates either number of elements before or after it?
In this problem, we need to check whether there exists a permutation of a given array such that each element indicates the number of elements either before or after it in that permutation. For example, consider the array {2, 1, 3, 3}. A valid permutation is {3, 1, 2, 3} where the first 3 indicates there are three elements after it, 1 indicates there is one element before it, 2 indicates there are two elements before it, and the last 3 indicates there are three elements before it. Algorithm The approach uses a frequency map to track ...
Read More