Skip to main content
deleted 28 characters in body
Source Link
Nathaniel
  • 17k
  • 2
  • 30
  • 55

You can use a boolean array of length $|V|$ to check whether a vertex $u$ has already been seen or not. Assuming $V = \{0, 1, …, n-1\}$, the algorithm could be re-written as:

Input: graph G as an adjacency lists array

Initialize C as an empty set
for u = 0 to n - 1 do
each edge e = for{u, v} in G[u]E do
        if neither u nor v is marked then
           Add {u, v}e to C
           mark u and v
return C

The complexity would indeed be proportionnal to $\sum\limits_{u\in V} (1+\deg u) = |V| + 2|E| = \mathcal{O}(|V| + |E|)$$\mathcal{O}(|V| + |E|)$.

You can use a boolean array of length $|V|$ to check whether a vertex $u$ has already been seen or not. Assuming $V = \{0, 1, …, n-1\}$, the algorithm could be re-written as:

Input: graph G as an adjacency lists array

Initialize C as an empty set
for u = 0 to n - 1 do
    for v in G[u] do
        if neither u nor v is marked then
           Add {u, v} to C
           mark u and v
return C

The complexity would be proportionnal to $\sum\limits_{u\in V} (1+\deg u) = |V| + 2|E| = \mathcal{O}(|V| + |E|)$.

You can use a boolean array of length $|V|$ to check whether a vertex $u$ has already been seen or not. Assuming $V = \{0, 1, …, n-1\}$, the algorithm could be re-written as:

Input: graph G as an adjacency lists array

Initialize C as an empty set
for each edge e = {u, v} in E do
    if neither u nor v is marked then
       Add e to C
       mark u and v
return C

The complexity would indeed be $\mathcal{O}(|V| + |E|)$.

Source Link
Nathaniel
  • 17k
  • 2
  • 30
  • 55

You can use a boolean array of length $|V|$ to check whether a vertex $u$ has already been seen or not. Assuming $V = \{0, 1, …, n-1\}$, the algorithm could be re-written as:

Input: graph G as an adjacency lists array

Initialize C as an empty set
for u = 0 to n - 1 do
    for v in G[u] do
        if neither u nor v is marked then
           Add {u, v} to C
           mark u and v
return C

The complexity would be proportionnal to $\sum\limits_{u\in V} (1+\deg u) = |V| + 2|E| = \mathcal{O}(|V| + |E|)$.