dfs 3

[Data Structures] Graph Search (DFS and BFS)

The two most common ways to search a graph are depth-first search and breadth-first search. In depth-first search (DFS), we start at the root (or another arbitrarily selected node) and explore each branch completely before moving on to the next branch. That is, we go deep first (hence the name depth-first search) before we go wide. In breadth-first search (BFS), we start at the root (or another ..

[Data Structures] Binary Tree Traversals with Implementations

In Order: visit the left branch, then the current node, and finally visit the right branch. When performed on a binary search tree, it visits the nodes in ascending order (hence the name "in-order") void inOrderTraversal(Node node) { if (node != null){ inOrderTraversal(node.left); visit(node); inOrderTraversal(node.right); } } Pre Order: visits the current node before its child nodes (hence the ..