Found 26504 Articles for Server Side Programming

Postorder traversal of Binary Tree without recursion and without stack in C++

sudhir sharma
Updated on 17-Apr-2020 07:03:44

453 Views

In this problem, we are given a Binary tree. Our task is to print the postorder traversal of the binary tree without using recursion and without stack.Binary tree is a special type of tree in which each node can have at max 2 child nodes.Postorder Traversal is a tree traversal technique, in which the first left subtree is traversed than the right subtree and the root is traversed at the end.postorder traversal of the above tree − 8 4 2 7 9 6To traverse the tree without using recursion and stack. We will depth-first search based technique and data will ... Read More

pow() function for complex number in C++

sudhir sharma
Updated on 17-Apr-2020 06:58:09

713 Views

pow() or power function is a function used to calculate the power of a number. It is generally used in real numbers. Here, we will see its implementation of complex numbers.Complex numbers are those numbers that can be represented as A + iB, where A is the real part and B is the complex part of the number.The functions for the complex number in c++ are defined in the header file . Here, the pow() method for complex numbers is defined. It finds the complex power of a complex number to some power.The method is applied to complex numbers takes ... Read More

Power in Mathematics in C++

sudhir sharma
Updated on 17-Apr-2020 06:55:32

170 Views

The power of a number is the times a number is multiplied to itself. Also knows as exponent or indices.a to the power b is b times a is multiplied by itself b times. 7 to the power 2 is 72 also known as 7 square is valued 49.Some common power values are −A number to the power 0 gives 1.A number to the power 1 gives the same number, as stated some multiplied once is the same.A number to the negative power is n times division. Example, a -3 = 1/a3 or (1/a)*(1/a)*(1/a)Now, let’s do some programming based on ... Read More

Power of a prime number r in n! in C++

sudhir sharma
Updated on 17-Apr-2020 06:49:39

222 Views

In this problem, we are given two integer n and r. Our task is to find the power of the given prime number r in the factorial of the number n.Let’s take an example to understand the problemInput − n = 6 r = 2Output − 4Explanation −Factorial n, 6! = 6*5*4*3*2*1 = 720 720 = 24 * 32 * 5, power of 2 is 4To solve this problem, a simple solution would be directly finding the factorial and then finding the power of the prime number. But this is not the best solution.Another efficient solution is using a formula, ... Read More

Power Set in Lexicographic order in C++

sudhir sharma
Updated on 17-Apr-2020 06:46:51

759 Views

In this problem, we are given string str. Our task is to print the power set of this string’s elements in lexicographical order.Power Set − The power set of a set is the set of all subsets of the set. Denoted by P(S) where s is the set.Example −S = {1, 2, 3} ; p(S) = {{}, {1}, {1, 2}, {1, 3}, {2}, {2, 3}, {3}, {1, 2, 3}}In this problem, we will treat the string as a set. So, its characters will be the elements of the set.Let’s take an example to understand the problemInput − str = “xyz”Output ... Read More

Powers of 2 to required sum in C++

sudhir sharma
Updated on 17-Apr-2020 06:43:33

675 Views

In this problem, we are given an integer N. Our task is to print the number which when raised to the power of 2 gives the number.Let’s take an example to understand the problemInput − 17Output − 0, 4Explanation − 17 = 24 + 20 = 16 + 1To solve this problem, we will divide the number with 2 recursively. By this method, every number can be represented as a power of 2. This method is used to convert the number to its binary equivalent.ExampleThe program to show the implementation of our solution Live Demo#include using namespace std; void sumPower(long ... Read More

Powers of two and subsequences in C++

sudhir sharma
Updated on 17-Apr-2020 06:41:39

209 Views

In this problem, we are given an array of N integers. Our task is to find the count of subsequences that can be formed such that if their elements are multiplied, they result in a number which is a power of two.Let’s take an example to understand the problem, Input − arr = [2, 5, 4]Output − 3Explanation − subsequences [2], [4] and [2, 4] give the desired result.To solve this problem, we need to understand the logic of power.Only those numbers with are powers of 2 will multiply to give the desired result. So, we have to consider only ... Read More

Difference between Python and Bash

Mahesh Parahar
Updated on 16-Apr-2020 06:20:19

1K+ Views

PythonPython is a programing language designed to be simple to implement and easy to understand. It is a dynamically typed language. It is not using pointers.BashBash is a command-line interpreter and is shipped by default in Linux and MacOS operating systems. It can be installed in other operating systems as well. It is default User Shell for Linux and MacOS.The following are some of the important differences between Python and Bash.Sr. No.KeyPythonBash1TypePython is a programming language mostly used in automation programming.Bash is a command-line interpreter or user shell to interpret user commands.2BasisPython is developed as an easy to implement an ... Read More

map::at() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:58:18

425 Views

In this article we will be discussing the working, syntax and examples of map::at() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::at()?map::at() function is an inbuilt function in C++ STL, which is defined in  header file. at() is used to access a ... Read More

map::size() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:56:27

8K+ Views

In this article we will be discussing the working, syntax and examples of map::size() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::size()?map::size() function is an inbuilt function in C++ STL, which is defined in  header file. size() is used to check the ... Read More

Advertisements