Tree Traversals - PowerPoint PPT Presentation

About This Presentation
Title:

Tree Traversals

Description:

Do you have any questions about assignments? ... You get a breadth-frist traversal. Here you go across each level. Minute Essay ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 6
Provided by: mark721
Category:
Tags: frist | traversals | tree

less

Transcript and Presenter's Notes

Title: Tree Traversals


1
Tree Traversals
  • 4-3-2002

2
Opening Discussion
  • What did we talk about last class?
  • Do you have any questions about assignments? I
    am changing assignment 5 so it only includes the
    first two objectives. The other two will be
    assignment 6 and you get off from making a
    SubStr3 class. I will be posting a new full
    description.

3
Traversals
  • The nominal topic for today is traversals so we
    will discuss that very briefly. After that we
    will just code.
  • Your book discusses traversals for iterators.
    This is quite different from the recursive
    traversals we have mentioned because they cant
    be recursive. Instead you have to implement a
    data structure to help remember the places you
    have been or need to go.

4
Stack or Queue?
  • If you use a stack to remember where you have
    been you get a traversal like the ones we have
    discussed. Whether it is preorder, inorder, or
    postorder depends only on exactly when you return
    that object from the iterator. These are called
    depth-first traversals.
  • If you use a queue you get a slightly different
    behavior. You get a breadth-frist traversal.
    Here you go across each level.

5
Minute Essay
  • Give a brief description of why using a stack vs.
    a queue produces such a drastically different
    traversal.
  • I think Im going to swap the next two lecture
    topics with the two after them so we cover binary
    trees earlier.
Write a Comment
User Comments (0)
About PowerShow.com