Can someone provide me a
Mathematical expression of largest $k$ numbers from $n$ numbers $(n>k)$
eg $S$ is a 3x3 matrix with [6 8 5 ; 3 4 6 ; 9 0 5] where $n$ = 9 (elements)
and I need to choose $k=2$, equivalent to (9 8).
I would like to get a mathematical expression for this.
Define an array $A$ with order $k$ and an array $B$ with order $n$. Fill $B$ with the numbers you said "$n$ numbers. Also add two other variables $minA$ and $indexOfMinA$. Add first element of $B$ to $A$. Make $minA = b_1$ and $indexOfMinA=1$. Then add the rest of first $k$ elements of $B$ to $A$ and when you do this process, check for each $b_i$ if they are smaller than $minA$, if it is, make $minA=b_i$ and $indexOfMinA=j$ where $a_j$ is the place where you've added $b_i$ in $A$. Then From $i=k+1$ to $i=n$ search every number $b_i$, where $b_i\in B$. Whenever you see a $b_i >minA$, make $minA=b_i$ and $indexOfMinA = j$. Then replace $a_{indexOfMinA}$ with $b_i$. You have you array.