PTENES
Skip to content
MODULE 1.1

🔵 What is a graph

Two things: in nodes e edges. That's it. The rest of this module is what you get when you attach information to these two things—direction, weight, cycles— and why this is the foundation for everything that comes next in the course.

6
Topics
40
Minutes
Basic
Level
Baseline
Type
Progress in this module
0%0 of 6
1

⚪ See the Node: The Thing

A graph is a data structure — an organized way to store information — and it consists of just two things. The first is the at the. A node is a thing: a person, a step in your process, a ticket, a document, an AI agent. If you can point to something and say “this here,” it can be a node.

🆕 New here? Three words before you continue

  • Data structure: just a way to store information so you can search it and perform calculations on it. A shopping list is a data structure.
  • AI agent: an AI model (the kind that runs behind ChatGPT or Claude) that, in addition to writing text, does things on its own: searches the web, runs code, edits a file.
  • Node: a thing from your world, represented as a point in the diagram. In code, you’ll see it written as n or node.
person task document agent just nodes, no edges — this is still a list, not a graph

What to look at: four nodes and zero lines. Notice that nothing here tells you anything interesting — it's just a bunch of stuff. A graph only starts to matter when you connect things. That's what we do in the next topic.

✓ Good nodes

  • ✓“Review the text”—a unit of work with a beginning and an end
  • ✓“Customer activated”—a state you can verify
  • ✓“Research agent”—a role with clear responsibility

✗ Bad nodes

  • ✗“Build the product”—too big; the graph doesn’t help you at all
  • ✗“Press Enter”—too small; you drown in detail
  • ✗“Marketing stuff”—vague; nobody knows whether it’s done

Key concepts

Noun

A node is a thing, not an action

Identity

You can point and name

Loads data

Label, owner, cost, state

Granularity

Neither huge nor microscopic

2

➖ Connect with edges: the relationship

The second (and final) piece is the edge — in English edge, written as e in algorithms. An edge is the relationship between two nodes. If the node is a noun, the edge is a verb: “depends on,” “becomes,” “knows,” “delivers the result to.”

💡 The value lies in the edges

A classic mistake for beginners is to carefully design the nodes and treat the edges as decoration. In practice, it’s the opposite: the nodes are usually obvious (everyone knows how to list the steps), and the difficulty — and the value — lies in saying how one thing leads to another.

  • •A digital product by itself doesn’t reach anyone. The edge to the consumer (ad, referral, affiliate) is the hard part.
  • •In an agent graph, the edge is where the decision lives: “if approved, continue; if rejected, go back.”
  • •An edge can also have type — “details,” “contradicts,” “blocks”—and now you have a graph with typed edges.
creates generates reads person task document agent now it’s clear: nodes + labeled edges = graph

What to look at: compare it with the previous diagram — they’re the same four nodes. The only thing that changed was the three labeled lines. And that alone lets you answer questions the list couldn’t: “who produced this document?”, “what does the agent depend on to work?”.

Key concepts

Verb

An edge is a relationship, not a thing

Typed

The relationship may have a name

Where the decision lies

“If X, go to Y”

No edge

Without edges, it’s just a list

3

➡️ Add direction: a one-way street

An edge can work in both directions or just one. When it has an arrow, the graph is directed (directed): it went from A to B and doesn’t return along that edge. Friendship is undirected (if I’m your friend, you’re mine). But “the researcher hands it off to the writer” is directed — the reverse doesn’t make sense.

1

Undirected: the relationship is symmetric

Social network, teammates, “runs on the same server.”

If A relates to B, B relates to A. You draw a line without an arrow and that's it.

2

Directed: the relationship has a direction

Workflow, dependencies, module imports, result delivery.

The arrow is what gives it order to the system. Every agent workflow is directed.

3

Want to go back? That’s another edge

The case “the reviewer rejected it, send it back to the writer.”

Going back isn't “undoing the arrow” — it's drawing a new edge, with its own rule. It will become the cycle in topic 5.

💡 Practical tip

When in doubt about whether an edge is directed, use the sentence test: write the relationship as a sentence (“A delivers the draft to B") and try reversing it (“B gives the draft to A”). If the reversed sentence is false or absurd, the edge is directed.

Key concepts

Arrow = order

Direction creates a sequence

Symmetry

Reversed sentence test

Loop back = new edge

With its own rule

Agents

Agent flow is always directed

4

⚖️ Add Weight: How Much Does It Cost to Pass?

Weight (edge weight, sometimes written as ew) and is a number attached to the edge. Minutes, dollars, tokens, probability, confidence. It’s the ingredient that turns a nice-looking diagram into a structure you can calculate: which path is faster, cheaper, more reliable.

The cheapest example to understand is your morning. You asleep are one node. You awake are another. Two minutes pass between waking up and getting out of bed—that 2 is the weight. Five from getting up to brushing your teeth. Three from brushing your teeth to coffee in the cup. A weighted graph already answers “how long does it take to get from bed to coffee?”—and lets you compare alternative paths.

0 2 5 3 sleeping wake up raise teeth coffee ☕ alternate path: weight 4 (the coffee came in bed) top path = 0+2+5+3 = 10 min · bottom path = 4 min

What to look at: the little numbers above the arrows. Add them up along a path and you get the cost of that path. The dashed cyan line is a shortcut: skips two nodes and costs 4 instead of 10. Finding this kind of shortcut is literally what shortest-path algorithms do—and what you’ll want from your agent graph when the weight is “cost in tokens.”

Whiteboard-style diagram: waking up takes 2 minutes before getting up, getting up takes 5 minutes before brushing your teeth, brushing takes 3 minutes before making coffee, making coffee takes 4 minutes before drinking it, and drinking it takes 8 minutes before leaving home. A yellow arrow goes directly from waking up to making coffee, with a weight of 5 minutes, labeled coffee ready or automated. A legend defines circles as steps, arrows as relationships, and the number as the time weight.
What to look at: the yellow arrow. It skips two nodes and costs 5 minutes, compared with 2+5+3 = 10 for the route above. Two routes, same destination, different costs— this is what the weight lets you see. Without the numbers, the two arrows would look equivalent.

📊 What tends to become overhead in an agent system

  • Tokens / dollar cost — the most concrete: how much that step burns
  • Latency — how long the step takes (it matters if the user is waiting)
  • Confidence — 0 to 1: how much you believe in that transition
  • Risk — how much damage that step causes if it goes wrong (delete a file > read a file)

Key concepts

Number on the edge

Cost, time, confidence

Additive

Path cost = sum

Enables optimization

Without weights, there is no “best”

Can change

Dynamic weight changes the route

5

🔁 Recognize the cycle: a loop is a graph

Cycle is a path that starts at a node and returns to it. When a directed graph no has no cycles, it gets a name you'll hear a lot: DAG, by Directed Acyclic Graph — directed acyclic graph. It has been the standard workflow format for decades (every data pipeline, every build, and every CI system is a DAG).

🎯 The sentence that underpins the entire course

A loop already is a graph — a graph whose path returns to a previous node.

Remember this. When someone announces that “the loop is dead; now it’s a graph,” you’ll know the statement makes no technical sense: a loop is the smallest graph with a cycle. What really changes is how many in nodes you have and how you connect them — and that’s what Tracks 3 and 4 will unpack.

DAG — no way back step A step B end finishes on its own · can be sorted CYCLE — the loop act check needs a stop condition, or it runs forever

What to look at: both sides are graphs. The only difference is the bottom line on the right, which closes the loop. That line has two effects: (1) the graph can now repeat work — which is exactly what you want from an agent — and (2) it loses the guarantee that it will finish. That’s why every cycle needs a stopping condition.

⚠️ Warning: a cycle with no exit = an infinite bill

A DAG ends on its own because there’s nowhere to go back to. A cycle doesn’t. If you connect an agent in a cycle without a repetition limit and a progress criterion, it will run until your credit runs out. Every time you draw a return edge, write next to it when it stops being followed.

Key concepts

Cycle

Path that returns to the start

DAG

Directed and acyclic

Loop = cycle

The minimal graph with a loop

Mandatory stopping

Every return needs an exit

6

🌳 Separate it from the tree (and write your first graph)

Lists, trees, and graphs are the same family with different rules for how many connections each node can have. List: each item points to the next, forming a queue. Tree: each node has exactly one “parent,” nothing loops back. Graph: Anything can connect to anything. Lists and trees are special cases of graphs.

✓ Use a tree when

  • ✓The hierarchy is genuine, and no one depends on a neighboring branch
  • ✓You only need “contains / is inside”
  • ✓Folders, book chapters, navigation menu

✗ Don’t force a tree when

  • ✗One story depends on another story from another epic
  • ✗Two modules import the same third module
  • ✗The reviewer returns the work to the writer (that is a cycle)

🧪 Practical example: write your first graph

Objective: turn one of your processes into a JSON graph and see the computer answer questions about it. You don’t need to install anything—it runs in your browser’s own console (F12 → Console) or in Node.

// 1) O grafo: lista de adjacencia + pesos (minutos)
const grafo = {
  "dormindo": { "acordar": 0 },
  "acordar":  { "levantar": 2, "cafe": 4 },   // 'cafe' e o atalho
  "levantar": { "dentes": 5 },
  "dentes":   { "cafe": 3 },
  "cafe":     {}
};

// 2) Todos os caminhos de um no ate outro, com custo
function caminhos(g, de, ate, visitados = [], custo = 0) {
  if (de === ate) return [{ rota: [...visitados, de], custo }];
  if (visitados.includes(de)) return [];          // corta ciclo
  return Object.entries(g[de] || {}).flatMap(([viz, peso]) =>
    caminhos(g, viz, ate, [...visitados, de], custo + peso)
  );
}

const r = caminhos(grafo, "dormindo", "cafe");
r.sort((a, b) => a.custo - b.custo);
r.forEach(c => console.log(c.custo + " min:", c.rota.join(" → ")));

How to verify: you should see two lines — 4 min: dormindo → acordar → cafe e 10 min: dormindo → acordar → levantar → dentes → cafe. If both appear, your graph is correct and you just ran a path search.

Now swap it for yours: replace the nodes with <etapas do seu processo> and the weights for <minutos, reais ou tokens>. If more than one path appears, you've found a decision that your process was making automatically.

Quick check (doesn’t block anything): an agent that tries, tests, and tries again until it passes—which structure is that?

Key concepts

Family

List ⊂ tree ⊂ graph

Graph signal

Cross-dependency

Adjacency

Node dictionary → neighbors

JSON is enough

No framework needed

📌 Module Summary

✓
Node = thing — a noun, with identity and data. Neither gigantic nor microscopic.
✓
Edge = relationship — verb. That’s where the decision and value live.
✓
Direction = order — every agent flow is directed; going back is another edge.
✓
Weight = cost — without weights, there is no “best path.” For agents: tokens, latency, confidence, risk.
✓
Cycle = loop — a loop is the smallest graph with a return path. Without a cycle, it's a DAG and ends on its own.
✓
A tree becomes a graph — the moment the first cross-dependency appears.

Next Module:

1.2 — Graphs in the real world: your morning, LinkedIn, your SaaS funnel, and your team's backlog.