473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Graphs (BFS and TFS)

I am trying to write a program that uses graphs and I have this
algorithm for the Depth First Search.

//Input: Graph G=(V, E)
//Output Graph G with its vertices marked with consecutive integers in
//the order they've been first encountered by the DFS traversal mark
//each vertex in V with 0 as a mark of being "unvisited"

count<--0

for each vertex v in V do
if v is marked with 0 dfs(v)
algorithm for dfs
//visits recursively all the unvisited vertices connected to vertex v
and then assigns them the numers in the order they are encountered via
global variable count

count<-- count +1; mark v with count

for each vertex w in V adjacent to v do
if w is marked with 0
dfs(w)

My question is the first algorithm DFS(G), takes in a graph , and then
says a Graph is G(V,E)... What type of data structure is a graph, that u
can pass it in as a Graph and then it has a V(vertice) and E ( edge). I
also have the algorithm for the BFS but it takes in a Graph too. I do
not know exactly what a Graph data structure is so therefore i can't use
the algorithm. Any help is greatly appreciated.
Nov 14 '05 #1
3 3755


Scott Dabot wrote:
I am trying to write a program that uses graphs and I have this
algorithm for the Depth First Search.

//Input: Graph G=(V, E)
//Output Graph G with its vertices marked with consecutive integers in
//the order they've been first encountered by the DFS traversal mark
//each vertex in V with 0 as a mark of being "unvisited"

count<--0

for each vertex v in V do
if v is marked with 0 dfs(v)
algorithm for dfs
//visits recursively all the unvisited vertices connected to vertex v
and then assigns them the numers in the order they are encountered via
global variable count

count<-- count +1; mark v with count

for each vertex w in V adjacent to v do
if w is marked with 0
dfs(w)

My question is the first algorithm DFS(G), takes in a graph , and then
says a Graph is G(V,E)... What type of data structure is a graph, that u
can pass it in as a Graph and then it has a V(vertice) and E ( edge). I
also have the algorithm for the BFS but it takes in a Graph too. I do
not know exactly what a Graph data structure is so therefore i can't use
the algorithm. Any help is greatly appreciated.


Please note that algorithmical and related questions are mostly offtopic
round here, especially if you have not given us C code to comment on.
For general information, ask rather in *.program* newsgroups.

Your example looks like the definitions from a lecture, so probably
they tell you about graph representation, too. Maybe you can go from
there.
Depending on what you want to do with your graph and what you know
about your graph, there are several ways to represent it; just google
for these keywords
- Adjacency Matrix
- Incidence Matrix
- Edge Representation
In case of sparse matrices, you can just use the sparse matrix
representation or do everything equivalently by data structures
of your own, say linked lists for either the vertices or the edges
or both containing additional data as you need it.
For searching the vertices with dfs or bfs, I would just use the
adjacency matrices or related sparse structures, as they usually
are defined only in terms of vertices which makes applying the
abstract algorithm easier; in addition, for graphs with O(|V|^s),
s>1, edges you have smaller matrices most of the time.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2
Scott Dabot wrote:

I am trying to write a program that uses graphs and I have this
algorithm for the Depth First Search.

.... snip ...

You are in the wrong newsgroup. Try comp.programming. Around here
we limit discussion the the standardized portable C language.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #3
Scott Dabot wrote:
I am trying to write a program that uses graphs and I have this
algorithm for the Depth First Search.

//Input: Graph G=(V, E)
//Output Graph G with its vertices marked with consecutive integers in
//the order they've been first encountered by the DFS traversal mark
//each vertex in V with 0 as a mark of being "unvisited"

count<--0

for each vertex v in V do
if v is marked with 0 dfs(v)
algorithm for dfs
//visits recursively all the unvisited vertices connected to vertex v
and then assigns them the numers in the order they are encountered via
global variable count

count<-- count +1; mark v with count

for each vertex w in V adjacent to v do
if w is marked with 0
dfs(w)

My question is the first algorithm DFS(G), takes in a graph , and then
says a Graph is G(V,E)... What type of data structure is a graph, that u
can pass it in as a Graph and then it has a V(vertice) and E ( edge). I
also have the algorithm for the BFS but it takes in a Graph too. I do
not know exactly what a Graph data structure is so therefore i can't use
the algorithm. Any help is greatly appreciated.


A graph is a set of nodes and vertices. If you don't care about
performance, just write a linked list of nodes:

typedef struct _node{
void *data;
void *vertex_list;
void *next_node;
} node;

typedef struct _graph{
node* first;
node* last;
}

--
Thanks,
Elliott C. Bäck
--------------------------
www.elliottback.com
www.spreadIE.com
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Wright | last post by:
When we try to replicate our SQL Server that is running TFS (Windows 2005 Standard), the replication works fine, but we cannot connect with TFS any more. Any reason why? Any fixes? John
0
by: Matt | last post by:
Company has switched to MS Team Foundation Server from VSS. Need a programmers text editor that interfaces with TFS or SCC providers to visually provide checkin/out status on project files. So far,...
4
prometheuzz
by: prometheuzz | last post by:
Hello (Java) enthusiasts, In this article I’d like to tell you a little bit about graphs and how you can search a graph using the BFS (breadth first search) algorithm. I’ll address, and...
2
by: DR | last post by:
how to search tfs by name of file or contents in file?
1
by: Steve | last post by:
Hi guys, I'm trying to upgrade TFS 2005 to TFS 2008 on a test server in preparation for upgrading our live box. However, when I run the install of 2008, I get the following error message: ...
0
by: Steve | last post by:
Hi guys, I've just done an upgrade on TFS 2005 to 2008. The upgrade didn't mention any problems, but I've since discovered one! The TFS Server is now not responding. For instance, if I go here...
0
by: =?Utf-8?B?VmFk?= | last post by:
Hello, I have TFS 2005 installed on server A We resently purchased TFS 2008 and installed it on Server B We need to migrate / move all data from TFS 2005 on server A to TFS 2008 on server B. ...
1
by: rboorgapally | last post by:
Hi everyone, I am trying to run BFS on a graph that is created with input from a file. I am facing problems with the output though the code is compiling: #include <boost/graph/adjacency_list.hpp>...
2
by: orzeech | last post by:
He everyone! My question is quite simple: is there an algorithm that does exactly what's shown on this picture: http://upload.wikimedia.org/wikipedia/commons/6/6d/FloodAck.gif I thought about...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.