473,809 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3782


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.programmin g. Around here
we limit discussion the the standardized portable C language.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.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
1140
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
931
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, in all of the editors I have used, some support SCC interfaces, but do not show the file status. The current alternative is to load Visual Studio (or the TFS client which is simply a subset of VS), simply to manage checkins. Using command...
4
32087
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 hopefully answer, the following questions: • what is a graph? • how can a graph be represented as an ADT? • how can we search/walk through a graph using the BFS algorithm?
2
2824
by: DR | last post by:
how to search tfs by name of file or contents in file?
1
1316
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: TF220059: An error occurred while the Setup program was querying the installation settings for Team Foundation Server. For more information about this error, see the installation logs. For more information about the installation logs, see...
0
879
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 on the TFS box: http://localhost:8080/Services/v1.0/ServerStatus.asmx
0
770
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. What would be microsoft recommended approach for this type of activity. Thank you
1
3168
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> #include <boost/graph/depth_first_search.hpp> #include <fstream> #include <utility> #include <boost/graph/breadth_first_search.hpp> #include <algorithm>
2
3269
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 using BFS or IDDFS that "backtrack" after reaching all the leaves of the graph. Is there a better way to compute this algorithm?
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.