October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

What Is a DAG? Directed Acyclic Graphs, Explained with an Example

A directed acyclic graph has arrows but no directed cycles. Its nodes can be arranged in a topological order that respects every dependency.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A DAG is a directed acyclic graph: a set of nodes connected by arrows, with no directed route that loops back to its starting node. Because it has no cycles, its nodes can be arranged in a topological order that puts the start of every arrow before its endpoint—a useful way to sequence tasks with prerequisites.

What do “directed” and “acyclic” mean?

A graph consists of vertices (also called nodes) and edges connecting them. In a directed graph, each edge has an orientation, shown as an arrow. “Acyclic” means there is no directed path that starts and ends at the same vertex. NIST defines a DAG as “a directed graph with no path that starts and ends at the same vertex.” NIST Dictionary of Algorithms and Data Structures

As an Amazon Associate I earn from qualifying purchases.

For example, in A → C, the arrow runs from A to C. The graph alone does not tell you what that relationship means; an example must define it. If the nodes are tasks and arrows mean “must finish before,” then A must finish before C.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does a topological order work?

A topological order is a sequence of the graph’s nodes in which every arrow points forward. Formally, for each edge (u, v), node u appears before node v. A DAG has at least one such ordering. LEDA guide to topological sorting

Topological sorting does not add new relationships; it produces an order that respects the arrows already in the graph. When nodes have no path connecting them, the graph may leave their relative order unrestricted, so several different sequences can all be valid. NetworkX DAG reference

Example: ordering tasks with prerequisites

Suppose A and B are independent tasks, and both must be completed before C. The arrows are A → C and B → C. A valid order is A, B, C; another is B, A, C. Both satisfy the dependencies because A and B each come before C. The graph does not require A and B to happen in a particular order.

This is why DAGs are useful for dependency problems: a topological order provides a valid sequence in which prerequisites appear before the work that depends on them. The same reasoning applies to any situation where arrows represent an ordering constraint. The arrows should not be read as proof that one event scientifically causes another; their meaning depends on how the graph is defined. Neo4j graph data science DAG algorithms

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What happens if the graph contains a cycle?

A directed cycle creates a contradiction when arrows mean “must happen before.” For example, if A must precede B, B must precede C, and C must precede A, each task is required to come before itself through the chain. No sequence can place every node before the next while satisfying all three arrows, so there is no topological order for the whole graph.

Be careful with software output when a graph has cycles. Neo4j documents that its topological-sort procedure omits nodes in cycles and nodes that depend on those cycles. A partial result therefore is not necessarily a complete valid schedule. Neo4j topological sort

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.