Algorithms and OOD (CSC 207 2014S) : Outlines

# Outline 41: Tree Traversal

Held: Monday, 14 April 2014

Summary

We consider orders in which one might visit the nodes in a tree and the algorithms one uses to achieve those orders.

Related Pages

Overview

• Orders for traversing the tree.
• Implementating traversal algorithms.

### Upcoming Work

• Tomorrow will be a "design data structure day", with no lab.
• Today's writeup: Exercise 5b.
• Part 1 of the project is due Wednesday night.
• I'll take questions after the introductory stuff.

• Congratulations to our new SEPC members.
• Remember that there are ACM Chapter elections tonight at 8 pm.
• Remember that there's a CS study break tonight at 8 pm.
• I did my best to get grades to you yesterday. Let me know about questions and comments.
• I'm returning the makeups. I would have liked more depth on part 1.

### Extra Credit

• CS extra today: Walker and Liberto on bluetooth.
• Convo Wednesday: Philip Deloria, Professor of History and Native American Studies, University of Michigan.
• CS extra Thursday: Charlie Eddy on Kinect.
• CS table Friday: Big Data (Stone leads).
• Get and wear one of the 1 in 4 shirts.
• Iowater project April 19 - Tag drains. Mail iowater@grinnell.edu for details.
• http://www.strikingly.com/pioneerweekend

## Tree Traversal

• Once we've built a tree, we may want to systematically visit the nodes in the tree. We call that tree traversal.
• There are a number of decisions to make as we design a traversal algorithms.
• If we assume that the children/subtrees are ordered, do we visit them left-to-right or right-to-left? (Yes, there are reasons to do both.)
• Do we delve deeply into a subtree before we go across the tree (depth-first) or do we go across each level of the tree (breadth-first)?
• If we are doing a depth-first traversal, do we visit a node before (preorder), between (inorder), or after (postorder) its children?
• Why after? If we are computing a value based on the children, we need to have the children finished.
• If we are doing a breadth-first traversal, do we go top-down or bottom-up?
• And how do we implement all of these, anyway?
• That's the subject of today's lab.

## Lab

Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit `http://creativecommons.org/licenses/by/3.0/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.