Sum of the elements of the ith row up to jth column of a Pascal's triangle in O(1) time - combinatorics

The sum of the elements of the ith row of Pascal's triangle is 2^n. How can we find the sum of the elements of the ith row up to the jth column of Pascal's triangle in O(1) time?
The solutions that came to my mind is not O(1). The recursive combination function for the nth row of Pascal's triangle. nCk = n-1Ck + n-1Ck-1

Related

Determine the lexicographically smallest array of size N

You are given 4 non-negative integers N, A, B, and C. Determine the lexicographically smallest array of size N such that Bitwise AND of the whole array is A, Bitwise OR of the whole array is B, and Bitwise XOR of t he whole array is C. if no such array exists then print "-1.​" python program

returning highest value with vlookup function

i have this kind of dataset and i have to fill the "tot depth" column taking the highest value from each progressive (col K).
i've tried with ==VLOOKUP(N2,K1:L13841,2,0) but it gives me back the lowest value of the "P1" entry (-0.22).
the result i need would be :
Progressiva Tot depth
P1 -1.15
P2 -1.15
P3 -1.67
If you do not have MINIFS, you might try this in cell O2:
=MIN(INDIRECT("L"&MATCH(N2,K:K,0)&":L"&IF(N3="",COUNTAK:K),MATCH(N3,K:K,0)-1)))
And drag it to the end of the list. It will work as long as:
K column contains only the uninterrupted list of "progressiva" values;
H column contains the uninterrupted complete list of single occurences of "progressiva" value;
both column K and column N are sorted in the same way.

Sigma summation in Excel for accumulated value

how can I use an iterative summation in Excel to compute the accumulated value starting amount (stored in one column) which escalates at 5 % p.a for n years (stored in another column) with the resultant amount then being subjected to a constraint. In essence, the raw function looks like:
where x = starting amount in a column, constraint is 10% of the amount less 80
Also, is my raw function okay to compute the accumulated value with the constraint?
To sum just one year:
Put n in cell A1, put x in cell A2:
=1.05^A1*0.1*A2-80
That will give you the value you're looking for.
To sum all of the years less than (and including) n down to 1:
Put n in cell A1, put x in cell A2:
=SUMPRODUCT(1.05^ROW(INDIRECT("1:"&A1))*(0.1*A2)-80)
Much the same, except that it's wrapped in a SUMPRODUCT() to allow for array formulas and the value given for n will return all positive integers less than (and including) n. The calculation is repeated n times and the result summed.
To sum all years less than (and including) n down to zero
=SUMPRODUCT(1.05^(-1+ROW(INDIRECT("1:"&A1+1)))*(0.1*A2)-80)
Same as answer #2, except it includes zero.

Median Selling Price Excel Table

I have a spreadsheet with different products, listing units and retail value sold like the example below
Product Units Value
A 10 100
B 15 80
C 30 560
I'd like to compare the Average Selling Price with the Median Selling price, so I am looking for a quick formula to accurately calculate the median.
The median function requires the entire series, so for Product A above I would need 10 instances of 10 etc. How can I calculate the Median quickly considering the condensed form of my data?
Without writing your own VBA function to do this there are a couple of approaches that can be taken.
The first expands the data from its compressed frequency count format to generate the full set of observations. This can be done manually or formulaically. On the assumption the latter is required, it can be achieved using a few columns.
All the blue cells are formulae.
Column Eis simply the cumulative of column B and F is an adjusted version of this. Column H is just the values 1 to 55, the total number of observations given by cell L2. Column I uses the MATCH() with its final argument as 1 to match each observation in H against the adjusted cumulative in F. Column J uses the INDEX() function to generate the value of the observation. (Observations 1-10 have value 100, 11-25 have value 80 and 26-55 have value 560 in this example). The MEDIAN() function is used in cell M2 with column J as its argument.
This approach can be refined to take account of varying numbers of products and data points through the use of the OFFSET function to control the range arguments of the MATCH(), INDEX() and MEDIAN functions. And, of course, adjacent cells in columns I and J could be combined using a single formula - I've shown them separately for ease of explanation.
The second approach involves sorting the data by value (so in this case the data rows would become Product B in row 2, product A in row 3 and product C left as-is in row 4). It is then a case of identifying the middle observation number (if the number of observations is odd) or the middle pair of observation numbers (if the number of observations is even) and then determining the value(s) corresponding to this/these middle observation(s). In this approach the adjusted cumulative in column F is still used but rather than explicitly calculating the values in column I and J for every observation it can now be restricted to just the middle observation(s).
I think there is no way around compromises. Either using big amounts of helper cells or having the table sorted by the values.
Helper cells:
Formula in F4:AS6:
=IF(COLUMN()<COLUMN($F$4)+$B4,$C4,"end")
Formula in D2:
=MEDIAN(F4:AS6)
Sorted:
Formula in F4 downwards:
=SUM($B$3:B3)+1
Formula in D2:
=SUM(LOOKUP(INT(SUM(B4:B6)/2+{0.5,1}),F4:F6,C4:C6))/2

Determining a winner from multiple criteria

I am trying to determine group winners from points earned (firstly) then margins in Excel 2010.
In Column 1 there are 4 names, column 2 has points earned from wins and draws. If more than one of these are the maximum value, I then want to determine the winner of those, by the margins entered in the third column.
Any Ideas?
You can do it using this formula:
=INDEX(A2:A5,MAX(IF(B2:B5*10^5+C2:C5=MAX(B2:B5*10^5+C2:C5),ROW(B2:B5),""))-1)
Where:
MAX(B2:B5*10^5+C2:C5) calculates a weighted score, which considers column C only when values in column B are equal (10^5 is just a random value, what's important is that minimum difference between scores after the multiplication should be bigger than maximum margin)
=MAX(IF(B2:B5*10^5+C2:C5=MAX(...),ROW(B2:B5),"")) - determines the row with the highest weighted score
=INDEX(A2:A5,MAX(...)-1) - returns the team with the highest weighted score (-1 is there for correction of the difference of scales (INDEX counts withing selected area, while row number is given from nested expression))
This is an array formula, so you need to press CTRL+SHIFT+ENTER after inserting it.

Resources