# User:Upssdr/array

Recently I did some research on array templates, and it seems I got some interesting results. In Help:Template's description, we must set up arrays with a lot of templates. But now it is different. The following is a method to set up an n elements 1d array. (the italic words are some parameters to be specified.)
[[template:tmpltname]]={{tmpltname/1|par[1]=1|par[2]=2|...|par[n]=n|{{{1}}}=}}
[[template:tmpltname/1]]={{tmpltname/2|val[1]|val[2]|...|val[n]|{{{par[1]}}}=|{{{par[2]}}}=|...|{{{par[n]}}}=}}
[[template:tmpltname/2]]={{{1}}}{{{2}}}...{{{n}}}
The usage is e.g. {{tmpltname|par[x]}}, and it gives val[x]. The exact size of the three templates can be calculated with the following formula:
${\displaystyle Size=23+17n+2length(tmpltname)+2\sum _{i=1}^{n}length(par[i])+\sum _{i=1}^{n}length(val[i])+2\sum _{i=1}^{-[-\lg n\ ]}9i10^{i-1}}$
So its space complexity is ${\displaystyle O(n)}$. And How about those arrays of higher dimensions? As we all know, the nd array in any programming language is based on 1d array. So it's easy to deal with nd arrays.