# Workflow delete node (Directed Graph) ## Algorithms ### delete edge (a > b) #### Draft #1 - check if (b) is connected to (0) without this edge - if connected delete edge and stop - else delete node (b) #### Final - cut the edge - check for disconnected nodes and delete them - no need for more scan as batch scan algorithm could detect all disconnected nodes once ### delete node (X) #### Draft #1 - check for all direct children of (X) not including self after removing all edges from (X > C0, ... X < Cn) - (this check could be optimized to single scan) - if child (Ci) is connected to (0) keep it - else delete node (Ci) - Note: Keep track of disconnected nodes from batch scan (Cached) - if node is not connected from previous scan no need t scan again #### Final - delete node from the model - check for disconnected nodes and delete them - no need for more scan as batch scan algorithm could detect all disconnected nodes once ### batch connection scan - clean (signal) property from all nodes - start from (0) send send signal to direct children using depth first and stop if node recieved a signal - each node resend the signal to all direct children - after scan stopped - check if any node didnot recieved signal , it's disconnected ### single node (X) connection scan - clean (signal) property from all nodes - start from (0) send send signal to direct children using depth first and stop if node recieved a signal or if node is (X) - each node resend the signal to all direct children unless we reached node (X) - if scan stopped without reaching node (X) then It's not connected ## Data structure ### nodes - A list of all nodes ### edges - We could store edges as a dictionary with key represent the start of the edge and value is a list of targets. - root node should have edge from hidden node (0). ### Example ```mermaid flowchart TB A --> B B --> C A --> C C --> D B --> E D --> E E --> |Approve| F E --> |Reject| F ``` #### Nodes ```json [ "A", "B", "C", "D", "E", "F" ] ``` #### Edges ```json { "0": ["A"], "A": ["B", "C"], "B": ["C", "E"], "C": ["D"], "D": ["E"], "E": ["F". "F"] } ```