edited by
153 views
1 votes
1 votes

Consider the following pseudocode for a function that operates on an $N$ element array $A[1],A[2],\dots,A[N]$ of integers.

function mystery (A[1...N])
{
    int i,j,position,tmp;
    for i=1 to N
    {
        position=i;
        for j=i+1 to N
        {
            if(A[j]<A[position])
            {
                position=j;
            }
        }
        tmp=A[i];
        A[i]=A[position];
        A[position]=tmp;
    }
}
  1. Explain what effect the function has on the input array $A$.
  2. If $N=100$, how many times is the comparison $A[i]<A[position]$ checked?
edited by

1 Answer

Related questions

0 votes
0 votes
1 answer
1
soujanyareddy13 asked Jan 29, 2021
168 views
The sum of the diagonal elements of a matrix $A$ is called the trace of $A$ and is denoted by $tr(A)$. Which of the following statements about the trace are true?$\text{t...
0 votes
0 votes
1 answer
2
soujanyareddy13 asked Jan 29, 2021
141 views
For numerical answers, the following forms are acceptable: fractions, decimals, symbolic e.g.:$\left( \begin{array}{c} n \\ r \end{array} \right)^n P_r , n!$ etc.For posi...
0 votes
0 votes
1 answer
4
soujanyareddy13 asked Jan 29, 2021
184 views
Suppose $X$ is a continuous distribution with probability density function$$f(x)=k(x-x^2),\;0\leq x\leq 1,$$where $k$ is the normalizing constant. Find the value of $k$ a...