mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 05:14:06 -06:00
31 lines
565 B
Markdown
31 lines
565 B
Markdown
---
|
|
title: "tree-traversal"
|
|
aliases: traversal
|
|
tags:
|
|
- cosc201
|
|
---
|
|
|
|
Visit each node in the tree once. So we need to visit n, all the nodes in L, and all the nodes in R. We can do this in four different ways
|
|
|
|
preorder
|
|
- visit n
|
|
- traverse L
|
|
- traverse R
|
|
|
|
Inorder.
|
|
- traverse L
|
|
- visit n
|
|
- traverse R
|
|
Creating an BST from an array using the add operation then doing an inorder traversal is effectively a [quicksort](notes/quicksort)
|
|
|
|
postorder
|
|
- traverse L
|
|
- traverse R
|
|
- visit n
|
|
|
|
level order
|
|
- vist the root
|
|
- visit the roots children
|
|
- visit their children
|
|
- etc
|