What is a data structure?
Options
- A way to organize data, like a list, set or tree (Correct option)
- A building plan for the rooms of a server farm
- A password that protects the data of a database
- A type of error that the compiler can raise
Answer
A way of organizing and storing data so it can be used efficiently, such as a list, dictionary, set or tree
Why
Data has to be arranged somehow in memory. Different arrangements make different operations fast or slow.
- List/array: access by position is fast.
- Dictionary (hash map): look up a value by key is fast.
- Set: check membership and keep unique values.
- Stack and queue: control the order in which items come out.
Choosing the right data structure is half of solving most interview problems.
Remember
Data structure = how data is organized in memory.