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.

Crash Course Start

Welcome to Day 1

This 30-day crash course is about building enough data structures and algorithms fluency to solve easy and medium problems with confidence.

Today starts with the mental toolkit: data structures.

A data structure is a way to organize data so certain actions become easier:

  • Find something quickly
  • Add or remove items cleanly
  • Keep order
  • Avoid duplicates
  • Model relationships

Over the next lessons, we will build on this foundation with recursion, sorting, hash tables, graphs, divide and conquer, and dynamic programming. For now, focus on one question:

What structure makes this problem easier?

Crash Course Start

Why Structures Matter

Data is not enough

Imagine you have a pile of names:

Mia, Omar, Chen, Ava, Leo

If you only need to print them, almost any format works.

But if you need to answer questions like:

  • Who came first?
  • Is Ava present?
  • Remove the most recent person
  • Process people in arrival order
  • Count each name once

Then the organization matters.

A good data structure matches the problem's most important operations.

Why Structures Matter

Lists Are Workhorses

Python lists

A Python list is usually your first go-to structure.

It is useful when you need:

  • Ordered items
  • Access by position
  • Appending to the end
  • Iterating through everything

Think of a list as a row of boxes, each with an index.

index:   0    1    2    3
value:  10   20   30   40

Lists are excellent for many beginner problems, but not every operation is equally cheap. For example, adding to the end is usually simple, while inserting at the front may require shifting many elements.

```python
numbers = [10, 20, 30, 40]

print("Full list:", numbers)
print("First item:", numbers[0])
print("Last item:", numbers[-1])

numbers.append(50)
print("After append:", numbers)

removed = numbers.pop()
print("Removed:", removed)
print("Final list:", numbers)
```

Pick The Structure

You are modeling people waiting in line at a coffee shop.

The first person who arrives should be the first person served.

Which structure best matches this behavior?

Stacks And Queues

Two simple patterns

Two classic structures appear constantly in algorithm problems:

Stack

A stack is last in, first out.

push A, push B, push C
pop -> C

Use this when the most recent item matters.

Queue

A queue is first in, first out.

enqueue A, enqueue B, enqueue C
dequeue -> A

Use this when arrival order matters.

In Python, collections.deque is a strong practical choice for queues because removing from the left is efficient.

```python
from collections import deque

# Stack using a list
stack = []
stack.append("A")
stack.append("B")
stack.append("C")
print("Stack pop:", stack.pop())
print("Stack now:", stack)

# Queue using deque
queue = deque()
queue.append("A")
queue.append("B")
queue.append("C")
print("Queue popleft:", queue.popleft())
print("Queue now:", list(queue))
```

Index Access

True or false:

If you already know the index, getting items[3] from a Python list is usually fast because Python can jump directly to that position.

Sets And Maps

Membership and labels

Two other everyday structures are set and dict.

Set

A set stores unique values.

Good for questions like:

  • Have I seen this before?
  • Remove duplicates
  • Is this value present?
Dictionary

A dict stores key-value pairs.

Good for questions like:

  • What count belongs to this word?
  • What user data belongs to this ID?
  • What index belongs to this value?

We will study hash tables more deeply later. For now, treat sets and dictionaries as tools for fast membership and lookup.

```python
names = ["Ava", "Leo", "Ava", "Mia", "Leo"]

unique_names = set(names)
print("Unique names:", unique_names)

counts = {}
for name in names:
    counts[name] = counts.get(name, 0) + 1

print("Counts:", counts)
print("Have we seen Mia?", "Mia" in unique_names)
print("Have we seen Omar?", "Omar" in unique_names)
```

Stack Acronym

Fill in the blank:

A stack is often described as last in, first out, abbreviated as ____.

Choose By Operation

Ask the practical question

When solving algorithm problems, beginners often ask:

What data structure should I use?

A better version is:

What operation do I need to do over and over?

Use this quick guide:

Need Consider Keep order and access by index list Add/remove most recent item stack Process oldest item first queue / deque Track unique values set Associate keys with values dict

This habit will make upcoming lessons easier because algorithms are often just smart operation choices repeated many times.

Choose By Operation

Your Review Loop

How to practice today

For this course, you are not just learning concepts once. You are building a review loop.

For today's data structures, practice recognizing the pattern:

  1. Read the problem statement.
  2. Identify the repeated operation.
  3. Pick a structure that makes that operation natural.
  4. Implement the simplest working version.
  5. Revisit the same problem in about 2 days.

That last step matters. Repetition turns recognition into speed.

In the next lesson, we will move from storing data to solving problems where functions call themselves: recursion.

Your Review Loop

Open interactive view →