• edited by
87 views
0 0 votes

Consider the following pseudo-code for reversing an array $A$.
Algorithm ReverseArray(A[l..r])
// Input: an array A[l..r]
// Output: the array A in reverse order
if ..... then
  Swap A[l] and A[r]
  REVERSEARRAY (A[l+1..r-1])


For what condition in the if clause, the above pseudo-code will correctly reverse the array $A$ ?

  1. $r \geq 0$
  2. $\ell \neq r$
  3. $l \leq r$
  4. $l < r$

1 Answer

Position:
Show:

Related questions

0 0 votes
1 1 answer
81
81 views
Shubham Sharma 2 asked May 18
81 views
Let $S=\{1,\{2\},\{3,4\}\}$ and $\mathcal{P}$ be the power set of $S$. Which of the following is false?$\{1\}$ is in $\mathcal{P}$.$\{1,\{3,4\}\}$ is in $\mathcal{P}$.$\{...
0 0 votes
1 1 answer
105
105 views
Shubham Sharma 2 asked May 18
105 views
Let $R$ be an equivalence relation on a set with $7$ elements. Which of the following is not possible for the relation $R$?There are $2$ different equivalence classes, ea...
0 0 votes
1 1 answer
61
61 views
Shubham Sharma 2 asked May 18
61 views
The number of vectors $\left(x_{1}, x_{2}, \ldots, x_{n}\right)$ such that each $x_{i}$ is a non-negative integer and $\sum_{i=1}^{n} x_{i} \leq k$, where $k$ is a non-ne...
0 0 votes
1 1 answer
63
63 views
Shubham Sharma 2 asked May 18
63 views
Let $X_{1}, X_{2}$ and $X_{3}$ be independent and identically distributed random variables defined as follows: for $i=1,2,3$,$$X_{i}=\left\{\begin{array}{ll}-1 & \text { ...