+1 vote
in Data Structures & Algorithms I by (110k points)
How many swaps are required for reversing an array having n elements where n is an even number?

(a) (n-1) / 2

(b) n/2

(c) (n/2) – 1

(d) (n+1)/2

Question is from Arrays Types in chapter Arrays Types of Data Structures & Algorithms I

I had been asked this question in unit test.

1 Answer

+1 vote
by (444k points)
selected by
Best answer
Correct choice is (b) n/2

To explain: The number of swaps required for an odd element and an even element array is different because in an odd element array the position of the middle element does not need to be changed. So number of swaps required will be n/2.

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.