• recategorized by
7,154 views
26 26 votes

Consider an array $A[1...n]$. It consists of a permutation of numbers $1....n$. Now compute another array $B[1...n]$ as follows: $B[A[i]]:= i$ for all $i$. Which of the following is true?

  1. $B$ will be a sorted array.
  2. $B$ is a permutation of array $A$.
  3. Doing the same transformation twice will not give the same array.
  4. $B$ is not a permutation of array $A$.
  5. None of the above.

5 Answers

Best answer
38 38 votes

Option (b) B is a permutation of array A.

In fact, $B$ gives the reverse index of all the elements of array $A$. Since the array $A$ contains numbers $[1 .. n]$ mapped to the locations $[1 .. n]$ and $A$ is a permutation of the numbers $[1 .. n]$, the array $B$ will also be a permutation of the numbers $[1 .. n]$.

For example: $$\begin{array}{l|cccccccc} \text{index} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\[1em] \hline A & 5 & 1 & 3 & 7 & 6 & 2 & 8 & 4\\ B & 2 & 6 & 3 & 8 & 1 & 5 & 4 & 7 \end{array}$$


To see that option c is incorrect, let array $C$ be the array attained from doing the same transformation twice, that is, $C[B[i]] = i , \forall i \in [1 .. n]$. We get, $$\begin{array}{l|cccccccc} \text{index} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\[1em] \hline A & 5 & 1 & 3 & 7 & 6 & 2 & 8 & 4\\ B & 2 & 6 & 3 & 8 & 1 & 5 & 4 & 7\\ C & 5 & 1 & 3 & 7 & 6 & 2 & 8 & 4 \end{array}$$

We can see that $C = A$, which makes option c incorrect.

• edited by
2 2 votes

let n=2
A[1,2] and it consists of a permutation of numbers 1,2 which are 
case 1: (1,2)
case 2: (2,1)
B[A[i]]:=i  for all i (GIVEN)
case 1: B[A[1]]:=1 B[1]:=1
             B[A[2]]:=2 B[2]:=2 so B=(1,2)
case 2: B[A[1]]:=1 B[2]:=1
             B[A[2]]:=2 B[1]:=2 so B=(2,1)
Hence array B have permutation of 1,2

Ans is B


 

2 2 votes

Let n=4 ,so indexes from 1 to 4.

Ex 1 - A[3,2,1,4] then B is B[3,2,1,4]

Ex 2 - A[4,2,1,3] then B is B[3,2,4,1]

From the examples above

Option C - Doing the same transformation twice will not give the same array. is proven false by Ex 1. As A=B.

Option A - B will be a sorted array. is proven false by Ex 2.

Option B - B is a permutation of array A.

From google - meaning of permutation - "each of several possible ways in which a set or number of things can be ordered or arranged.". As we see both Ex 1 and Ex 2 B's are permutations of their A's.

Option D - is false if option B is True.

So Answer is option B.

• edited by
1 1 vote
Given that array is start from 1 to n

let assume A[i] = x; therefore where can be this x in sorted array ? it is at xth position

B[x]=x but we are getting B[x]=i ===> option A is wrong

Note that A[i] given different results because of no repetition of numbers.. that implies every index of B is accessed and moreover we fill the index of B with i which is different ===> B contains the permutation order of A
0 0 votes

Answer : B

Because A and B both contains same data if we consider each element of A contains distinct values.

For example :

Answer:
Position:
Show:

Related questions

20 20 votes
3 answers 3 answers
4.1k
4.1k views
Misbah Ghaya asked Oct 22, 2015
4,111 views
You are given ten rings numbered from $1$ to $10$, and three pegs labeled $A$, $B$, and $C$. Initially all the rings are on peg $A$, arranged from top to bottom in ascend...
5 5 votes
2 2 answers
2.0k
2.0k views
Misbah Ghaya asked Oct 26, 2015
1,953 views
Consider the class of object oriented languages. Which of the following is true?Pascal is an object oriented language.Object oriented languages require heap management.Ob...
19 19 votes
4 answers 4 answers
6.9k
6.9k views
Misbah Ghaya asked Oct 25, 2015
6,926 views
The first $n$ cells of an array $L$ contain positive integers sorted in decreasing order, and the remaining $m - n$ cells all contain 0. Then, given an integer $x$, in ho...
25 25 votes
2 2 answers
8.8k
8.8k views
Misbah Ghaya asked Oct 25, 2015
8,771 views
Consider the class of recursive and iterative programs. Which of the following is false?Recursive programs are more powerful than iterative programs.For every iterative p...