reset password
Author Message
G190852562
Posts: 162
Posted 21:36 Dec 07, 2014 |

My questions/comments are bolded:

What are connected components?

6. Following is the algorithm to find the connected components of a graph G.

for i = 1 to n

if i is not yet explored

BFS(G, i)   -- run the BFS search algorithm on node i of graph G

The runtime for this algorithm is

 O(n^2) because we run the BFS algorithm, which is O(n), once for each node of the graph
 O(n) because we run the BFS algorithm, which is O(n), once for each node that wasn't touched by a previous BFS run
 O(n^2) because we run the BFS algorithm, which is O(n^2), once for each node that wasn't touched by a previous BFS run
 O(n) because we run the BFS algorithm, which is O(1), once for each node of the graph
 
 I got this exercise wrong. But I assume that it is either the first or third option due to the connected component's algorithm. The BFS has a while loop which is n and an inner for loop which is another n, yielding n^2. My guess leans more towards option 3.

Last edited by G190852562 at 21:38 Dec 07, 2014.
rabbott
Posts: 1649
Posted 21:59 Dec 07, 2014 |

The answer is 

O(n) because we run the BFS algorithm, which is O(n), once for each node that wasn't touched by a previous BFS run

This algorithm simply touches each node once. Hence it's O(n). The only reason the last answer is wrong is that it claims that BFS is O(1).

Last edited by rabbott at 22:00 Dec 07, 2014.
G190852562
Posts: 162
Posted 22:06 Dec 07, 2014 |
rabbott wrote:

The answer is 

O(n) because we run the BFS algorithm, which is O(n), once for each node that wasn't touched by a previous BFS run

This algorithm simply touches each node once. Hence it's O(n). The only reason the last answer is wrong is that it claims that BFS is O(1).

I selected the last answer on my quiz. It definitely threw off my reasoning for another attempt to answer this question.

rabbott
Posts: 1649
Posted 22:33 Dec 07, 2014 |

Actually, the last answer is wrong also for another reason as well. It claims that BFS is run for each node. It touches each node, but it's not run separately for each node. 

Last edited by rabbott at 23:19 Dec 07, 2014.
G190852562
Posts: 162
Posted 23:00 Dec 07, 2014 |
rabbott wrote:

Actually, the last answer is wrong also because it claims that BFS is run for each node. It touches each node, but it's not run separately for each node. 

Makes sense, thanks.

G190852562
Posts: 162
Posted 00:04 Dec 08, 2014 |

So what are connected components? All I know is that they're like equivalence classes.

rabbott
Posts: 1649
Posted 00:19 Dec 08, 2014 |
See https://en.wikipedia.org/wiki/Connected_component_%28graph_theory%29
Last edited by rabbott at 00:19 Dec 08, 2014.