graphs.basic_graphs

Attributes

graph_choice

Functions

_input(message)

adjm()

Reading an Adjacency matrix

bfs(g, s)

dfs(g, s)

dijk(g, s)

edglist()

Get the edges and number of edges from the user

find_isolated_nodes(graph)

Find the isolated node in the graph

floy(a_and_n)

initialize_unweighted_directed_graph(→ dict[int, ...)

initialize_unweighted_undirected_graph(→ dict[int, ...)

initialize_weighted_undirected_graph(→ dict[int, ...)

krusk(e_and_n)

Sort edges on the basis of distance

prim(g, s)

topo(g[, ind, q])

Module Contents

graphs.basic_graphs._input(message)
graphs.basic_graphs.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 = “4n0 1 0 1n1 0 1 0n0 1 0 1n1 0 1 0n” >>> 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

graphs.basic_graphs.bfs(g, s)
graphs.basic_graphs.dfs(g, s)
graphs.basic_graphs.dijk(g, s)
graphs.basic_graphs.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 3n1 2n2 3n3 4n” >>> 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

graphs.basic_graphs.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)
[]
graphs.basic_graphs.floy(a_and_n)
graphs.basic_graphs.initialize_unweighted_directed_graph(node_count: int, edge_count: int) dict[int, list[int]]
graphs.basic_graphs.initialize_unweighted_undirected_graph(node_count: int, edge_count: int) dict[int, list[int]]
graphs.basic_graphs.initialize_weighted_undirected_graph(node_count: int, edge_count: int) dict[int, list[tuple[int, int]]]
graphs.basic_graphs.krusk(e_and_n)

Sort edges on the basis of distance

graphs.basic_graphs.prim(g, s)
graphs.basic_graphs.topo(g, ind=None, q=None)
graphs.basic_graphs.graph_choice