@ 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
@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
@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,
@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
@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
@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)
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
@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++;
@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
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
@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
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
@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
@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
@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
@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
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],
17 matches
Mail list logo