I know that n(n+1)/2 is getting the sum of 1 to n numbers.

How about the n(n-1)/2?

where and when do we use this formula? and what other formulas are related to these two?

I know that n(n+1)/2 is getting the sum of 1 to n numbers.

How about the n(n-1)/2?

where and when do we use this formula? and what other formulas are related to these two?

4 Likes

Iâ€™d say, that if \frac{n(n+1)}{2} is som of n numbers, then \frac{(n-1)n}{2} is the sum of n-1 numbers, do you agree?

You know, itâ€™s not easy to answer the question without the proper contextâ€¦

Second formula can also be used to find out number of combinations how to choose two elements out of n, or how many elements A_{i,j} are in square matrix where i < j and probably one can find another dozen of descriptionsâ€¦

14 Likes

As @betlista has said, `n(n-1)/2`

is the sum of the first `(n-1)`

numbers, that is

```
1 + 2 + 3 + 4 + .......... + (n-1)
```

Now one might think that there is not much use for this formula, but when you do some research, you can find interesting uses for it. @betlista has explained a few uses. Here is a link which explains one usage

link

3 Likes

So basically it is a combination formula where you need to choose r element out of n and order does not matter.

n * (n-1) / 2

Same as NCR forumula which is N! / (N-R)! * R!

6 Likes

Bruh its been six years

4 Likes

Legend says he is still asking this question. Duhhhh

10 Likes

Your answer is right , if you look at T(n) for insertion sort here you can see how outer loop runs for n(n+1)/2 -1 times and inner while runs one less than test case which again yields (n-1)(n-1+1)/2=n(n-1)/2

(n + 1) * (n + 2)/ 2 are both are same n*(n + 1) / 2

can anyone explain?

n*(n-1)/2 .This formula is mostly used to find **total number of subarrays** for a given array of size n

1 Like

I think it should have been \frac{n\times (n+1)}{2}. You missed subarrays of size 1.

nC2 ->Combination, number of handshakes

1 Like

This link is not working.

It was posted in 2015

3 Likes

use n as 5

it give sum of n number

n*(n+1)/2 = 5(5+1)/2=15

it give sum of n+1 number

(n+1)*(n+2)/2 =(6*7)/2=31

it give sum of n-1 number

n*(n-1)/2 = 5(5-1)/2=10

it give sum of square n`2`

n(n+1)(2n+1)/6 = 5(6)(11)/6=55

it give sum of cube n`3`

[ n*(n-1)/2]`2`

=( 5(5-1)/2)2=100

1 Like