Learn Trees

Learn the tree data structure using Python and create an adventure game!

Start[missing "en.views.course_landing_page.complex-data-structures.course_illustration" translation]
Chevron Left Icon
Trees: Conceptual
Lesson 1 of 2
Chevron Right Icon
  1. 1

    Trees are an essential data structure for storing hierarchical data with a directed flow. Similar to linked lists and graphs, trees are composed of nodes which hold data. The diagram represents ...

  2. 2

    Trees grow downwards in computer science, and a root node is at the very top. The root of this tree is [...] . [...] references to two other nodes: [...] and [...] . [...] and [...] ar...

  3. 3

    Trees come in various shapes and sizes depending on the dataset modeled. Some are wide, with parent nodes referencing many child nodes. Some are deep, with many parent-child relationships. Tre...

  4. 4

    Constraints are placed on the data or node arrangement of a tree to solve difficult problems like efficient search. A binary tree is a type of tree where each parent can have **no more than tw...

  5. 5

    Trees are useful for modeling data that has a hierarchical relationship which moves in the direction from parent to child. No child node will have more than one parent. To recap some terms: * [...

  1. 1

    Before we start building (planting?) our trees, let's do a quick inventory of what we'll need in our Python implementation. We're going to make the class [...] . [...] : - have a value - have a ...

  2. 2

    Let's start by defining our [...] class. We'll begin with having our node store a value, and additional functionality can be layered on in the following exercises.

  3. 3

    We have a working [...] class, but there's no time to enjoy a refreshing glass of lemonade. Trees are all about data hierarchy, and we need a parent-child relationship to make that work. To revi...

  4. 4

    Let's explore how to remove nodes from a tree. Remember, child nodes are held in a list within the parent node. To remove a child, we need to remove that node from the list. We want the following ...

  5. 5

    Trees are an abstract idea that we're making concrete in Python. When implementing these abstract data structures, it's important to leverage the features of your language. Let's refactor [...] ...

  6. 6

    Our implementation has covered adding and removing nodes. Let's expand the functionality and add the ability to move through connected nodes. Tree traversal is a standard operation for finding no...

  7. 7

    Our implementation of tree traversal has a slight hiccup. Trees grow many levels deep, but we've only accounted for one parent-child relationship. How is this a problem? [...] "VP of Bananas" ...

  8. 8

    Congratulations, you have implemented a tree in Python. For review, in our implementation: - Trees are a Python class called [...] . - A [...] has two properties, [...] and [...] . - Nodes h...

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Learn Trees

Start[missing "en.views.course_landing_page.complex-data-structures.course_illustration" translation]