Errata: Data Structures and Algorithms Book!

Hi @anlexN - you are right. It required me to sleep and wake up today and see it with a fresher perspective :stuck_out_tongue:

In what I had originally, instead of removing references to the deleted node, I’m removing self-references (which don’t exist anyway). It should be as you described earlier:

removeNode(nodeToRemove) {
  if (this.nodes.has(nodeToRemove)) {
    // Remove the node and its edges from the graph
    this.nodes.delete(nodeToRemove);

    // Remove any incident edges in other nodes
    for (const [node, adjacentNodes] of this.nodes) {
      adjacentNodes.delete(nodeToRemove); // Now properly removing nodeToRemove
    }
  }
}

Thanks for flagging this. I’ll update the errata to call this out.