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

a)(d,c)

b)(d,b)

c)(e,b)

d)(e,f)

asked in DS by Veteran (53.8k points)   | 181 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.5k points)   | 62 views
0 votes
0 answers
3
asked in Algorithms by thor Boss (8.6k points)   | 25 views


Top Users May 2017
  1. akash.dinkar12

    3302 Points

  2. pawan kumarln

    1776 Points

  3. Bikram

    1646 Points

  4. sh!va

    1640 Points

  5. Arjun

    1396 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1142 Points

  8. Angkit

    1044 Points

  9. LeenSharma

    1000 Points

  10. Arunav Khare

    754 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    732 Points

  2. Arnab Bhadra

    402 Points

  3. pawan kumarln

    402 Points

  4. bharti

    304 Points

  5. LeenSharma

    238 Points


22,822 questions
29,142 answers
65,209 comments
27,666 users