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 we need to shift elements after deleting the first element in an array?
Because arrays have fixed positions, shifting keeps the array continuous without empty spaces.
Click to reveal answer
beginner
Show the array after deleting the first element from [10, 20, 30, 40].
After deletion, the array becomes [20, 30, 40]. The elements 20, 30, and 40 shift left by one position.
Click to reveal answer
intermediate
What is the time complexity of deleting the first element in an array?
It is O(n) because all elements after the first must be shifted one position to the left.
Click to reveal answer
intermediate
Can we delete the first element of an array without shifting elements?
No, because arrays store elements in continuous memory. To keep order, shifting is necessary.
Click to reveal answer
What must be done after deleting the first element of an array?
ADo nothing
BShift all elements to the left by one position
CReplace the first element with zero
DShift all elements to the right by one position
✗ Incorrect
After deleting the first element, all other elements must shift 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(log n)
CO(n)
DO(n^2)
✗ Incorrect
Deleting the first element requires shifting all other n-1 elements, so time complexity is O(n).
If the array is [5, 10, 15], what is the array after deleting the first element?
A[]
B[5, 10, 15]
C[15, 10]
D[10, 15]
✗ Incorrect
The first element 5 is removed, and the rest shift left, resulting in [10, 15].
Why can't we just mark the first element as deleted without shifting?
ABecause arrays require continuous memory without gaps
BBecause marking is not allowed in arrays
CBecause shifting is faster
DBecause arrays are linked lists
✗ Incorrect
Arrays store elements in continuous memory, so gaps are not allowed; shifting maintains continuity.
What happens to the size of the array after deleting the first element?
AIt decreases by one logically
BIt increases by one
CIt stays the same
DIt doubles
✗ Incorrect
Logically, the array size decreases by one because one element is removed.
Explain step-by-step how to delete the first element of an array and update the array.
Think about what happens to each element after deletion.
You got /4 concepts.
Describe the time complexity of deleting the first element in an array and why it is that way.
Consider how many elements move after deletion.
You got /4 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 right, and the last element is removed.
B. All elements shift one position to the left, and the first element is removed.
C. The array size increases by one.
D. The array remains unchanged.
Solution
Step 1: Understand 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.
Final Answer:
All elements shift one position to the left, and the first element is removed. -> Option B
Quick Check:
Deletion at start shifts elements left [OK]
Hint: Deleting start shifts all elements left by one [OK]
Common Mistakes:
Thinking elements shift right instead of left
Assuming array size increases
Believing array stays unchanged
2. Which of the following C code snippets correctly deletes the first element of an integer array arr of size n by shifting elements left?
easy
A. for(int i = 0; i < n; i++) { arr[i] = arr[i]; } n--;
B. for(int i = n - 1; i > 0; i--) { arr[i] = arr[i - 1]; } n++;
C. for(int i = 0; i < n - 1; i++) { arr[i] = arr[i + 1]; } n--;
D. for(int i = 1; i < n; i++) { arr[i] = arr[i - 1]; } n--;
Solution
Step 1: Identify correct loop for shifting left
The loop must start from index 0 and assign arr[i] = arr[i+1] up to n-2.
Step 2: Check array size update
After shifting, size decreases by 1 (n--).
Final Answer:
for(int i = 0; i < n - 1; i++) { arr[i] = arr[i + 1]; } n--; -> Option C
Quick Check:
Shift left from 0 to n-2, then reduce size [OK]
Hint: Shift elements left from 0 to n-2, then decrease size [OK]
Common Mistakes:
Looping backwards instead of forwards
Increasing size instead of decreasing
Incorrect loop bounds causing overwrite
3. What is the output array after deleting the first element from int arr[] = {10, 20, 30, 40, 50}; using the correct deletion method?
medium
A. [50, 40, 30, 20]
B. [10, 20, 30, 40]
C. [30, 40, 50]
D. [20, 30, 40, 50]
Solution
Step 1: Remove first element 10
Deleting first element removes 10 from the array.
Step 2: Shift remaining elements left
Elements 20, 30, 40, 50 shift left to fill index 0 to 3.
Final Answer:
[20, 30, 40, 50] -> Option D
Quick Check:
First element removed, others shifted left [OK]
Hint: After deletion, array starts from second element [OK]
Common Mistakes:
Leaving original first element in array
Removing last element instead
Reversing array order
4. Consider this code snippet for deleting the first element of an array:
for(int i = 1; i < n; i++) { arr[i-1] = arr[i]; } n--;
What is the error in this code?
medium
A. The loop correctly shifts elements; no error present.
B. The loop should start from i = 0, not 1.
C. The array size should be increased, not decreased.
D. The assignment should be arr[i] = arr[i-1], not arr[i-1] = arr[i].
Solution
Step 1: Analyze loop start and assignments
The loop starts at i=1 and assigns arr[i-1] = arr[i], shifting elements left correctly.
Step 2: Check array size update
Decreasing n by 1 after shifting is correct to reflect deletion.
Final Answer:
The loop correctly shifts elements; no error present. -> Option A
Quick Check:
Loop from 1 with arr[i-1]=arr[i] shifts left [OK]
Hint: Loop from 1 with arr[i-1]=arr[i] shifts left correctly [OK]
Common Mistakes:
Thinking loop must start at 0 for shifting left
Confusing assignment direction
Incorrectly changing array size
5. You have an array int arr[] = {5, 10, 15, 20, 25, 30}; and size n = 6. You delete the first element twice using the correct deletion method. What is the resulting array and size?
hard
A. Array: [15, 20, 25, 30], Size: 4
B. Array: [10, 15, 20, 25, 30], Size: 5
C. Array: [5, 10, 15, 20], Size: 4
D. Array: [20, 25, 30], Size: 3
Solution
Step 1: First deletion removes 5
After first deletion, array becomes [10, 15, 20, 25, 30], size 5.
Step 2: Second deletion removes 10
After second deletion, array becomes [15, 20, 25, 30], size 4.
Final Answer:
Array: [15, 20, 25, 30], Size: 4 -> Option A
Quick Check:
Two deletions remove first two elements, size reduces by 2 [OK]
Hint: Each deletion removes first element and reduces size by one [OK]
Common Mistakes:
Not updating size after each deletion
Deleting wrong elements
Confusing array indexes after shifts
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.