Problem · Graph
Drawing Edge
Learn this problemProblem statement
Given n labeled nodes, count the distinct simple undirected graphs that can be drawn on them.
- For every unordered pair of distinct nodes, an edge may be present or absent.
- A node cannot have an edge to itself.
- The graph does not have to be connected.
Two graphs are distinct if at least one unordered pair has a different edge state. Return the number of distinct graphs modulo 10^9 + 7.
Function
drawingEdge(n: int) → intExamples
Example 1
n = 3return = 8There are three possible undirected edges. Each one can independently be present or absent, so there are 2^3 = 8 distinct graphs.
Example 2
n = 4return = 64Four nodes have six unordered pairs, so the number of graphs is 2^6 = 64.
Constraints
1 <= n <= 10^9