Mathematics

Count Triangles formed by the elements of array

Problem Statement Given a sorted array of distinct integers, each of these integers can represent a length. The task at hand is to count the number of possible triangles which can be made through these lengths. Of course, if you chose one length to be one side of the triangle, you cannot use that length again in the same triangle. This means, no triangle contains the same length more than once. Important Note: For given sides of lengths a, b and c. A triangle can only be formed if sum of any two sides is greater than the third side. This is called the triangle inequality. The sum of any...
Read More

Polynomial Operations

Introduction This is a famous interview question where it is asked to write program for simple arithmetic polynomial operations. The operation may include adding, subtracting and multiplication of two polynomials (mostly in one variable). For those who want to refresh their knowledge of polynomials, I would include a section below: Understanding Polynomials Polynomials are mathematical expressions of the form a1xnym + a2xn-1ym-1+ . . . + akxn-ky + . . . + anx + an+1. The above polynomial is said to be a polynomial in two variables (x and y). a1xn + a2xn-1 + a3xn-2 + . . . + an-1x + ...
Read More

Combination of Numbers

Introduction I already have one post on this blog which explains the permutations code, now its time for the combinations. The idea behind Combination of Numbers Combination by definition is a concept of discrete mathematics which essentially relates to the act of selecting a list of items from a collection. For e.g. If I have to pick up 3 fruits from a basket of 10 fruits then what all ways are there to pick them up? Combinations is the answer to this question. Let us say that I picked an Apple, a Banana and a Strawberry from the basket, then it really won't matter in what order I pi...
Read More

Code to find Permutation of Numbers

Introduction The article is about writing a Code to find permutation of numbers, the program prints all possible permutations of a given list or array of numbers. I have this question listed on my Stackoverflow.com account as well. To know the opinions of other people on the same and to find out other ways to solve the problem, please visit the link Also, you might be interested in the code for Combinations. Find it here Problem Statement Given a list of numbers, print the possible permutations. The program must also be able to print P(n,r) where N and r can be input parameters. Before ...
Read More