diff --git a/tech/BFS.wiki b/tech/BFS.wiki index d208b96..b3c8458 100644 --- a/tech/BFS.wiki +++ b/tech/BFS.wiki @@ -1 +1,20 @@ = Breadth First Search = + +Breadth First Search is an algorithm for searching a tree/graph for a node that +has a certain property. It starts at some chosen/implied root node, and +traverses the entire tree/graph. Therefore, BFS is often performed in O(n) +time. + +== Algorithm == + +=== Tree === + +The algorithm first starts by creating a Queue, Q, and a pointer to the current +node, curr. Starting at the root of the tree, all child nodes of the current +node are placed onto Q, then curr is changed to the first element of Q, which +is dequeued. This will traverse the tree from left to right, layer by layer. If +desired, a condition can be added for the desired node. + +This method of traversal *does not* take advantage of the structure of a tree, +and therefore does not have any of the lookup advantages of a [[binary_tree]]. +