InterviewSolution
Saved Bookmarks
| 1. |
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)/2Question is from Arrays Types in chapter Arrays Types of Data Structures & Algorithms II had been asked this question in unit test. |
|
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. |
|