data_structures.binary_tree.lowest_common_ancestor ================================================== .. py:module:: data_structures.binary_tree.lowest_common_ancestor Functions --------- .. autoapisummary:: data_structures.binary_tree.lowest_common_ancestor.breadth_first_search data_structures.binary_tree.lowest_common_ancestor.create_sparse data_structures.binary_tree.lowest_common_ancestor.lowest_common_ancestor data_structures.binary_tree.lowest_common_ancestor.main data_structures.binary_tree.lowest_common_ancestor.swap Module Contents --------------- .. py:function:: breadth_first_search(level: list[int], parent: list[list[int]], max_node: int, graph: dict[int, list[int]], root: int = 1) -> tuple[list[int], list[list[int]]] sets every nodes direct parent parent of root node is set to 0 calculates depth of each node from root node .. py:function:: create_sparse(max_node: int, parent: list[list[int]]) -> list[list[int]] creating sparse table which saves each nodes 2^i-th parent .. py:function:: lowest_common_ancestor(u: int, v: int, level: list[int], parent: list[list[int]]) -> int .. py:function:: main() -> None .. py:function:: swap(a: int, b: int) -> tuple[int, int] Return a tuple (b, a) when given two integers a and b >>> swap(2,3) (3, 2) >>> swap(3,4) (4, 3) >>> swap(67, 12) (12, 67)