Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Interview Problems on Graph
  • Practice Graph
  • MCQs on Graph
  • Graph Tutorial
  • Graph Representation
  • Graph Properties
  • Types of Graphs
  • Graph Applications
  • BFS on Graph
  • DFS on Graph
  • Graph VS Tree
  • Transpose Graph
  • Dijkstra's Algorithm
  • Minimum Spanning Tree
  • Prim’s Algorithm
  • Topological Sorting
  • Floyd Warshall Algorithm
  • Strongly Connected Components
  • Advantages & Disadvantages
Open In App
Next Article:
Longest Path in a Directed Acyclic Graph
Next article icon

Introduction to Directed Acyclic Graph

Last Updated : 08 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

A Directed Acyclic Graph, often abbreviated as DAG, is a fundamental concept in graph theory. DAGs are used to show how things are related or depend on each other in a clear and organized way. In this article, we are going to learn about Directed Acyclic Graph, its properties, and application in real life.



dag-banners
Directed Acyclic Graph

What is Directed Acyclic Graph?

A Directed Acyclic Graph (DAG) is a directed graph that does not contain any cycles.

Below Graph represents a Directed Acyclic Graph (DAG):

dag6-660x478
Direct Acyclic Graph

Meaning of Directed Acyclic Graph:

Directed Acyclic Graph has two important features:

  • Directed Edges: In Directed Acyclic Graph, each edge has a direction, meaning it goes from one vertex (node) to another. This direction signifies a one-way relationship or dependency between nodes.
  • Acyclic: The term "acyclic" indicates that there are no cycles or closed loops within the graph. In other words, you cannot traverse a sequence of directed edges and return to the same node, following the edge directions. Formation of cycles is prohibited in DAG. Hence this characteristic is essential.
Untitled-Diagram-(2)
Directed Acyclic Graph

Properties of Directed Acyclic Graph DAG:

Directed Acyclic Graph (DAG) has different properties that make them usable in graph problems.

There are following properties of Directed Acyclic Graph (DAG):

  • Reachability Relation: In DAG, we can determine if there is a reachability relation between two nodes. Node A is said to be reachable from node B if there exists a directed path that starts at node B and ends at node A. This implies that you can follow the direction of edges in the graph to get from B to A.
  • Transitive Closure:The transitive closure of a directed graph is a new graph that represents all the direct and indirect relationships or connections between nodes in the original graph. In other words, it tells you which nodes can be reached from other nodes by following one or more directed edges.


1-(2)
Transitive Closure of Directed Acyclic Graph


  • Transitive Reduction: The transitive reduction of a directed graph is a new graph that retains only the essential, direct relationships between nodes, while removing any unnecessary indirect edges. In essence, it simplifies the graph by eliminating edges that can be inferred from the remaining edges.


2-(1)
Transitive Reduction of Directed Acyclic Graph


  • Topological Ordering: A DAG can be topologically sorted, which means you can linearly order its nodes in such a way that for all the edges, start node of the edge occurs earlier in the sequence. This property is useful for tasks like scheduling and dependency resolution.



3-(1)
Topological Ordering of Directed Acyclic Graph


Practical Applications of DAG:

  • Data flow Analysis: In compiler design and optimization, DAGs are used to represent data flow within a program. This aids in optimizing code by identifying redundant calculations and dead code. DAGs are also used to represent the structure of basic blocks in Compiler Design.
  • Task Scheduling: DAGs are used in project management and job scheduling. Each task or job is represented as a node in the DAG, with directed edges indicating dependencies. The acyclic nature of the DAG ensures tasks are scheduled in a logical order, preventing circular dependencies.

A weighted directed acyclic graph can be used to represent a scheduling problem. Let's take the example of a task scheduling problem. Here, a vertex can represent the task and its weight can represent the size of the task computation. Similarly, an edge can represent the communication between two tasks and its weight can represent the cost of communication:


4-(1)
Task Scheduling in Directed Acyclic Graph


Conclusion:

In summary, Directed Acyclic Graphs are a fundamental concept of graph theory with numerous practical applications. DAGs play a crucial role in task scheduling, data flow analysis, dependency resolution, and various other areas of computer science and engineering. They help optimize processes, manage dependencies, and ensure efficient execution of tasks or jobs.


Next Article
Longest Path in a Directed Acyclic Graph

P

pinki___gfg
Improve
Article Tags :
  • Graph
  • DSA
Practice Tags :
  • Graph

Similar Reads

  • Shortest Path in Directed Acyclic Graph
    Given a Weighted Directed Acyclic Graph and a source vertex in the graph, find the shortest paths from given source to all other vertices. Recommended PracticeShortest path from 1 to nTry It! For a general weighted graph, we can calculate single source shortest distances in O(VE) time using Bellman–
    15 min read
  • Longest Path in a Directed Acyclic Graph
    Given a Weighted Directed Acyclic Graph (DAG) and a source vertex s in it, find the longest distances from s to all other vertices in the given graph. The longest path problem for a general graph is not as easy as the shortest path problem because the longest path problem doesn’t have optimal substr
    15+ min read
  • Longest Path in a Directed Acyclic Graph | Set 2
    Given a Weighted Directed Acyclic Graph (DAG) and a source vertex in it, find the longest distances from source vertex to all other vertices in the given graph. We have already discussed how we can find Longest Path in Directed Acyclic Graph(DAG) in Set 1. In this post, we will discuss another inter
    14 min read
  • Detect Cycle in a Directed Graph
    Given the number of vertices V and a list of directed edges, determine whether the graph contains a cycle or not. Examples: Input: V = 4, edges[][] = [[0, 1], [0, 2], [1, 2], [2, 0], [2, 3]] Output: trueExplanation: The diagram clearly shows a cycle 0 → 2 → 0 Input: V = 4, edges[][] = [[0, 1], [0, 2
    15+ min read
  • Detect Cycle in a Directed Graph using BFS
    Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false. For example, the following graph contains two cycles 0->1->2->3->0 and 2->4->2, so your function must return
    11 min read
  • Print negative weight cycle in a Directed Graph
    Given a weighted directed graph consisting of V vertices and E edges. The task is to print the cyclic path whose sum of weight is negative. If there is no such path present then print "-1". Input: V = 5, E = 5, Below is the graph: Here, for the given negative cycle o/p (1->2->3->4->1) ;
    14 min read
  • CSES Solutions - Acyclic Graph Edges
    Given an undirected graph, the task is to choose a direction for each edge so that the resulting directed graph is acyclic. You can print any valid solution. Example:Input: n = 3, m = 3, edge = {{1, 2}, {2, 3}, {3, 1}}Output: 1 22 31 3Explanation: Connecting the graph in this manner will result in d
    2 min read
  • Adjacency Matrix of Directed Graph
    Adjacency Matrix of a Directed Graph is a square matrix that represents the graph in a matrix form. In a directed graph, the edges have a direction associated with them, meaning the adjacency matrix will not necessarily be symmetric. In a directed graph, the edges have a direction associated with th
    6 min read
  • Convert Directed Graph into a Tree
    Given an array arr[] of size N. There is an edge from i to arr[i]. The task is to convert this directed graph into tree by changing some of the edges. If for some i, arr[i] = i then i represents the root of the tree. In case of multiple answers print any of them.Examples: Input: arr[] = {6, 6, 0, 1,
    9 min read
  • Clone a Directed Acyclic Graph
    A directed acyclic graph (DAG) is a graph which doesn't contain a cycle and has directed edges. We are given a DAG, we need to clone it, i.e., create another graph that has copy of its vertices and edges connecting them. Examples: Input : 0 - - - > 1 - - - -> 4 | / \ ^ | / \ | | / \ | | / \ |
    12 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences