Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread anshu mishra
@ akash solution is complete. :P first try to understand the solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread Aakash Johari
@anshuman sir: yes, I know you have completed the solution. I have just added :) On Sun, May 29, 2011 at 11:02 PM, anshu mishra anshumishra6...@gmail.comwrote: @ akash solution is complete. :P first try to understand the solution. -- You received this message because you are subscribed

[algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread ross
@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 aakashj@gmail.com wrote: At the each level, traversed by BFS,

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread Aakash Johari
@ross : * if their flag is true and their value is equal to x* On Sun, May 29, 2011 at 11:07 PM, ross jagadish1...@gmail.com wrote: @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

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread anshu mishra
@ross no, a particular element has to read only 5 times maximum. 1 reading (i,j) (if its flag is already false skip) 2 read by top element 3. read by bottom element 4 read by left element 5 read by right element coz atleast one of the this operation its flag will be unset(false), then we have to

[algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread ross
@anshu mishra: Hi, kindly clarify on this small doubt of mine. Your algo is while (!q.empty()) { x = q.top(); q.pop(); if(node notvisited already adjacent to x value = x) add to queue } For the graph, 1 1 2 1 3 1 2 3 4 first, queue = 1 (at 0,0) then you would add the 2 1s at (0,1) and (1,0)

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread anshu mishra
main() { for (i = 0; i n; i++) { for (j = 0; j n; j++) { if (flag[i][[j]) { bfs(mat, flag, i, j); count++; } } } } bfs(mat[][], flag[][], i, j) while (!q.empty()) { x = q.top(); q.pop(); if(node notvisited already

[algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread ross
@anshu mithra: Hi, Thanks for clarifying! :) On May 30, 11:06 am, anshu mishra anshumishra6...@gmail.com wrote: main() { for (i = 0; i n; i++) {      for (j = 0; j n; j++)      {             if (flag[i][[j])            {                  bfs(mat, flag, i, j);                  count++;

[algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread ross
@vishal Hi, I do not get you. Can you please elaborate a little more how you ll use hash? On May 30, 8:50 am, Vishal Thanki vishaltha...@gmail.com wrote: what about using a hash function? On Mon, May 30, 2011 at 10:18 AM, ross jagadish1...@gmail.com wrote: Given a matrix, you need to

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread Vishal Thanki
Okay, i thought it this way: iterate through the whole matrix, and take the value as a key to a hash table. and the value corresponding to the key would be the count. increment the count everytime you encounter the same key. it is very easy to implement this in python (using dictionary) but i am

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread Piyush Sinha
@ross... I have adoubt regarding this question... what should be output if the matrix is like this.. 1 1 2 1 3 1 2 3 4 U reply I will tell you then what doubt I have. On Mon, May 30, 2011 at 10:36 AM, Vishal Thanki vishaltha...@gmail.comwrote: Okay, i thought it this way: iterate through

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread anshu mishra
it is a simple graph problem. travese the whole matrix using BFS. it will be O(n^2). for (i = 0; i n; i++) { for (j = 0; j n; j++) { if (flag[i][[j]) { bfs(mat, flag, i, j); count++; } } } -- You received this

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread anshu mishra
@vishal ur sol wil give wrong answer for this 1 1 2 1 3 1 2 3 4 answer should be 6 but ur sol wil give 4. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread Piyush Sinha
@anshucan u plz elaborate ur solution for a particular case?? On Mon, May 30, 2011 at 10:49 AM, anshu mishra anshumishra6...@gmail.comwrote: @vishal ur sol wil give wrong answer for this 1 1 2 1 3 1 2 3 4 answer should be 6 but ur sol wil give 4. -- You received this message because

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread Vishal Thanki
@anshu, i got you. my bad!! On Mon, May 30, 2011 at 10:49 AM, anshu mishra anshumishra6...@gmail.com wrote: @vishal ur sol wil give wrong answer for this 1 1 2 1 3 1 2 3 4 answer should be 6 but ur sol wil give 4. -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread anshu mishra
@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

Re: [algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread Aakash Johari
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 anshumishra6...@gmail.comwrote: @piyush void bfs(int mat[][n],