reading-notes

Read: Implementation Graphs Summary :

Directed vs Undirected
Complete vs Connected vs Disconnected
Acyclic vs Cyclic

Graph Representation

Weighted Graphs

Traversals

  1. Breadth First
    • Breadth first traversal is when you visit all the nodes that are closest to the root as possible. From there you traverse outwards, level by level, until you have visited all the vertices/nodes.
    • Here is what the algorithm breadth first traversal looks like:
      • Enqueue the declared start node into the Queue.
      • Create a loop that will run while the node still has nodes present.
      • Dequeue the first node from the queue
      • if the Dequeue‘d node has unvisited child nodes, add the unvisited children to visited set and insert them into the queue.
  2. Depth First
    • The algorithm for a depth first traversal is as follows:
      • Push the root node into the stack
      • Start a while loop while the stack is not empty
      • Peek at the top node in the stack
      • If the top node has unvisited children, mark the top node as visited, and then Push any unvisited children back into the stack.
      • If the top node does not have any unvisited children, Pop that node off the stack
      • repeat until the stack is empty.
Real World Uses of Graphs