Programming Articles - Page 2207 of 3363

C++ Program for Derivative of a Polynomial

Sunidhi Bansal
Updated on 20-Dec-2019 11:32:06

5K+ Views

Given a string containing the polynomial term, the task is to evaluate the derivative of that polynomial.What is a Polynomial?Polynomial comes from two words: - “Poly” which means “many” and “nomial” means “terms”, which comprises many terms. Polynomial expression is an expression containing variables, coefficients and exponents, which only involves operations such as, addition, multiplication and subtraction of variable(s).Example of polynomialx2+x+1Derivative of the polynomial p(x) = mx^n  will be −m * n * x^(n-1)ExampleInput: str = "2x^3 +1x^1 + 3x^2"    val = 2 Output: 37 Explanation: 6x^2 + 1x^0 + 6x^1    Putting x = 2    6*4 + ... Read More

Boolean Indexing in Python

Pradeep Elance
Updated on 20-Dec-2019 11:26:46

2K+ Views

The Boolean values like True & false and 1&0 can be used as indexes in panda dataframe. They can help us filter out the required records. In the below exampels we will see different methods that can be used to carry out the Boolean indexing operations.Creating Boolean IndexLet’s consider a data frame desciribing the data from a game. The various points scored on different days are mentioned in a dictionary. Then we can create an index on the dataframe using True and False as the indexing values. Then we can print the final dataframe.Example Live Demoimport pandas as pd # dictionary ... Read More

html5lib and lxml parsers in Python

Pradeep Elance
Updated on 20-Dec-2019 11:19:19

768 Views

html5lib is a pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers. It can parse almost all the elements of an HTML doc, breaking it down into different tags and pieces which can be filtered out for various use cases. It parses the text the same way as done by the major browsers. It can also tackle broken HTML tags and add some necessary tags to complete the structure. Also it is written in pure python code.lxml is also a similar parser but driven by XML ... Read More

C Program for focal length of a lens

Sunidhi Bansal
Updated on 20-Dec-2019 11:20:43

441 Views

Given two floating values; image distance and object distance from a lens; the task is to print the focal length of the lens.What is focal length?Focal length of an optical system is the distance between the center of lens or curved mirror and its focus.Let’s understand with the help of figure given below −In the above figure i is the object, and F is the image of the object which is formed and f is the focal length of the image.So to find the focal length of the image from the lens the formula is −1F= 1O+1IWhere, F is the ... Read More

How to assign values to variables in Python

Pradeep Elance
Updated on 20-Dec-2019 11:07:16

5K+ Views

Variable assignment is a very basic requirement in any computer programming language. In python there are multiple ways we can declare a variable and assign value to it. Below we see each of them.Direct InitialisationIn this method, we directly declare the variable and assign a value using the = sign. If the variable is declare multiple times, then the last declaration’s value will be used by the program.Examplex = 5 x = 9 print(a)Running the above code gives us the following result:Output9Using if-elseWe can initialize value of a variable using some conditions. The evaluation of the result of the condition ... Read More

Program for Mobius Function in C++

Sunidhi Bansal
Updated on 20-Dec-2019 11:17:22

509 Views

Given a number n; the task is to find the Mobius function of the number n.What is Mobius Function?A Mobius function is number theory function which is defined by$$\mu(n)\equiv\begin{cases}0\1\(-1)^{k}\end{cases}$$n=  0 If n has one or more than one repeated factorsn= 1 If n=1n= (-1)k  If n is product of k distinct prime numbersExampleInput: N = 17 Output: -1 Explanation: Prime factors: 17, k = 1, (-1)^k 🠠(-1)^1 = -1 Input: N = 6 Output: 1 Explanation: prime factors: 2 and 3, k = 2 (-1)^k 🠠(-1)^2 = 1 Input: N = 25 Output: 0 Explanation: Prime factor is ... Read More

What is a target type of lambda expression in Java?

raja
Updated on 11-Jul-2020 08:30:22

3K+ Views

A functional Interface for which a lambda expression has invoked is called target type of lambda expression. It means that if a lambda expression has invoked for some "X" interface then "X" is the target type of that lambda expression. Hence, we conclude that lambda expressions can be used only in those situations where java compiler can determine the Target Type.In the below example, the target type of lambda expression is BiFunction. An instance of a class is automatically created that implements the functional interface and lambda expression provides an implementation of the abstract method declared by the functional interface.Exampleinterface BiFunction { ... Read More

Generating hash ids using uuid3() and uuid5() in Python

Pradeep Elance
Updated on 20-Dec-2019 10:40:51

2K+ Views

The universally unique identifier is a 32 bit hexadecimal number that can guarantee a unique value in a given namespace. This helps in tracking down objects created by a program or where ever python needs to handle object or data that needs large value of identifier. The UUID class defines functions that can create these values.Syntaxuuid3(namespace, string) uuid3 usesMD5 hash value to create the identifier. Uuid5(namespace, string) Uuid5 uses SHA-1 hash value to create the identifier. The namespace can be – NAMESPACE_DNS : Used when name string is fully qualified domain name. NAMESPACE_URL : Used when name string is ... Read More

Max sum of M non-overlapping subarrays of size K in C++

Narendra Kumar
Updated on 20-Dec-2019 10:39:21

319 Views

Problem statementGiven an array and two numbers M and K. We need to find sum of max M subarrays of size K (non-overlapping) in the array. (Order of array remains unchanged). K is the size of subarrays and M is the count of subarray. It may be assumed that size of array is more than m*k. If total array size is not multiple of k, then we can take partial last array.ExampleIf Given array is = {2, 10, 7, 18, 5, 33, 0}. N = 7, M = 3 and K = 1 then output will be 61 as subset ... Read More

Missing Permutations in a list in C++

Narendra Kumar
Updated on 20-Dec-2019 10:34:29

152 Views

Problem statementGiven a list of permutations of any word. Find the missing permutation from the list of permutations.ExampleIf permutation is = { “ABC”, “ACB”, “BAC”, “BCA”} then missing permutations are {“CBA” and “CAB”}AlgorithmCreate a set of all given stringsAnd one more set of all permutationsReturn difference between two setsExample Live Demo#include using namespace std; void findMissingPermutation(string givenPermutation[], size_t permutationSize) {    vector permutations;    string input = givenPermutation[0];    permutations.push_back(input);    while (true) {       string p = permutations.back();       next_permutation(p.begin(), p.end());       if (p == permutations.front())          break;     ... Read More

Advertisements