I want to understand the proof that the minimal distance $d_C$ of a linear $[n,k]$ code $C$ over $\mathbb{F_q}$ is less or equal to $\frac{nq^{k-1}(q-1)}{q^k-1}$. The proof I'm reading says that the sum of the weights of all the words in $C$ is not bigger than $nq^{k-1}(q-1)$ and then the minimal distance (equivalently the minimal weight is less or equal to the average of the weights of all non-zero code words $\frac{nq^{k-1}(q-1)}{q^k-1}$).
However I don't see why the sum of the weights of all code words is $\leq nq^{k-1}(q-1)$.
These are my calculations. Suppose that $C$ has a word $c$ which is not zero. Then $c = (c_1, ... c_n)$ has a non-zero component $c_i \neq 0$. If $D = \{(x_1, ..., x_n) \in C \ | \ x_i = 0 \}$ is the subspace of $C$ of all the words having $0$ in the $i^{th}$ component, then $C/D$ contains exactly $q$ elements. This is true because, for every $a \in \mathbb{F_q}$ $C$ contains a word with $i^{th}$ component equal to $a$ (namely this is the word $c_i^{-1}a . c$) and two words $s, t$ with different $i^{th}$ components $s_i \neq t_i$ represent different elements in $C/D$. So $q = |C/D| = |C| / |D| \Rightarrow |D| = |C| / q = q^k / q = q^{k-1}$. So there are $(q-1)|D| = (q-1)q^{k-1}$ words in $C$ that has non zero $i^{th}$ component and potentially has weight of $n$ and the sum of their weights is $\leq n(q-1)q^{k-1}$. However this doesn't include the words with $i^{th}$ component equal to $0$ (the elements of $D$). Any help how to handle them too ?
Thanks in advance!
In a linear code over $\mathbb F_q$, in each coordinate position, either all the codewords have a $0$, or each element of $\mathbb F_q$ appears equally often. That is, if we form a $q^k\times n$ array in which the rows are the codewords, then in each column, we either have all zeroes, or each element of $\mathbb F_q$ appears $q^{k-1}$ times. The total weight of all the codewords is the total number of nonzero elements in this array, and since the total number of nonzero elements in a column is upper-bounded by $q^{k-1}(q-1)$, the total weight is no larger than $nq^{k-1}(q-1)$.