AlgoDaily

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.

Welcome To Structures

Why this lesson matters

This is the first lesson of your 30-day crash course, so we are setting up the vocabulary and mental models you will reuse every day.

A data structure is a way to organize data so your program can use it effectively.

In Python, you already have powerful built-ins like:

  • list
  • tuple
  • dict
  • set

Over the next lessons, we will add algorithms, complexity, recursion, trees, graphs, dynamic programming, and problem-solving patterns. But first: you need to recognize what kind of container your data wants to live in.

Welcome To Structures

Data Has Shape

Data structures are shapes for information

Think of data as items you need to store, find, update, or remove.

Different structures support different habits:

  • A list keeps items in order.
  • A set keeps unique items.
  • A dictionary connects keys to values.
  • A stack lets you remove the most recently added item first.
  • A queue lets you remove the oldest added item first.

The goal is not to memorize names. The goal is to ask:

What operations will I perform most often?

That question will guide many algorithm choices later in the course.

Data Has Shape

Python Containers

Your first toolbox

Python gives you several data structures immediately. Here is a small tour.

Notice how each one answers a different kind of question:

  • list: What is at position 0, 1, 2...?
  • tuple: What fixed group of values belongs together?
  • dict: What value is attached to this key?
  • set: Have I seen this item before?
```python
# A quick tour of Python's core containers

scores = [90, 85, 100]                 # list: ordered, changeable
point = (3, 4)                         # tuple: ordered, usually fixed
profile = {"name": "Ada", "level": 1} # dict: key -> value
seen = {"apple", "banana", "apple"}   # set: unique values only

print("scores:", scores)
print("first score:", scores[0])
print("point:", point)
print("name:", profile["name"])
print("seen:", seen)
print("unique fruit count:", len(seen))
```

Choose The Structure

You are building a small program that tracks whether a username has already been taken.

Which data structure is the most natural first choice?

Operations Matter

Think in operations

When choosing a data structure, name the actions your program needs.

Common operations include:

  • Access: get an item
  • Search: find whether an item exists
  • Insert: add an item
  • Delete: remove an item
  • Update: change an item
  • Iterate: visit every item

For now, do not worry about formal runtime notation — that comes in the next lesson, Algorithm Basics and Complexity Analysis.

Today, just build the habit of connecting a structure to the operations it makes feel natural.

Operations Matter

List Behavior

Lists: ordered and flexible

A Python list is often the first structure beginners reach for — and for good reason.

Lists are useful when:

  • order matters
  • you need index access like items[0]
  • you want to append new items
  • duplicates are allowed

They are not always the best choice for every problem, but they are a great starting point.

```python
# Lists keep order and allow duplicates

tasks = ["read", "practice", "review"]
print("starting tasks:", tasks)

# Add to the end
tasks.append("sleep")
print("after append:", tasks)

# Access by index
print("first task:", tasks[0])

# Update by index
tasks[1] = "solve problems"
print("after update:", tasks)

# Remove by value
tasks.remove("review")
print("after remove:", tasks)
```

Order Always Matters

True or false:

If two problems both store many values, they should usually use the same data structure.

Stacks And Queues

Two simple access rules

Some structures are less about what they store and more about the order in which items come out.

Stack

A stack is last-in, first-out.

Example: a pile of plates. You remove the top plate first.

Queue

A queue is first-in, first-out.

Example: a line at a coffee shop. The first person in line is served first.

You will see these ideas again in recursion, backtracking, trees, and graphs.

```python
from collections import deque

# Stack using a list
stack = []
stack.append("A")
stack.append("B")
stack.append("C")
print("stack before:", stack)
print("stack pop:", stack.pop())  # C comes out first
print("stack after:", stack)

# Queue using deque
queue = deque()
queue.append("A")
queue.append("B")
queue.append("C")
print("queue before:", list(queue))
print("queue popleft:", queue.popleft())  # A comes out first
print("queue after:", list(queue))
```

Name The Rule

A data structure where the most recently added item is removed first is called a ____.

Review Loop

Your 30-day rhythm

This course is a crash course, so retention matters as much as exposure.

A useful practice loop:

  1. Learn a structure or pattern.
  2. Solve 1–3 easy or medium problems using it.
  3. Revisit the same problems after about 2 days.
  4. Explain why the chosen structure fits.
  5. Try a small variation.

For this lesson, your target is simple:

When you see a problem, identify the data being stored and the operations being performed.

Next, we will attach a more precise language to efficiency in Algorithm Basics and Complexity Analysis.

Review Loop

Open interactive view →