Challenge your understanding of array insertion and deletion operations, including index handling, shifting elements, time complexity, and common pitfalls encountered in array manipulations. This quiz helps you assess your practical knowledge of working with arrays in computer science.
Given the array [5, 7, 9, 12], what will the array look like after you insert 8 at index 2?
Explanation: Inserting 8 at index 2 pushes the existing and subsequent elements rightward, resulting in [5, 7, 8, 9, 12]. Option B places 8 one index too late, between 9 and 12. Option C incorrectly pushes 7 instead of 9. Option D simply appends 8 without shifting, which is not proper insertion at an index.
If you have an array [3, 6, 9, 12, 15] and you remove the value 9, what is the resulting array?
Explanation: When 9 is removed, elements after it shift left, forming [3, 6, 12, 15]. Option B only removes the last element, which is incorrect. Option C re-inserts 9 at the end. Option D removes the wrong value, keeping 9 and removing 12 instead.
What is the worst-case time complexity of inserting an element at the start of an unsorted fixed-size array?
Explanation: Inserting at the start requires shifting all elements, making the operation O(n) in the worst case. O(1) would only be true for appending or cases with dynamic array pointers. O(log n) and O(n^2) are incorrect; logarithmic time is not typical for array insertions, and O(n^2) is far too high for this operation.
After deleting the element at index 3 from [10, 20, 30, 40, 50], which array is correct?
Explanation: Index 3 refers to the fourth element (40); removing it gives [10, 20, 30, 50]. Option B replaces 30 with 40, which is incorrect. Option C reflects no change, and Option D omits the last value (50), removing the wrong element.
What happens if you try to insert an element into a fixed-size array that is already full?
Explanation: Fixed-size arrays have a maximum capacity; trying to insert another element results in overflow, which often leads to an error. Automatic removal does not happen in standard array structures, nor does the size increase automatically unless implemented. Silently ignoring the operation is not a safe default behavior for array insertions.