Upload
walter-hawkins
View
226
Download
3
Tags:
Embed Size (px)
Citation preview
Alyce BradyAlyce Brady
CS 470: Data StructuresCS 470: Data Structures
CS 510: Computer Algorithms CS 510: Computer Algorithms
Breadth-FirstBinary Tree
Traversal Algorithm
Pseudo-Code forBreadth-First Traversal
breadth-first-traversalbreadth-first-traversalput root node onto a queueput root node onto a queuewhile the queue is not emptywhile the queue is not empty
dequeue the next nodedequeue the next nodevisit the nodevisit the node e.g., print valuee.g., print value
enqueue the left child nodeenqueue the left child nodeenqueue the right child nodeenqueue the right child node
Time and Space Complexityfor Breadth-First Search Alg.
Time ComplexityTime Complexity– Consider each node twiceConsider each node twice O(n)O(n)
when put on queuewhen put on queue when taken from queuewhen taken from queue