Fast Inverse Square Root in C++

sudhir sharma
Updated on 22-Jan-2021 13:32:33

2K+ Views

In this problem, we are given an integers x. Our task is to calculate Fast inverse square root () of a 32-bit floating point number.  The algorithm to find the inverse square root of the number is of great use in programming, such as vector normalization in video games,  in 3D graphics, etc.  Algorithm: Step 1: The algorithm converts the floating point value to integer. Step 2: Operate on the integer value and return approximate value of the inverse square root.Step 3: Convert the integer value back to floating point using the same method used in step 1.Step 4: The approximation is made for improving precision using ... Read More

Extended Operators in Relational Algebra in C++

sudhir sharma
Updated on 22-Jan-2021 13:31:03

936 Views

Relational data model is the primary data model, which is used widely around the world for data storage and processing. This model is simple and it has all the properties and capabilities required to process data with storage efficiency.They are basic operators on Relation Algebra, here we will learn about some extended operators. They are mainly of three types:Intersection Join Divide  Intersection Operation i s a special type of operation in for relations R1 and R2 where the relation in which the tuples with elements present in both relations i.e. in relation R1 and R2. JOIN Conditional Join is a special type of join in which we ... Read More

External Sorting with Example in C++

sudhir sharma
Updated on 22-Jan-2021 13:30:46

3K+ Views

External Sorting is a category of sorting algorithm that is able to sort huge amounts of data. This type of sorting is applied on data set which acquire large memory which cannot be holded in main memory (RAM) and is stored in secondary memory ( hard disk).The idea of sorting used in external sort is quite similar to merge sort. In also possess two phases like in merge sort, In the sort phase,  small memory size data sets are sorted and then in merge phase, these are combined to a single dataset.External Sorting For a huge data set which cannot be processed in ... Read More

Fast Average of Two Numbers Without Division in C++

sudhir sharma
Updated on 22-Jan-2021 13:30:31

441 Views

In this problem, we are given two numbers A and B. Our task is to create a program to calculate the Fast average of two numbers without division. Let’s take an example to understand the problem, Input: A = 34       B = 54Output: 44Solution Approach: Normally, the average is calculated by adding two numbers and then divide it by 2. This requires division but we need to find the average without using division. This can be done using right shift operator >> and shift the binary expansion instead of using division operator.Program to illustrate the working of our solution, ExampleLive Demo#include ... Read More

Extended Midy’s Theorem in C++

sudhir sharma
Updated on 22-Jan-2021 13:26:20

154 Views

Midy’s Theorem is a statement used for decimal expansion of numbers denoted by n/p, where n is any number and p is a prime number and a/p has a repeating decimal with even period.In Extended Midy’s Theorem, the repeating portion is divided into m digits, then their sum is a multiple of 10m - 1. Program to illustrate Extended Midy’s Theorem: ExampleLive Demo#include using namespace std; string findDecimalValue(int num, int den) {        string res;    unordered_map mp;    int rem = num % den;    while ((rem != 0) && (mp.find(rem) == mp.end())) {   ... Read More

Expression Tree with Example in C++

sudhir sharma
Updated on 22-Jan-2021 13:26:00

485 Views

An expression tree is a special type of binary tree in which each node of the tree either consists of an operator or operand.Leaf nodes of the tree represent an operand.Non-leaf nodes of the tree represent an operator.Example:To get the infix expression which can be easily solved, we need to traverse the tree using inorder traversal. 

Express Odd Number as Sum of Prime Numbers in C++

sudhir sharma
Updated on 22-Jan-2021 13:25:36

408 Views

In this problem, we are given an odd number N. Our task is to express an odd number as the sum of prime numbers.There can be at max three prime numbers while expressing the number.Let’s take an example to understand the problem, Input: N = 55Output: 53 + 2Solution Approach: The odd number can be represented as a sum of primes. Taking these primes into consideration we have three cases.Case 1: If n is a prime number, it is represented as the sum of one prime number n.Case 2: If (n - 2) is a prime number, it is represented as the sum of two ... Read More

Evil Number with Example in C++

sudhir sharma
Updated on 22-Jan-2021 13:17:29

951 Views

In this problem, we are given an array a number N. Our task is to check whether the number is an evil Number or Odious Number. Evil Number: It is a positive number which has an even number of 1’s in its binary expansion.Example: 5, 17 Odious Number: It is a positive number which has an odd number of 1’s in its binary expansion.example : 4, 6Let’s take an example to understand the problem, Input: N = 65Output: Evil NumberExplanation: Binary Expansion of 65 :  1000001Solution Approach: A simple solution to the problem is by finding the binary expansion of the number and then counting the number of 1’s ... Read More

Evaluation of Risk in Investments in C++

sudhir sharma
Updated on 22-Jan-2021 13:16:43

188 Views

In this problem, we are given two arrays each denoting an investment plan. Our task is to perform the evaluation of Risk in Investment and find which of the two investments is more promising.Both the investments I1[][] and I2[][] has a set of outcomes and the probability of that investment outcome.Using these values, we need to find the risk in each investment and then print the better investment out of the two investments.For this, we will be using statistical mathematics and find some values that will help us conclude to the better investment.We will find these values, Mean or average amount ... Read More

Evaluation Order of Operands in C++

sudhir sharma
Updated on 22-Jan-2021 13:16:32

244 Views

There are some rules in programming that govern how an operation is performed.The order of evaluation of operation and the associativity of operations (which is left to right is defined).Here is a program to show the evaluation order of operands,ExampleLive Demo#include using namespace std; int x = 2; int changeVal() {    x *= x;    return x; } int main() {        int p = changeVal() + changeVal();    cout

Advertisements