The number of connected components in an undirected graph

I turn to some graph algorithms ( this is not homework, I just comb the algorithms and data structures ), and I have a question. Suppose I have the following undirected graph:

var graph = {
    9: [19, 26],
    13: [19, 5],
    17: [],
    26: [11, 18],
    18: [9],
    19: [],
    23: [24],
    24: [],
    11: [],
    18: []
};

The chart basically looks like this:

enter image description here

How many connected components are in this graph? From just looking at the graph, there seem to be 3 components. But if I really implement the algorithm (iterating over each vertex and executing bfs using this vertex as a starting point if that vertex is not found. In addition, bfs will mark any vertex found as detected).

9, : [19, 26, 11, 18]. 13 , 19. 19 13 . .

? 4 , , ?

+5
2

,

(1) , .. ab, b adjlist[a]

(2) , .

(2) , (1). adj, . adj, , .

+4

, "", . (a, b) {a: [b], b: [a]}

+3

All Articles