What happens when you delete the first element of an array?
The first element is removed, and all other elements shift one position to the left to fill the gap.
Click to reveal answer
beginner
Why do elements shift left after deleting the first element in an array?
Because arrays have fixed positions, shifting left keeps the array continuous without empty spaces.
Click to reveal answer
intermediate
What is the time complexity of deleting the first element in a simple array?
O(n), because all elements after the first must be moved one step left.
Click to reveal answer
beginner
Show the array after deleting the first element from [5, 10, 15, 20].
After deletion, the array becomes [10, 15, 20].
Click to reveal answer
intermediate
What is a drawback of deleting the first element in an array?
It requires shifting all elements, which can be slow for large arrays.
Click to reveal answer
What must happen to the elements after deleting the first element in an array?
AThey shift one position to the right
BThey stay in the same place
CThey shift one position to the left
DThey are all deleted
✗ Incorrect
After deleting the first element, all other elements move left to fill the empty space.
What is the time complexity of deleting the first element in an array of size n?
AO(1)
BO(n)
CO(log n)
DO(n^2)
✗ Incorrect
Because all elements after the first must be shifted left, the operation takes O(n) time.
If the array is [3, 6, 9, 12], what is the array after deleting the first element?
A[12]
B[3, 6, 9]
C[9, 12]
D[6, 9, 12]
✗ Incorrect
Deleting the first element (3) shifts the rest left, resulting in [6, 9, 12].
Why is deleting the first element in an array slower than deleting the last element?
ABecause deleting the first requires shifting all elements
BBecause the first element is always the largest
CBecause arrays cannot delete elements
DBecause the last element is always zero
✗ Incorrect
Deleting the first element requires shifting all other elements left, which takes more time.
What happens to the array size after deleting the first element?
AIt decreases by one
BIt increases by one
CIt stays the same
DIt doubles
✗ Incorrect
Deleting an element reduces the array size by one.
Explain step-by-step what happens when you delete the first element of an array.
Think about how the array stays continuous without gaps.
You got /3 concepts.
Why does deleting the first element in an array take more time than deleting the last element?
Consider how many elements need to move.
You got /3 concepts.
Practice
(1/5)
1. What happens to the elements of an array when you delete the first element (at the beginning)?
easy
A. All elements shift one position to the left, and the first element is removed.
B. All elements shift one position to the right, and the last element is removed.
C. The array size increases by one.
D. The array remains unchanged.
Solution
Step 1: Understand array deletion at beginning
Deleting the first element means removing the element at index 0.
Step 2: Effect on remaining elements
All other elements move one position left to fill the gap, reducing the array size by one.
Final Answer:
All elements shift one position to the left, and the first element is removed. -> Option A
Quick Check:
Delete first element = shift left [OK]
Hint: Deleting first element shifts all others left by one [OK]
Common Mistakes:
Thinking elements shift right instead of left
Assuming array size stays the same
Believing the array remains unchanged
2. Which of the following Java code snippets correctly deletes the first element from an integer array arr and shifts the remaining elements left?
easy
A. for (int i = 1; i < arr.length; i++) { arr[i] = arr[i - 1]; }
B. for (int i = arr.length - 1; i > 0; i--) { arr[i] = arr[i - 1]; }
C. for (int i = 0; i < arr.length - 1; i++) { arr[i] = arr[i + 1]; }
D. for (int i = 0; i < arr.length; i++) { arr[i + 1] = arr[i]; }
Solution
Step 1: Identify correct loop direction and indices
To shift elements left, start from index 0 to length-2, assigning arr[i] = arr[i+1].
Step 2: Check each option
for (int i = 0; i < arr.length - 1; i++) { arr[i] = arr[i + 1]; } matches this logic; others shift right or use wrong indices causing errors.
Final Answer:
for (int i = 0; i < arr.length - 1; i++) { arr[i] = arr[i + 1]; } -> Option C
Quick Check:
Shift left loop: i from 0 to length-2 [OK]
Hint: Shift left by copying arr[i+1] to arr[i] in forward loop [OK]
Common Mistakes:
Looping backwards when shifting left
Using wrong indices causing ArrayIndexOutOfBounds
Assigning arr[i-1] instead of arr[i+1]
3. What is the output of the following Java code?
int[] arr = {10, 20, 30, 40, 50};
for (int i = 0; i < arr.length - 1; i++) {
arr[i] = arr[i + 1];
}
arr[arr.length - 1] = 0;
for (int num : arr) {
System.out.print(num + " ");
}
medium
A. 20 30 40 50 0
B. 10 20 30 40 50
C. 0 10 20 30 40
D. 50 40 30 20 10
Solution
Step 1: Trace the shifting loop
Each element moves left: arr[0]=20, arr[1]=30, arr[2]=40, arr[3]=50.
Step 2: Set last element to 0
arr[4] is set to 0 explicitly.
Final Answer:
20 30 40 50 0 -> Option A
Quick Check:
Shift left + last zero = 20 30 40 50 0 [OK]
Hint: After shift, last element set to zero to fill gap [OK]
Common Mistakes:
Forgetting to set last element to zero
Printing original array without shift
Confusing shift direction
4. The following code attempts to delete the first element of an array but causes an error. What is the error?
int[] arr = {1, 2, 3, 4};
for (int i = 0; i <= arr.length - 1; i++) {
arr[i] = arr[i + 1];
}
medium
A. Logical error: elements shift right instead of left
B. ArrayIndexOutOfBoundsException at i = 3
C. Syntax error due to missing semicolon
D. No error, code runs fine
Solution
Step 1: Analyze loop range
The loop runs i from 0 to arr.length - 1 (i.e., 0 to 3).
Step 2: Identify out-of-bounds access
At i=3, arr[i+1] = arr[4] is accessed, which is outside array bounds causing exception.
Final Answer:
ArrayIndexOutOfBoundsException at i = 3 -> Option B
Quick Check:
Accessing arr[4] in length 4 array causes exception [OK]
Hint: Loop till length-2 to avoid out-of-bounds [OK]
Common Mistakes:
Using <= instead of < in loop condition
Ignoring array length limits
Assuming code runs without error
5. Given an array arr = {5, 10, 15, 20, 25}, write the output after deleting the first element twice using the standard shift-left method and setting the last element to zero each time. What is the final state of the array?
hard
A. [5, 10, 15, 20, 25]
B. [10, 15, 20, 25, 0]
C. [0, 0, 15, 20, 25]
D. [15, 20, 25, 0, 0]
Solution
Step 1: First deletion
Shift left: arr becomes [10, 15, 20, 25, 0]
Step 2: Second deletion
Shift left again: arr becomes [15, 20, 25, 0, 0]
Final Answer:
[15, 20, 25, 0, 0] -> Option D
Quick Check:
Two shifts left + zeros at end = [15, 20, 25, 0, 0] [OK]
Hint: Each deletion shifts left and adds zero at end [OK]
Common Mistakes:
Deleting only once instead of twice
Not setting last element to zero after shift
Confusing order of elements after shifts
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.