Data Structures & AlgorithmsHardInfosys · Graphs
An undirected graph on vertices 0 to 9 has the edges (0,1), (1,2), (2,0), (3,4), (5,6), (6,7), (7,5) and a self-loop (8,8). How many connected components does it have?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: A. 5
The components are {0,1,2}, {3,4}, {5,6,7}, and the single vertices {8} and {9}.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- In a binary tree every node has 0 or 2 children, except 7 nodes that have exactly one child, and there are 12 nodes with two children. How…
- A depth-first search runs on a directed graph with edges A->B, A->C, B->D, C->E, D->E, D->B, E->F, F->C, G->A, G->F, starting from A and…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65, 85 are inserted into an empty BST in this order. What is the lowest common ancestor of the…
- The words car, card, care, cat, dog, dot, do are inserted into an initially empty trie. How many nodes does the trie contain, not counting…
- A Fenwick (binary indexed) tree over indices 1 to 16 is used. Updating position 5 touches the nodes 5, 6, 8, 16 (add the lowest set bit…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 25 are inserted into an empty BST in this order. The node 30 is then deleted, being replaced by…