Python Data Structures:  Trees

Python Data Structures: Trees

1h 16mIntermediate2021-02-25

Authors

Ryan Mitchell

Ryan Mitchell

Senior Software Engineer at GLG

Course details

What are trees, in Python, and how do they fit in with other data structures such as linked lists and graphs? In this course, instructor Ryan Mitchell discusses binary search trees (BSTs) and what you can do with them in a real-world context. Ryan shows you how to build a basic tree with just a few lines of Python. She steps through how to search and traverse a tree, as well as how to print a tree to a terminal. Ryan explains how to add nodes to your tree, delete them, and detect unbalanced trees. When you find an unbalanced tree, it’s important to rebalance it. Ryan walks you through rebalancing four types of unbalanced trees. She concludes with a challenge that features smarter automated rebalancing.

Skills covered

Data EngineeringPythonProgramming LanguagesData ScienceOpen SourceSoftware DevelopmentOne-Off

Concepts

Introduction

  • Getting started with trees
  • What you should know
  • BSTs and other trees

Navigating Trees

  • Building a basic tree
  • Searching a tree
  • Traversing a tree
  • Getting the maximum height of a tree
  • Getting all nodes at a particular depth
  • Challenge Printing a tree
  • Solution Printing a tree

Modifying Trees

  • Adding nodes
  • Deleting nodes Theory
  • Deleting nodes Code
  • Detecting unbalanced trees
  • Challenge Adding a balance indicator to the printed tree
  • Solution Adding a balance indicator to the printed tree

Rebalancing Trees

  • Introduction to rotations
  • Rotating trees in Python
  • Fixing a tree with multiple points of imbalance
  • Challenge Smarter automated rebalancing
  • Solution Smarter automated rebalancing

Conclusion

  • Next steps with data structures
40,000 Toman