First time here? Checkout the FAQ!
+4 votes





asked in DS by Veteran (55.5k points)   | 200 views

3 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.4k 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.

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 
    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.8k points)  

I am aware of the 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)
0 votes



answered by Loyal (4.6k points)  

Top Users Jul 2017
  1. Bikram

    4062 Points

  2. manu00x

    2464 Points

  3. Debashish Deka

    1850 Points

  4. joshi_nitish

    1658 Points

  5. Arjun

    1294 Points

  6. Hemant Parihar

    1184 Points

  7. Arnab Bhadra

    1112 Points

  8. Shubhanshu

    1054 Points

  9. Ahwan

    900 Points

  10. rahul sharma 5

    706 Points

24,022 questions
30,966 answers
29,342 users