QUESTION 03
Name two factors in data-structure selection.
2 marksAnswer
Consider the required operations and their frequency, as well as data size, memory limits, order requirements and expected growth.
QUESTION 03
Consider the required operations and their frequency, as well as data size, memory limits, order requirements and expected growth.
QUESTION 04
Choose a structure by the operations the application must perform, rather than by which structure looks most advanced.
A fixed table of marks suits an array because indexed access is direct. A changing sequence with frequent head insertion can suit a linked list. A reverse-order undo history suggests a stack, while arrival-order work suggests a queue. Relationships between cities suggest a graph.
Arrays have contiguous storage and efficient indexed access, but a middle insertion can require shifting. Linked nodes can be relinked efficiently when the relevant location is known, but finding that location may require traversal and each node carries link storage.
Compare whole workloads, not one isolated best-case operation. An operation that first searches n nodes and then relinks one link still has O(n) total search-and-update work. Include input storage, output storage and auxiliary storage deliberately rather than mixing those categories.
State the expected workload, choose a simple correct representation, define an interface, then test boundary cases. A more complicated structure can add maintenance cost without helping a small task. The selected structure must also represent the required logical relationships accurately.