• BFS and DFS

    BFS and DFS

    Breadth-First Search Breadth-First search is commonly used to find the shortest path from the root node to target node. Implementation Note that we used visited hash set to skip adding duplicate nodes, but there are some cases where one does not need the visited hash. Depth-First Search Depth-First search can be used to find the… Read more

  • Tree Traversal

    Tree Traversal

    Tree is a frequently used data structure that simulates a tree structure. Each node of the tree will have a root value and a list of subtrees of child nodes. There are 3 different ways to traverse all nodes in the tree. Pre-order Traversal (NLR) Visit the root node first. Then, visit the left subtree.… Read more