This is the best image I could find to help visualize what is happening.
If you keep this in mind then look at the next image you should at least start to be able to visualise what is going on.
Here is a good read.
This is taken directly from Ethereum, if you read it you can almost visualise what it describes.
Essentially, it starts off a graph as a single node, sha3(seed), and
from there starts sequentially adding on other nodes based on random
previous nodes. When a new node is created, a modular power of the
seed is computed to randomly select some indices less than i (using x
% i above), and the values of the nodes at those indices are used in a
calculation to generate a new a value for x, which is then fed into a
small proof of work function (based on XOR) to ultimately generate the
value of the graph at index i. The rationale behind this particular
design is to force sequential access of the DAG; the next value of the
DAG that will be accessed cannot be determined until the current value
is known. Finally, modular exponentiation is used to further hash the
This is the actual code that builds the DAG Graph in python
def produce_dag(params, seed, length):
P = params["P"]
picker = init = pow(sha3(seed), params["w"], P)
o = [init]
for i in range(1, length):
x = picker = (picker * init) % P
for _ in range(params["k"]):
x ^= o[x % i]
o.append(pow(x, params["w"], P))