Log in from a computer to take this course

You'll need to log in from a computer to start Introduction to Non-linear Data Structures in Swift. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

Imagine you’re a superhero escaping a villain’s lair. As you move from perilous room to perilous room, the doors close immediately behind you, barring any return.

For this dramatic example, we need a directed graph, where edges restrict the direction of movement between vertices.

We can move from spikes to lasers, but not from lasers to spikes. This differs from earlier examples when every edge was bi-directional.

Note the path spikes to lasers to piranhas to spikes. This path is a cycle, because it ends on the vertex where it began: spikes.


Consider a city with one-way streets, how would you model this with a directed graph?

What other cycles exist in this graph?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?