code: def maximal_matching(G):
      r"""Find a maximal matching in the graph.
  
      A matching is a subset of edges in which no node occurs more than once.
      A maximal matching cannot add more edges and still be a matching.
  
      Parameters
      ----------
      G : NetworkX graph
          Undirected graph
  
      Returns
      -------
      matching : set
          A maximal matching of the graph.
  
      Examples
      --------
      >>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)])
      >>> sorted(nx.maximal_matching(G))
      [(1, 2), (3, 5)]
  
      Notes
      -----
      The algorithm greedily selects a maximal matching M of the graph G
      (i.e. no superset of M exists). It runs in $O(|E|)$ time.
      """
      matching = set()
      nodes = set()
      for edge in G.edges():
          # If the edge isn't covered, add it to the matching
          # then remove neighborhood of u and v from consideration.
          u, v = edge
          if u not in nodes and v not in nodes and u != v:
              matching.add(edge)
              nodes.update(edge)
      return matching
  
file_path: networkx/networkx/algorithms/matching.py
imports: from collections import Counter
  from itertools import combinations, repeat
  import networkx
  from networkx.utils import not_implemented_for
label_desc: Use image node_id 1 for calling a global function with example usage: maximal_matching(G) and returns: matching