lecture19 - b Proceeds as far as possible to the left then...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI-255 Advanced Data Structures Lecture 19
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Inserting an Element into a BST (cont’d) Exercise: Write a recursive version of insert (DONE IN CLASS) Do 6.22(e) (DONE IN CLASS) Running Time?
Background image of page 2
Tree Traversal b Tree traversal is the process of visiting each node in the tree exactly one time s This definition does not specify the order in which the nodes are visited s For a tree with n nodes, how many different traversals there are? b n ! different traversals, but most of them are useless s Two main traversals: b Breadth-First b Depth-First
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Breadth-First Traversal b Visits each node starting from the lowest level and moving down level by level, visiting nodes on each level from left to right
Background image of page 4
DO 6.6 (c) (IN CLASS)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Depth-First Traversal
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: b Proceeds as far as possible to the left then backs up until the first crossroad, goes one step to the right, and again as far as possible to the left b This process is repeated until all nodes are visited b This definition does not specify exactly when nodes are visited: before proceeding down the tree or after backing up? s Preorder traversal s Inorder traversal s Postorder traversal Inorder Traversal b Left child, parent node, right child (DONE IN CLASS) Inorder Traversal (contd) Preorder Traversal b Parent node, left child, right child (DONE IN CLASS) Postorder Traversal b Left child, right child, parent node (DONE IN CLASS)...
View Full Document

This note was uploaded on 11/26/2009 for the course MATH AND C CSCI255 taught by Professor Dr.ikergondraluja during the Spring '09 term at St. Francis Xavier, Antigonish.

Page1 / 11

lecture19 - b Proceeds as far as possible to the left then...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online