Evaluate Array Expression with Numbers in C++

sudhir sharma
Updated on 22-Jan-2021 13:13:55

283 Views

In this problem, we are given an array arr[] consisting of n character values denoting an expression. Our task is to evaluate an array expression with numbers, + and –. The expression consists of only, numbers, ‘+’ character and ‘- ’ character.Let’s take an example to understand the problem, Input: arr = {“5”, “+”, “2”, “-8”, “+”, “9”, }Output: 8Explanation: The expression is 5 + 2 - 8 + 9 = 8Solution Approach:The solution to the problem is found by performing each operation and then returning the value. Each number needs to be converted to its equivalent integer value.Program to illustrate the working of ... Read More

Evaluation of Prefix Expressions in C++

sudhir sharma
Updated on 22-Jan-2021 13:13:40

16K+ Views

In this article, we will discuss the evaluation of prefix Expression. Prefix ExpressionIn this notation, operator is prefixed to operands, i.e. operator is written ahead of operands. For example, +ab. This is equivalent to its infix notation a + b. Prefix notation is also known as Polish Notation.For more read.Example:* + 6 9 - 3 1Prefix expressions are evaluated faster than infix expressions. Also, there are no brackets in prefix expressions which make it evaluate quicker.Algorithm to evaluate Prefix Expression:The evaluation of prefix expression requires a stack data structure. We will push the operators in the stack and then solve the ... Read More

Evaluation of Expression Tree in C++

sudhir sharma
Updated on 22-Jan-2021 13:13:21

1K+ Views

In this problem, we are given an expression tree that consist of binary operations like +, - , /, *. We need to do the evaluation of the expression tree and then return the result.Expression Tree is a special type of binary tree in which each node either consist of an operator or operand which are distributed as−Leaf nodes of the tree are values on which the operation is to be performed. Non-leaf nodes consist of the binary operator denoting the operation to be performed. Let’s take an example to understand the problem, Input: Output: 1Explanation: Decoding the expression tree, Exp           ... Read More

Euler's Four Square Identity in C++

sudhir sharma
Updated on 22-Jan-2021 13:07:49

206 Views

In this problem, we are given two numbers and we need to find the product of the numbers using Euler's four square Identity. Euler’s Four Square Identity is the method to find the product of two numbers which can be represented using the sum of four squares of the number if the numbers can be represented as sum of four squares.The product a * b can be represented as the sum of four squares ifa = x12 + x22 + x32 + x42 b = y12 + y22 + y32 + y42 a * b = z12 + z22 + z32 + z42Let’s take an example ... Read More

Eulerian Number in C++

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

497 Views

In mathematics, the Eulerian number is a special type of combination number. It defines the number of permutations in which the next element is a specific number greater than the previous one.Denoted as,  A(n, m) is permutation from 1 to n in which two numbers vary by m.Problem Statement: In this problem, we are given two numbers m and n. And we need to find the number of permutations that are the Eulerian Number.Let’s take an example to understand the problem, Input:  n = 4, m = 2Output: 11Explanation: All permutations of number from 1 to 4 are −1 2 3 4       ... Read More

Evaluate Boolean Expression Represented as String in C++

sudhir sharma
Updated on 22-Jan-2021 13:07:18

706 Views

In this problem, we are given a string exp that represents a boolean expression. Our task is to evaluate the boolean expression represented as String.The valid characters in the expression are −0 or 1 denoting the boolean value& denoting AND operation| denoting OR operation^ denoting XOR operationWe need to solve this expression and return the result.Let's take an example to understand the problem, Input: str = 1&1|0^1^0&1Output: 0Explanation: 1&1|0^1^0&11 AND 1 OR 0 XOR 1 XOR 0 AND 11 OR 0 XOR 1 XOR 0 AND 11 XOR 1 XOR 0 AND 10 XOR 0 AND 10 AND 10Solution Approach:A simple solution is ... Read More

Euler Method for Solving Differential Equations in C++

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

5K+ Views

In this problem, we are given a differential equation f(x, y) = dy/dx with initial value y(x0) = y0. Our task is to find the solution of the equation using the Euler method for solving differential equations.EULER METHODEuler method also known as forward euler Method is a first order numerical procedure to find the solution of the given differential equation using the given initial value.For a differential equation f(x, y) = dy / dx. Euler method is defined as, y(n+1) = y(n) + h * f( x(n), y(n) )The value h is step size which is calculated as, h = (x(n) - x(0)) ... Read More

Equilibrium Index of an Array in C++

sudhir sharma
Updated on 22-Jan-2021 12:59:42

620 Views

In this problem, we are given an array arr[] consisting of n integer values. Our task is to create a program to find the equilibrium index of an array.Equilibrium Index is the index at which the sum of all elements before the index is the same as the sum of all elements after the index.For array arr[] of size n, the equilibrium index is e such that, sum (arr[0… e-1] ) = sum (arr[e… n-1])Let’s take an example to understand the problem, Input: arr[] = {5, 1, 2, 8, 3, 4, 1}Output: 3Explanation: arr[0] +  arr[1] + arr[2] = arr[4] + arr[5] + arr[6]=> ... Read More

Equidigital Numbers in C++

sudhir sharma
Updated on 22-Jan-2021 12:59:30

151 Views

Equidigital numbers are mathematically special numbers in which the number of digits in the number is equal to the number in its prime factorization.In this problem, we are given an integer value n. Our task is to create a program to all equidigital numbers up to n.Let’s take an example to understand the problem, Input: n =  12Output:  1 2 3 5 7 10 11Solution Approach:A simple solution to the problem would be finding the factors of the number and check if the number of primes is equal to the number of digits in the number .The prime factors can be ... Read More

Equal Sum and XOR in C++

sudhir sharma
Updated on 22-Jan-2021 12:55:57

872 Views

In this problem, we are given an integer n. Our task is to create a program to find the count of integers from i = 0 to n, where sum is equal to XOR i.e. (n+i) = (n^i).Let’s take an example to understand the problem, Input:  n = 4Output: 4Explanation: Considering all values of i from 0 to n, i = 0,  4 + 0 = 4, 4^0 = 4i = 1,  4 + 1 = 5, 4^1 = 5i = 2,  4 + 2 = 6, 4^2 = 6i = 3,  4 + 3 = 7, 4^3 = 7i = 4, ... Read More

Advertisements