GATE CSE
First time here? Checkout the FAQ!
x
+3 votes
178 views

a)(d,c)

b)(d,b)

c)(e,b)

d)(e,f)

asked in DS by Veteran (53.1k points)   | 178 views

2 Answers

+1 vote

Answer would be b) (d,b)

You can find meaning of cross edge (for BFS on undirected graph)  here. Usually cross edges are used in context of Depth First Search Forest.

Since edge (d,b) is present in the breadth first search tree, it can't be cross edge (according to the meaning in the given link).

Following is the breadth first tree:

answered by Loyal (3.3k points)  
reshown by
@pratyush..BFS undirected graph doess not have back and forward edges??

@Akriti: I know for a fact that BFS of an undirected graph does not have back and forward edges. I have checked it on few simple graphs, but don't have an elaborate proof. However one of the answers in the this  post may clear it little bit. If you still want a credible source then you can check CLRS 3rd ed. problem 22-1 (a). This problem asks reader to prove the same.

THANKS @PRATYUSH
bfs tree in ans given ll b undirected ?
Yes. But even if they are directed it doesn't matter. Trees have an implicit direction from ancestor towards descendants. Actually I tried to draw it undirected but since I used an online tool, which had only directed lines to draw, the tree is directed here.
+1 vote

algorithm to detect cross edge and tree edge : 

Algorithm BFS(Vertex s
// iterative algorithm

initialize container L0, level, to contain vertex s 
i = 0 
while Li is not empty do {
create container Li+1 to initially be empty      // next level 
for each vertex v in Li do      // vertices in previous level
for each edge e incident on v do
if edge e is unexplored then
let w be the other end of e 
if vertex w is unexplored then 
    label e a discovery edge and  insert w into Li+1 
else 
    label e as a cross edge
i = i + 1
} //
So we can say that in case of bfs  with undirected  graph , the edge which are not including in the tree are cross edge.
So B will be the answer  , because bfs  tree contains : { (a-c) , ( a-d) , (a-e) ,  (c - f) ,  ( d - b ) }  all this mentioned edges would be tree edges.
answered by Loyal (2.7k points)  

I am aware of the max.ru page on fft. But I could not get easily from there, so I tried from this ..again in russian :) . Thanks for the problem set link. So, if the dice values are very big, then fft should be used right ?

The above problem is also solvable with dynamic programming
f( roll , face , sum )  with three states or  with 2 states too
where f( i , j ,  k ) =  number of ways to make k sum ending with jth value in ith roll of dice.

Complexity will be  : O( roll * face * sum )    or let say O( N ^ 3 )        with dp
with  coefficient   we have to calclaulate ( 0  +  x + x^2 +  x^3 ....  X^face ) ^ roll     
then  again it will be  : O(N ^ 3 )  , if we are multiplying two polyinomials in O(N^2) and if we use fft polynomial divide and conq.   then it will be O(N^2logN)   which is very fast as compared to above.
So if we increase some constraint on the third problem or number of test cases.  Then go for fast multiplication ( FFT )
U have done all three questions.
I have done last year also, not a big deal ! anyways thanks
regarding above comments.

I know how to find complexity. Thanks for explaining, though. Hope in upcoming days will discuss more on these problems.

like to see you in further rounds! (y)

Related questions

0 votes
1 answer
1
asked in Programming by rahul sharma 5 Loyal (3.1k points)   | 59 views
0 votes
0 answers
3
asked in Algorithms by thor Boss (8.6k points)   | 24 views


Top Users Apr 2017
  1. akash.dinkar12

    3508 Points

  2. Divya Bharti

    2542 Points

  3. Deepthi_ts

    2040 Points

  4. rude

    1966 Points

  5. Tesla!

    1768 Points

  6. Shubham Sharma 2

    1610 Points

  7. Debashish Deka

    1588 Points

  8. Arunav Khare

    1454 Points

  9. Kapil

    1424 Points

  10. Arjun

    1420 Points

Monthly Topper: Rs. 500 gift card

22,076 questions
28,041 answers
63,230 comments
24,135 users