Connected components in a graph can be found using which graph traversal…

2025

Connected components in a graph can be found using which graph traversal algorithm?

  1. A.

    DFS

  2. B.

    BFS

  3. C.

    Both DFS and BFS

  4. D.

    Neither DFS nor BFS

Attempted by 259 students.

Show answer & explanation

Correct answer: C

Connected components in a graph can be found using both DFS (Depth-First Search) and BFS (Breadth-First Search).

DFS explores as far as possible along each branch before backtracking. Starting from any node, it visits all nodes reachable from that node, which defines a connected component.

BFS explores all neighbors at the current depth before moving to the next level. It also visits all nodes reachable from a starting node, thus identifying connected components.

Therefore, both DFS and BFS are effective for finding connected components in a graph.

हिन्दी उत्तर:

ग्राफ में कनेक्टेड कंपोनेंट्स डीएफएस (Depth-First Search) और बीएफएस (Breadth-First Search) दोनों की सहायता से खोजे जा सकते हैं।

डीएफएस प्रत्येक शाखा के अंत तक जाता है और फिर वापस जाता है। किसी भी नोड से शुरू करके, यह उस नोड से पहुँचे जा सकने वाले सभी नोड्स को देखता है, जो एक कनेक्टेड कंपोनेंट को परिभाषित करता है।

बीएफएस वर्तमान गहराई पर सभी पड़ोसियों को तलाशता है और फिर अगले स्तर पर जाता है। यह भी एक शुरुआती नोड से पहुँचे जा सकने वाले सभी नोड्स को देखता है, जिससे कनेक्टेड कंपोनेंट्स की पहचान होती है।

इसलिए, डीएफएस और बीएफएस दोनों ग्राफ में कनेक्टेड कंपोनेंट्स को खोजने के लिए प्रभावी हैं।

Explore the full course: Bpsc