ProgrammingHard
Which of these statements about in-place transposition is correct?
- A. Any R x C matrix can be transposed in place with the same swap loop
- B. An n x n matrix can be transposed in place by swapping a[i][j] and a[j][i] for j > i
- C. In-place transposition needs an extra row of memory always
- D. Transposition in place is impossible for any matrix
Correct answer: B. An n x n matrix can be transposed in place by swapping a[i][j] and a[j][i] for j > i
For a square matrix the swap loop with j > i touches each pair once. A non-square matrix changes shape, so the swap loop does not apply.
More C Programming questions
- A table of size 5 uses h(k) = k % 5 with linear probing. Keys 15, 5, 10 and 3 are inserted in that order. How many slots are examined when…
- A hash table of size 5 uses h(k) = k mod 5 with linear probing. The keys 5, 10, 15 and 3 are inserted in that order into an empty table…
- A chained table has 4 buckets with h(k) = k % 4. Keys 1 and 5 are inserted with head insertion. Which key is first in bucket 1?
- A hash table starts with capacity 8 and doubles whenever the count exceeds half the capacity. After 9 insertions, what is the capacity?
- In a linear-probing table, slot 1 holds a tombstone and slot 2 holds key 6. A search for 6 begins at slot 1 (its hash). How many slots are…
- A singly linked list of five nodes 1 -> 2 -> 3 -> 4 -> 5 has the node with value 3 unlinked and freed. How many nodes remain?