graphs.basic_graphs =================== .. py:module:: graphs.basic_graphs Attributes ---------- .. autoapisummary:: graphs.basic_graphs.graph_choice Functions --------- .. autoapisummary:: graphs.basic_graphs._input graphs.basic_graphs.adjm graphs.basic_graphs.bfs graphs.basic_graphs.dfs graphs.basic_graphs.dijk graphs.basic_graphs.edglist graphs.basic_graphs.find_isolated_nodes graphs.basic_graphs.floy graphs.basic_graphs.initialize_unweighted_directed_graph graphs.basic_graphs.initialize_unweighted_undirected_graph graphs.basic_graphs.initialize_weighted_undirected_graph graphs.basic_graphs.krusk graphs.basic_graphs.prim graphs.basic_graphs.topo Module Contents --------------- .. py:function:: _input(message) .. py:function:: adjm() Reading an Adjacency matrix Parameters: None Returns: tuple: A tuple containing a list of edges and number of edges Example: >>> # Simulate user input for 3 nodes >>> input_data = "4\n0 1 0 1\n1 0 1 0\n0 1 0 1\n1 0 1 0\n" >>> import sys,io >>> original_input = sys.stdin >>> sys.stdin = io.StringIO(input_data) # Redirect stdin for testing >>> adjm() ([(0, 1, 0, 1), (1, 0, 1, 0), (0, 1, 0, 1), (1, 0, 1, 0)], 4) >>> sys.stdin = original_input # Restore original stdin .. py:function:: bfs(g, s) >>> bfs({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [], 5: [8], 6: [], 7: [], 8: []}, 1) 1 2 3 4 5 6 7 8 .. py:function:: dfs(g, s) >>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1) 1 2 4 5 3 .. py:function:: dijk(g, s) dijk({1: [(2, 7), (3, 9), (6, 14)], 2: [(1, 7), (3, 10), (4, 15)], 3: [(1, 9), (2, 10), (4, 11), (6, 2)], 4: [(2, 15), (3, 11), (5, 6)], 5: [(4, 6), (6, 9)], 6: [(1, 14), (3, 2), (5, 9)]}, 1) 7 9 11 20 20 .. py:function:: edglist() Get the edges and number of edges from the user Parameters: None Returns: tuple: A tuple containing a list of edges and number of edges Example: >>> # Simulate user input for 3 edges and 4 vertices: (1, 2), (2, 3), (3, 4) >>> input_data = "4 3\n1 2\n2 3\n3 4\n" >>> import sys,io >>> original_input = sys.stdin >>> sys.stdin = io.StringIO(input_data) # Redirect stdin for testing >>> edglist() ([(1, 2), (2, 3), (3, 4)], 4) >>> sys.stdin = original_input # Restore original stdin .. py:function:: find_isolated_nodes(graph) Find the isolated node in the graph Parameters: graph (dict): A dictionary representing a graph. Returns: list: A list of isolated nodes. Examples: >>> graph1 = {1: [2, 3], 2: [1, 3], 3: [1, 2], 4: []} >>> find_isolated_nodes(graph1) [4] >>> graph2 = {'A': ['B', 'C'], 'B': ['A'], 'C': ['A'], 'D': []} >>> find_isolated_nodes(graph2) ['D'] >>> graph3 = {'X': [], 'Y': [], 'Z': []} >>> find_isolated_nodes(graph3) ['X', 'Y', 'Z'] >>> graph4 = {1: [2, 3], 2: [1, 3], 3: [1, 2]} >>> find_isolated_nodes(graph4) [] >>> graph5 = {} >>> find_isolated_nodes(graph5) [] .. py:function:: floy(a_and_n) .. py:function:: initialize_unweighted_directed_graph(node_count: int, edge_count: int) -> dict[int, list[int]] .. py:function:: initialize_unweighted_undirected_graph(node_count: int, edge_count: int) -> dict[int, list[int]] .. py:function:: initialize_weighted_undirected_graph(node_count: int, edge_count: int) -> dict[int, list[tuple[int, int]]] .. py:function:: krusk(e_and_n) Sort edges on the basis of distance .. py:function:: prim(g, s) .. py:function:: topo(g, ind=None, q=None) .. py:data:: graph_choice