Data structure decisions
The most useful data-structure question is not “Which structure is best?” It is “What does the program need to do often?” Start with the requirements collected in Data structures, then match each operation to a structure whose rules fit it.
Start with the operation
| Help desk requirement | Question to ask | A likely fit |
|---|---|---|
| On-call slots | Do positions and capacity matter? | Array |
| Growing report log | Do reports remain ordered as they arrive? | List |
| Report lookup | Does an ID lead to one ticket? | Dictionary |
| Duplicate events | Is membership the only question? | Set |
| Routine assignment | Should the oldest waiting report go first? | Queue |
| Undo history | Should the latest action be removed first? | Stack |
| Urgent incidents | Should priority decide what comes next? | Priority queue |
| Related reports | Can reports connect in many directions? | Graph |
Order and position
An array provides indexed positions and is a good fit for the four bounded on-call slots. A list keeps the same ordered-sequence idea while making it easier to add or remove reports as the log changes.
Both can search by scanning, which is typically O(n). Both can usually read by index in O(1). The distinction is primarily the capacity rule: the array represents a known bound, while the list represents a changing report log.
Uniqueness and lookup
A set answers “Have we seen this event?” without storing duplicates. A dictionary answers “Which ticket belongs to this ID?” These structures often provide average O(1) membership or lookup, but they do not automatically preserve every ordering or relationship the program might need.
Choose a set when the event ID itself is the thing being checked. Choose a dictionary when a key must lead to a ticket.
Rules for taking items out
A stack removes the newest action first (LIFO). A queue removes the oldest report first (FIFO). A priority queue removes the most urgent incident first. These structures may all support adding and removing efficiently, but they answer different correctness requirements.
The structure should make the program’s rule easy to see. A correct, understandable O(n) scan can be better than a complicated structure that is theoretically faster but does not match the actual requirements.
Apply this table to the same help desk one structure at a time.