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

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

CSCI-255 Advanced Data Structures Lecture 19

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

View Full Document
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?
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

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

View Full Document
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
DO 6.6 (c) (IN CLASS)

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

View Full Document
Depth-First Traversal

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

View Full Document

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

View Full Document
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
Ask a homework question - tutors are online