Which statement correctly describes the memory usage difference between linked lists and arrays?
Think about what extra information each element in a linked list must keep compared to an array.
Each node in a linked list stores the data plus a pointer to the next node, which uses extra memory. Arrays store elements contiguously without extra pointers.
Which data structure provides faster access to an element by index, and why?
Consider how you find the 5th element in each structure.
Arrays store elements contiguously, so accessing an element by index is direct and fast. Linked lists require traversing nodes one by one.
Why is inserting an element in the middle of a linked list generally faster than in an array?
Think about what happens to elements after the insertion point in each structure.
Inserting in an array requires moving all elements after the insertion point to make space. Linked lists only need to update pointers, which is faster.
In which scenario is using an array generally better than a linked list?
Consider the strengths of arrays in terms of access speed and memory layout.
Arrays provide fast indexed access and are efficient when the size is known and does not change often. Linked lists are better for frequent insertions/deletions.
How does cache locality affect the performance difference between arrays and linked lists?
Think about how CPUs load data from memory into cache lines.
Arrays store elements next to each other in memory, so CPUs can load multiple elements at once into cache, speeding up access. Linked lists store elements scattered in memory, reducing cache efficiency.