[algogeeks] Popular Puzzle of the week

2011-05-29 Thread Lavesh Rawat
*Hi,* * * *Based on most comments, The popular puzzle of the last week is* * * * http://dailybrainteaser.blogspot.com/2011/05/murder-mystery-puzzle-23-may.html?lavesh=lavesh * * * *Please subscribe and follow this blog to show your liking to the blog.* * * *-- * Never explain

Re: [algogeeks] Google Interview Question

2011-05-29 Thread Ashish Goel
Radix/bucket sort.. won't that help? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, May 27, 2011 at 7:15 PM, adityasir...@gmail.com wrote: how about this case: 9, 100 - 9100 100 9 9100 2, 3, 9, 78 -- 78 9 3 2 9 78 3 2 I guess

Re: [algogeeks] Google Interview Question

2011-05-29 Thread Vishal Jain
Can this work... Lets say I have following numbers 8 9 7 4 2 121 23 21 24 27 35 79 2334 6785 Now repeat the last number to make all the number of equal length... 1211 2333 2111 2444 2777 3555 7999 2334 6785 Sort the following numbers in descending order. 7999

Re: [algogeeks] one constructor problem

2011-05-29 Thread D.N.Vishwakarma@IITR
check this sol frends #includeiostream using namespace std; class A { private: int a; public: A(int m) { a=m; } }; int main() { coutEnter no of objects in arrayendl; int p,n; cinn; coutEnter value of a for first object of arrayendl; cinp;

Re: [algogeeks] Re: spoj--two squares problem

2011-05-29 Thread Vishal Jain
Hi Saurabh, Can you try it for 10? Could not really understand, what are you gonna communicate? 10 = 2*5 (2^2 + 1^2 )*(1*2 + 1^2)... If with this logic you are saying 10 is prime then all numbers divisible by 5 should be prime. Could you elaborate your answer more? Thanks Regards Vishal Jain

[algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Dumanshu
here in this part if bitmap[bi] matrix[i][j]) 0x1) == 0x0) (((bitmap[bj] matrix[i][j]) 0x1) == 0x0) (((bitmap[bk] matrix[i][j]) 0x1) == 0x0)) { bitmap[bi] |= 1 matrix[i][j];

Re: [algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Vishal Thanki
yes, you are right. bitmap will be filled in the process of solving the grid. in verify routine, if the expression evaluates to false, it mean an element is encountered which is already present in row, col and 3x3 cube. this way you an tell that the solution is wrong. hope that helps. On Sun,

[algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Dumanshu
no... what i mean to say is you have filled the bitmap in the process of solving the grid. The way you are filling the bitmap is - you are taking values from the matrix and placing them in the bitmaps using bi bj bk. now in the verification you are checking the same matrix value against the same

[algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Dumanshu
I think ur verification function is correct but it works only if user is entering the values one by one. as soon as he enters a duplicate value it will show a error. It will work for the case of ur solver as ur code itself is generating the values. But here in this verification problem u r given a

Re: [algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Vishal Thanki
sorry, i made a mistake in explaining. when you are solving the gird, you will have the matrix[][] array partially filled. the bitmap used for solving the grid is different than the one being used for verifying. in case of verifying, you will have a completely blank bitmap, with not bits set. you

Re: [algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Vishal Thanki
what i understood from your problem is, when the configuration is given by user, it can be directly stored into matrix[][] array. that will solve your problem in o(n^2), where n=9. On Sun, May 29, 2011 at 5:50 PM, Dumanshu duman...@gmail.com wrote: I think ur verification function is correct but

[algogeeks] Re: Google Interview Question

2011-05-29 Thread srinivas reddy
for eg 10, 9 most signifacnt digit of 10 is 1 and 9 is 9 so after sorting based on most significant digit is 10,9 output 910 2nd ex 2,3,5,78 most significant digit is 2,3,5,7 so out put is 78532 On May 29, 12:59 am, Vishal Jain jainv...@gmail.com wrote: Can this work... Lets say I have

[algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Dumanshu
oh yeah... now it works. thanx a lot! On May 29, 5:20 pm, Vishal Thanki vishaltha...@gmail.com wrote: sorry, i made a mistake in explaining. when you are solving the gird, you will have the matrix[][] array partially filled. the bitmap used for solving the grid is different than the one being

Re: [algogeeks] Re: spoj--two squares problem

2011-05-29 Thread Pradip Singh
use long long int instead of int for X and all except t.and type cast the sqrt returned value to integer..like int(sqrt(X)) On Sun, May 29, 2011 at 1:55 PM, Vishal Jain jainv...@gmail.com wrote: Hi Saurabh, Can you try it for 10? Could not really understand, what are you gonna communicate?

[algogeeks] A Graph Problem

2011-05-29 Thread ross
There are n persons. You are provided with a list of ppl which each person does not like. Determine the minm no. of houses required such that, in no house 2 people should dislike each other. Is there a polynomial time solution exist for this? Or is this not solvable at all? -- You received this

[algogeeks] C Output

2011-05-29 Thread Ankit Agarwal
#includestdio.h int main(void) { float a=0.08; if(a0.08) printf(Hello\n); else printf(Hii\n); return 0; } The o/p is: *Hello * why -- Ankit Agarwal -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] C Output

2011-05-29 Thread Vishal Thanki
a 0.08f will make it compare to float. by default 0.08 is considered as double. On Sun, May 29, 2011 at 9:51 PM, Ankit Agarwal ankitgeniu...@gmail.com wrote: #includestdio.h int main(void) {     float a=0.08;     if(a0.08)         printf(Hello\n);     else         printf(Hii\n);    

Re: [algogeeks] Re: Google Interview Question

2011-05-29 Thread sravanreddy001
@vishal,Sanjeev.. for the inputs 18,187.. apply ur method.. 18 -- 188 187-- 187 18187 - ur method 18718 - actual @Sunny... i agree that your algorithm takes the *O(N logN)* time.. but again.. the problem is it* doesn't get* the exact solution. Do we really have a polynomial solution for this

Re: [algogeeks] C Output

2011-05-29 Thread sravanreddy001
and, I read it long time back that.. the value of 0.8 alone will be stored as 0.7995 (not sure on the number of 9's but.. the last digit in the precision will be a 5) that could be a reason. may be what vishal said is correct. -- You received this message because you are subscribed to

Re: [algogeeks] Re: Google Interview Question

2011-05-29 Thread sunny agrawal
@sravanreddy001 i don't find any cases for which my algo fails and its O(nlgn) i may be missing something can you tell any case where it fails On Sun, May 29, 2011 at 10:15 PM, sravanreddy001 sravanreddy...@gmail.comwrote: @vishal,Sanjeev.. for the inputs 18,187.. apply ur method.. 18 --

Re: [algogeeks] A Graph Problem

2011-05-29 Thread anshu mishra
it is exactly a graph coloring problem. so it has no polynomial order 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] C Output

2011-05-29 Thread Vishal Thanki
you may want to check how the floats and doubles are stored into memory using ieee notation. i tried to print 0.08 and 0.08f in hex format and got the following result. vishal@ubuntu:~/progs/c\ 10:03:56 AM $ cat fl.c #include stdio.h int main() { float f=0.08; if (f 0.08f)

[algogeeks] Re: A Graph Problem

2011-05-29 Thread ross
@anshu mishra: Yeah. Thanks! :) On May 30, 8:26 am, anshu mishra anshumishra6...@gmail.com wrote: it is exactly a graph coloring problem. so it has no polynomial order solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Finding Blocks in a matrix

2011-05-29 Thread Vishal Thanki
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 find the number of blocks in it. A block has the same numbers. EG: 1 1 3 1 2 3 2 2 4 has 4 blocks namely, 1 1 1   2 2 2 3 3 4 1 2 3 4 5 6 7 8 9

Re: [algogeeks] Re: posix threads

2011-05-29 Thread anshu mishra
write these three lines in ur function, it will bind that particular thread to (id)th processor wher void func(int id) { unsigned long mask; mask = 1id; pthread_setaffinity_np(pthread_self(), sizeof(mask), mask); } main() { pthread_t *thread; thread =

Re: [algogeeks] Re: posix threads

2011-05-29 Thread anshu mishra
PS dont forget to bind ith thread with ith processor -- 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

[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] C Output

2011-05-29 Thread arjoo kumar
when u store 0.08 on the float variable a then it does not store exactly 0.08 on 'a' actually it store 0.7999 that's why after comparition it make less quantity with 0.08 i.e 'if ' condition is true and print it HELLO On Sun, May 29, 2011 at 9:21 AM, Ankit Agarwal

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] snake and ladder

2011-05-29 Thread Kunal Yadav
Made snake and ladder in c using graphics some time ago. Maybe it could help http://algoritmus.in/blog/2011/03/snakes-and-ladder-in-cgraphics/ On Sat, May 28, 2011 at 2:58 PM, utkarsh srivastav usdilogi...@gmail.comwrote: sorry snake and ladder On Sat, May 28, 2011 at 2:27 AM, Dilogical King

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] C Output

2011-05-29 Thread Ankit Agarwal
Thank u guys :) :) On Mon, May 30, 2011 at 10:40 AM, arjoo kumar 2009ar...@gmail.com wrote: when u store 0.08 on the float variable a then it does not store exactly 0.08 on 'a' actually it store 0.7999 that's why after comparition it make less quantity with 0.08 i.e 'if ' condition is

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],