Hi, I need to do a depth first search tree for the following undirected graph:

1-2-3
|...|..|
4-5 6
|......|
7-8-9

(Sorry about the graph being so unclear, the dots are just to space the lines out). It says to start at A which I'm guessing is 1?

My first attempt at the order was 1-4-7-8-9-6-3-2-5 but I'm really not sure?

Recommended Answers

All 5 Replies

Hi, I need to do a depth first search tree for the following undirected graph:

1-2-3
| | |
4-5 6
|   |
7-8-9

(Sorry about the graph being so unclear, the dots are just to space the lines out). It says to start at A which I'm guessing is 1?

My first attempt at the order was 1-4-7-8-9-6-3-2-5 but I'm really not sure?

Use Code tags to keep spacing.

That's not a tree.

Did you mean:

1-2-3
|   |
4-5 6
|    
7-8-9

Or in tree form:

___1___
     |       | 
   __4__     2
  |     |    |
  7     5    3
  |          |
  8          6
  |
  9

If so, it's 1-4-7-8-9-5-2-3-6
Your tree would be:

___1___
     |       | 
   __4__     3
  |     |    |
  7     6    2
  |          |
  8          5
  |
  9

Hi, thanks for your reply. I meant

1-2-3
| | |
4-5 6
|   |
7-8-9

That is not a tree as far as I can tell. 5 & 9 cannot be the child of 2 nodes. Unless you can explain how it works and I'm missing something.

It says its an undirected graph?

your attempt is correct....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.