Introduction to Data Structures
Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.
Your First Tool
Welcome to the course
You already know basic Python loops and containers. This lesson turns that knowledge into an interview skill: choosing the right way to organize data.
In finance-style interview problems, the story might be about prices, trades, orders, symbols, or schedules. The hidden question is often:
What structure makes the important operation simple?
This first lesson gives you a mental map. Later lessons will zoom into specific structures and analyze their tradeoffs more formally.

Data Structures Matter
A data structure is a decision
A data structure is a way to store data so certain actions become easier.
Common actions include:
- Remember order: What happened first, second, third?
- Find quickly: Have we seen this symbol before?
-
Connect keys to values: What is the current position for
AAPL? - Group related items: Which trades belong to each account?
- Process in a rule-based order: What should be handled next?
In interviews, confusion often starts when you think, “I know Python, but which container do I use?” This course is about building that instinct.

Same Data, Different Job
Lists and sets answer different questions
Suppose you receive a stream of ticker symbols.
A list is useful when the order matters.
A set is useful when you care about uniqueness or asking “have I seen this before?”
Same raw data. Different structure. Different strength.
```python
watchlist = ["AAPL", "MSFT", "AAPL", "NVDA", "MSFT"]
symbols_in_order = []
unique_symbols = set()
for symbol in watchlist:
symbols_in_order.append(symbol)
unique_symbols.add(symbol)
print("Original order:", symbols_in_order)
print("Unique symbols:", sorted(unique_symbols))
print("Have we seen AAPL?", "AAPL" in unique_symbols)
```
Pick The Container
You are tracking which trader IDs are currently active. You do not need duplicates, and you frequently ask: “Is this trader active right now?”
Which Python container is the best first choice?
Shape Of Data
Look for the shape
Before coding, ask what shape the data has.
Sequence: trade1 -> trade2 -> trade3
Key-value: "AAPL" -> 150 shares
Hierarchy: portfolio -> sector -> stock
Network: account A <-> account B <-> account C
The shape hints at the structure.
For now, you do not need to master every structure. You need the habit of asking:
What relationships does my data naturally have?
Upcoming lessons will focus on these shapes one at a time.

Only Easy Code?
True or false: In an interview, you should choose a data structure only because it makes the code look short.
Trades To Positions
A finance-flavored example
Imagine each trade updates your position in a symbol.
Raw trades arrive as a sequence. But the question “what is my current position per symbol?” is a key-value question.
That points us toward a dict: symbol as the key, current position as the value.
```python
trades = [
("AAPL", 10),
("MSFT", 5),
("AAPL", -3),
("NVDA", 8),
]
positions = {}
for symbol, quantity in trades:
positions[symbol] = positions.get(symbol, 0) + quantity
print("AAPL position:", positions["AAPL"])
print("All positions:", positions)
```
Name The Structure
In Python, the container commonly used to map a key like a ticker symbol to a value like its current position is called a ____.
Interview Thinking Loop
A simple loop for problem solving
When you see a new interview problem, pause before coding.
Use this loop:
- Identify the data: What are the items? Trades? Prices? Characters? Nodes?
- Identify the operations: Search? Count? Group? Update? Remove? Process next?
- Choose a structure: Which container makes those operations natural?
- Write clear code: Keep the structure visible in your solution.
- Explain the tradeoff: Say why you chose it.
Interviewers care about your reasoning, not just the final answer.

Why Not Memorize?
Which mindset is most useful when learning data structures for interviews?
What Comes Next
You now have the map
Data structures are not random containers. They are tools for making certain operations easier to express and reason about.
Today’s key idea:
First understand the job your data must do. Then choose the structure.
Next, we will learn how to describe efficiency using time and space complexity. That will give you a more precise way to compare choices in interviews.