@Anshu If you do " add top bottom, left right element to the popped element in qeuue " should you need to do it for each element in the matrix. So, will that not be O(n3)??
Clarify if i am wrong. On May 30, 9:52 am, Aakash Johari <[email protected]> wrote: > At the each level, traversed by BFS, you will have to check whether the > vertex in this level has the element same as it found in the previous level. > If it is different, then count it. > > On Sun, May 29, 2011 at 10:43 PM, anshu mishra > <[email protected]>wrote: > > > > > > > > > > > @piyush > > > void bfs(int mat[][n], bool flag[][n], int i, int j) > > { > > queue.push(mat[i][j]); > > while (!q.empty()) > > { > > x = q.top(); > > q.pop(); > > add top bottom, left right element in qeuue if their flag is true and their > > value is equal to x and mark their flag false; > > } > > } > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. > > -- > -Aakash Johari > (IIIT Allahabad) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
