Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:22:27+00:00 2026-06-18T07:22:27+00:00

It has suddenly occured into my mind. Why do we use only 2 colors

  • 0

It has suddenly occured into my mind.

Why do we use only 2 colors in BFS graphs traveral

and 3 are needed for DFS ?

for instance: from wikipedia:

BFS:

procedure BFS(G,v):
2      create a queue Q
3      enqueue v onto Q
4      mark v
5      while Q is not empty:
6          t ← Q.dequeue()
7          if t is what we are looking for:
8              return t
9          for all edges e in G.adjacentEdges(t) do
12             u ← G.adjacentVertex(t,e)
13             if u is not marked:
14                  **mark u**
15                  enqueue u onto Q
16     return none

DFS:

  procedure DFS(G,v):
2      label v **as explored**
3      for all edges e in G.adjacentEdges(v) do
4          if edge e is unexplored then
5              w ← G.adjacentVertex(v,e)
6              if vertex w is unexplored then
7                  label e as a **discovery edge**
8                  recursively call DFS(G,w)
9              else
10                 label e as a **back edge**

why are 2 colors not enough for DFS?
why are 3 colors reduant for BFS?

here is another BFS (this time 3 colors):

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:22:28+00:00Added an answer on June 18, 2026 at 7:22 am

    There are a different number of colors in each of the two algorithms because they are used to represent fundamentally different types of information.

    In both BFS and DFS, nodes need to be marked as either unexplored nodes or explored nodes. Two colors are needed at a minimum to represent this information.

    In the DFS implementation you have listed above, the implementation also uses colors to classify edges as either “discovery edges” (edges that form the depth-first search tree produced by the algorithm) or “back edges” (edges that move from a deeper part of the DFS tree to a shallower part of the DFS tree). These colors are used to color edges, not nodes. As a result, three colors are necessary for edges – unexplored edges, “discovery” edges, and back edges.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It has suddenly happened that I need to output a couple of strings in
The Microsoft unit testing framework has suddenly gone on strike. When I try to
The 'Updates' button on the publish tab of my project has suddenly disabled. I
Hello suddenly VS2010 has started formatting my if statements in a way that I
Has anyone ever run into this issue before? Sometimes the string displays, sometimes half
EDIT: THIS QUESTION IS INVALID SINCE THE SERVER I'M USING HAS SUDDENLY EXPIRED. PLEASE
I've been building a static website and the client has suddenly stated that they
The Install New Software option used for adding plug-ins has suddenly started to show
My phone, running Windows Mobile 6, has suddenly decided to drop an hour every
This was working but has suddenly stopped for some reason. I can't see what's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.