Question 7.
MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Question 7. (Prog. Concept Question) Data Structures
Which of the following is/are true regarding Arrays and linked lists?
Pick ONE OR MORE options
Show answer & explanation
Option A is correct: arrays have fixed size (determined at creation), while linked lists grow/shrink dynamically. Option C is correct: deletion requires shifting elements in arrays (O(n) worst case), whereas linked lists need only pointer updates (O(1) after finding the node). Option B is false because insertion at the beginning of a linked list is O(1), faster than arrays. Option D is false because linked lists require sequential traversal; only arrays support true O(1) random access.
Step-by-step Derivation:
Analysis of each statement:
A) TRUE — Arrays: size fixed at declaration/creation. Linked lists: dynamic, nodes allocated as needed.
B) FALSE — Counterexample: insertion at head of linked list is O(1); insertion at end of array (if space available) is O(1). Insertion at beginning of array is O(n) due to shifting, but insertion at beginning of linked list is O(1).
C) TRUE — Arrays: deletion requires shifting remaining elements (O(n) in worst case). Linked lists: deletion requires only pointer updates after locating the node (O(1) once located).
D) FALSE — Arrays: access element i in O(1) via index. Linked lists: must traverse from head sequentially, O(n) to access element at position i. No random access in linked lists.