DFS, BFS using Vectors

bfs
dfs
graphs

#1

I want to implement DFS, BFS using vector of vectors. Can someone help me with that? I have never code using vector, so it is a bit tough for me i guess.


#2

Do not guess, if you never used vector before, do some tests, read some examples…

http://www.cplusplus.com/reference/vector/vector/


#3

void bfs(int s,vector adj[],bool vis[])
can someone help me ? how can i find the size of adj[] ?


#4

Refer Geeks for Geeks for graph+stl solutions. Here is the link for dfs using vectors http://www.geeksforgeeks.org/graph-implementation-using-stl-for-competitive-programming-set-1-dfs-of-unweighted-and-undirected/


#5

Refer to this link. Probably the best if you are a beginner in graphs c++.
Graph Theory Part - 1


#6

i have read it already. i am not able to write code for Dfs and bfs using it.


#7

If you can do it with arrays you can do it with vectors. If you can’t do it with arrays you need to learn dfs/bfs and solve some questions.


#8

ya… i think you are right. but thanks anyways…


#9

Try to solve this problem - http://www.codechef.com/problems/PETERSEN using BFS…

We can help you if you got stucked :wink:

Try to solve this problem - http://www.codechef.com/problems/FIRESC (DFS) also :wink:


#10

Well you have probably made a 2D vector and size of adj* (i.e no. of columns of a particular row) can be found simply using “adj*.size()” whereas the size of adj[] (i.e. no. of rows of 2D vector) has to be passed in the function!


#11

Dude, see the date.