- #1
suditi.saini
- 1
- 0
Given a number of terms, n in an equation containing only addition as the only possible operator, find the different number of valid ways in which they can be evaluated. Order of evaluation is controlled by grouping the terms in brackets
e.g. if n = 4
it means that there are 4 terms in the equation – i.e. something like
a+b+c+d
Now the valid ways in which it can be evaluated :
(a + (b + (c+d)))
(a + ((b+c) + d))
((a+b) + (c+d))
(((a+b) + c) + d)
((a + (b+c)) + d)
So the answer in this case is 5
what`s the logic to add n numbers in different possible ways?
e.g. if n = 4
it means that there are 4 terms in the equation – i.e. something like
a+b+c+d
Now the valid ways in which it can be evaluated :
(a + (b + (c+d)))
(a + ((b+c) + d))
((a+b) + (c+d))
(((a+b) + c) + d)
((a + (b+c)) + d)
So the answer in this case is 5
what`s the logic to add n numbers in different possible ways?