Consider two data structures: an array and a linked list. Which statement best explains how choosing one over the other affects system performance when accessing elements?
Think about how memory layout affects how quickly you can find an element by its position.
Arrays store elements in continuous memory locations, so accessing an element by index is fast (constant time). Linked lists store elements scattered in memory with pointers, so accessing by index requires traversing nodes, which is slower.
Which data structure typically provides the fastest average-case search time for unordered data?
Consider which structure uses a key to directly locate data.
Hash tables use a hash function to compute an index, allowing average-case constant time search. Arrays and linked lists require scanning elements, and binary trees have logarithmic search time if balanced.
Which data structure generally uses more memory overhead per element and why?
Think about what extra information each element must keep besides the data itself.
Linked lists store a pointer/reference with each element to link to the next node, increasing memory usage. Arrays store only the data contiguously without extra pointers. Hash tables have overhead but not per element pointer like linked lists. Stacks are often implemented using arrays or linked lists.
Which data structure allows the fastest insertion of a new element at the beginning?
Consider how many elements need to be moved or updated when inserting at the start.
Linked lists allow insertion at the beginning by updating the head pointer and the new node's next pointer, which is very fast. Arrays require shifting all elements to make space, which is slower. Binary trees and hash tables have different insertion logic and are not optimized for beginning insertion.
Imagine a system that frequently needs to check if an item exists and also iterate over all items in order. Which data structure choice would likely cause the worst performance and why?
Think about the cost of searching and iterating in each structure.
Linked lists require scanning each element to check existence, which is slow for large data. Iteration is sequential but slow for existence checks. Balanced trees and hash tables optimize existence checks. Arrays sorted after every insertion have slow insertion but fast iteration.