graphs.basic_graphs¶
Attributes¶
Functions¶
| 
 | |
| 
 | Reading an Adjacency matrix | 
| 
 | |
| 
 | |
| 
 | dijk({1: [(2, 7), (3, 9), (6, 14)], | 
| 
 | Get the edges and number of edges from the user | 
| 
 | Find the isolated node in the graph | 
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | Sort edges on the basis of distance | 
| 
 | |
| 
 | 
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)¶
- >>> 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 
- graphs.basic_graphs.dfs(g, s)¶
- >>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1) 1 2 4 5 3 
- graphs.basic_graphs.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 
- 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¶