Question:

A one-dimensional array has n elements stored from 0th position to (n-1)th position. How many elements need to be moved to insert an element at pth position of the array?

Show Hint

Inserting an element in the middle of an array requires shifting all the elements after the insertion point.
Updated On: May 3, 2025
  • \( n - p + 1 \)
  • \( n - p \)
  • \( n \)
  • \( p \)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

To insert an element at the \( p \)-th position in a one-dimensional array, all the elements after the \( p \)-th position must be shifted one position to the right.
Therefore, the number of elements that need to be moved is \( n - p \), where \( n \) is the total number of elements in the array.
Thus, the correct answer is \( n - p \).
Was this answer helpful?
0
0

Top Questions on Data Structures

View More Questions