I was doing a problem with the relevant problem statement being:
"
Consider a list of integers L. Initially, L contains the integers 1 through N, each of them exactly once (but it may contain multiple copies of some integers later). The order of elements in L is not important. You should perform the following operation N−1 times:
"
I was able to write down some examples for N = 2 and 3 and saw that the order in which I chose the two elements didn't matter, and thus I can just iterate through the list and perform the operation (X + Y + XY) sequentially till I get the final total.
BUT, the part I don't understand is how would I have actually proven that the order doesn't matter here? I want to be able to do these kinds of problems without needing to write down examples first but where I can really see why something is the case.
"
Consider a list of integers L. Initially, L contains the integers 1 through N, each of them exactly once (but it may contain multiple copies of some integers later). The order of elements in L is not important. You should perform the following operation N−1 times:
- Choose two elements of the list, let's denote them by X and Y.
- Erase the chosen elements from L.
- Append the number X+Y+X⋅Y to L.
"
I was able to write down some examples for N = 2 and 3 and saw that the order in which I chose the two elements didn't matter, and thus I can just iterate through the list and perform the operation (X + Y + XY) sequentially till I get the final total.
BUT, the part I don't understand is how would I have actually proven that the order doesn't matter here? I want to be able to do these kinds of problems without needing to write down examples first but where I can really see why something is the case.