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: A Graph Problem

2011-05-30 Thread Aakash Johari
Bipartite Graph.. On Sun, May 29, 2011 at 9:42 PM, ross jagadish1...@gmail.com wrote: @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

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] Google Interview Question

2011-05-30 Thread KRQ
but ,when the arr is 78 3 to add 0 78 30 sort: 30 78 ans:378? 2011/5/27 Logic King crazy.logic.k...@gmail.com i agree with piyush...can't find the countercase...satisfied with the algo. On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote: how about adding zeroes at

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

Re: [algogeeks] Re: A Graph Problem

2011-05-30 Thread anshu mishra
biaprtie graph is special case when we can color the whole graph just by two colors. -- 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

Re: [algogeeks] Re: A Graph Problem

2011-05-30 Thread Aakash Johari
yes, sorry.. i misunderstood the problem. On Sun, May 29, 2011 at 11:24 PM, anshu mishra anshumishra6...@gmail.comwrote: biaprtie graph is special case when we can color the whole graph just by two colors. -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: A Graph Problem

2011-05-30 Thread Aakash Johari
Can this solution work? Create adjacency matrix where adj[i][j] representing person i doesnt like person j. Now toggle the relations (means now the adj[i][j] will represent person i and person j can live with each other) and find the no. of connected components. No. of connected components

Re: [algogeeks] Re: A Graph Problem

2011-05-30 Thread Aakash Johari
No, won't work. :( On Sun, May 29, 2011 at 11:39 PM, Aakash Johari aakashj@gmail.comwrote: Can this solution work? Create adjacency matrix where adj[i][j] representing person i doesnt like person j. Now toggle the relations (means now the adj[i][j] will represent person i and person j

[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

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Naveen Agrawal
@ shubham Your solution need some changes at step 2 step 1: sort the given numbers in the decreasing order based on their first digit(left most). step 2: if two numbers come out to be equal in the above case both of their next digit exist then sort on the basis of their next

[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: Google Interview Question

2011-05-30 Thread Maksym Melnychok
here's efficient oneliner without any string manipulation divide every number by 10^(log10(x).ceil) sort convert back to original numbers join array into string there are edge-cases where this doesn't work but they can be dealt with easily - have to go back to work :) -- You received this

Re: [algogeeks] Google Interview Question

2011-05-30 Thread ankit sambyal
@Nave :: nice solution :) Phoda Sambyal On Mon, May 30, 2011 at 12:13 AM, Naveen Agrawal nav.coo...@gmail.comwrote: @ shubham Your solution need some changes at step 2 step 1: sort the given numbers in the decreasing order based on their first digit(left most). step

[algogeeks] Binary Tree Problem

2011-05-30 Thread ross
Given a binary tree(not a BST) find the 2 nodes of the binary tree which are separated by maximum distance. By distance, we mean no. of edges in the path from node1 to node2. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Sudhir mishra
give some explanation -- 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+unsubscr...@googlegroups.com. For more options,

Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Piyush Sinha
There can be two cases to it Case 1 - The maximum distance passes through the root node. 1 / \ 2 3 / \ 45 Maximum distance is between 4 and 5 i.e. 4 Case 2 - The maximum distance lies

Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Vipul Kumar
That is same as finding the diameter of the tree. On Mon, May 30, 2011 at 1:44 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote: There can be two cases to it Case 1 - The maximum distance passes through the root node.    1 /   \    2 3    

Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Aakash Johari
yes, it is the diameter of the tree. On Mon, May 30, 2011 at 1:17 AM, Vipul Kumar vipul.k.r...@gmail.com wrote: That is same as finding the diameter of the tree. On Mon, May 30, 2011 at 1:44 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote: There can be two cases to it Case 1 - The

Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread ankit sambyal
Here's the crude algo : First find the node having the max depth in the left sub tree and then find the node having the max depth in the right sub tree. Ties are broken arbitrarily. These will be the 2 nodes separated by the maximum distance. The sum of their depths will give us the distance

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread ross
@piyush, Hi, thanks alot for the solution, Thats to find the diameter of a tree. :) But, how would you obtain the 2 nodes which have the max. distance betwn them? On May 30, 1:17 pm, Vipul Kumar vipul.k.r...@gmail.com wrote: That is same as finding the diameter of the tree. On Mon, May

Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Maksym Melnychok
wont work for this tree: x /\ x x /\ x x / \ xy / \ xx /

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Maksym Melnychok
simplest algo: find a node with max depth M and go up tree calculating max depth of all upper branches that do not contain M until reaching root node -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Piyush Sinha
@ross...I think it can be done by taking a queue/stack...I am working on the code...Please comment if there is any error in my approach.. On Mon, May 30, 2011 at 2:19 PM, Maksym Melnychok keym...@gmail.com wrote: simplest algo: find a node with max depth M and go up tree calculating max depth

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread anshu mishra
this is a very standard problem :D start with any node(x) find the node which is at maximum distance. now start with x travese the tree and find the node(y) which is at maximum distance. so finally answer wil be (x, y) traversing the tree two times. so the order for finiding the such nodes

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread anshu mishra
little modification start with any node(r) find the node(x) which is at maximum distance. -- 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

Re: [algogeeks] Google Interview Question

2011-05-30 Thread snehi jain
i guess Sunny has already mentioned (concatenating the two numbers and comparing) this technique before, i liked and tried coding it ... it works perfectly without comparing the second digit incase the first is same. the algorithm can run in O(nlogn) taking the best sorting technique , though i

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
some explanation say we have numbers 2 3 5 78 divide all by something to get 0.2, 0.3, 0.5, 0.78 simple sort will give you 0.78, 0.5, 0.3, 0.2 multiply all numbers to get original ones 78 5 3 2 join 78532 -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Re: posix threads

2011-05-30 Thread jagannath prasad das
@anshu:thats means you say that pthreads are either kernel -level or hybrid in nature @lalit:mapping dependsfor user-level kernel isn't aware of threads,m-m is for kernel-level ,m-n for hybrid kinda does anbody knows whether pthreads are user-level or

Re: [algogeeks] Google Interview Question

2011-05-30 Thread sunny agrawal
@ Maksym Melnychok Fails i think some explanation say we have numbers 1 , 101 divide all by something to get 0.1, 0.101 simple sort will give you 0.101, 0.1 multiply all numbers to get original ones 101,1 join 1011 but correct answer should be 1101, isn't it ?? correct me if i m wrong ?? --

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
possible fix for 100 10 edgecases would be to simply array.map{|x| x*10+1} and then get rid of that after sorting -- 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

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Piyush Sinha
I think following algo will work..I haven't tested it plus its in its crude form...Kindly correct me if i am wrong.. *typedef struct queue { struct node *q[2]; int h1,h2; }queue;* ** *queue max_dist(struct node * tree) { if (tree == NULL) return; queue q1,q2,q3; q1.h1 =

Re: [algogeeks] [brain teaser] Aeroplane Hijack puzzle 30 may

2011-05-30 Thread Vandana Bachani
The hijacker was the pilot. On Mon, May 30, 2011 at 12:34 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *Aeroplane Hijack puzzle SOLUTION * * * ** *A man hijacks an aeroplane transporting both passengers(8 of them) and valuable cargo. After taking the cargo, the man demands nine

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Bhavesh agrawal
solution may be array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all exceptions ) then ,change this array like 3 , 21222, 9, 93999, 17111, 17811, 1 , 10111 ( make each number of 5 digit with rest digits same as Ist digit ) then sort this array 9, 93999,3

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Piyush Sinha
@Bhavesh... for the inputs 18,187.. apply your method.. 18 -- 188 187-- 187 18187 - ur method 18718 - actual On Mon, May 30, 2011 at 3:28 PM, Bhavesh agrawal agr.bhav...@gmail.comwrote: solution may be array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all exceptions ) then

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@Sunny i explained how to deal with edgecases right after my post 1, 101 - 11, 1011 11, 1011 - 0.11, 0.1011 sort - 0.11, 0.1011 restore - 1, 101 join - 1101 i can't think of any fail examples anymore -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Google Interview Question

2011-05-30 Thread snehi jain
@Maksym what if we have 90 and 9 they become .9 and .9 now what to do to get result as 990 and not 909. correct me if i am going somewhere wrong? On Mon, May 30, 2011 at 3:55 PM, Maksym Melnychok keym...@gmail.com wrote: @Sunny i explained how to deal with edgecases right after my post 1,

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@halo check my previous messages we multiply every element by 10 and add 1 90, 9 - 901, 91 901, 91 - 0.901, 0.91 sort - 0.91, 0.901 revert - 9, 90 join - 990 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

Re: [algogeeks] Google Interview Question

2011-05-30 Thread snehi jain
ok ... got it thanks ... :) On Mon, May 30, 2011 at 5:25 PM, Maksym Melnychok keym...@gmail.com wrote: @halo check my previous messages we multiply every element by 10 and add 1 90, 9 - 901, 91 901, 91 - 0.901, 0.91 sort - 0.91, 0.901 revert - 9, 90 join - 990 -- You received this

[algogeeks] Re: Google Interview Question

2011-05-30 Thread Maksym Melnychok
so here's oneliner code in ruby: a.map{|x| x=x*10+1; -x/10.0**Math.log10(x).ceil}.sort.map{|x| (-x).to_s[2..-2]}.join -- 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

[algogeeks]

2011-05-30 Thread Sairam Krishnamurthy
http://www.tavistockwood.com/find11.html -- 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+unsubscr...@googlegroups.com.

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Bhavesh agrawal
@piyush : hey buddy, check out carefully i think you missed something. my solution says it's 18 -18111 187-18711 and i think you will count it carefully... plz let me know in any case if my solution goes wrong anywhere . -- You received this message because

Re: [algogeeks] Admin of Group

2011-05-30 Thread HARISH S.C
+1 On Thu, May 26, 2011 at 9:31 PM, Ashish Patel ashishpatel1...@gmail.comwrote: +1000 ..dont count this as SPAM! :D On Thu, May 26, 2011 at 9:29 PM, radha krishnan radhakrishnance...@gmail.com wrote: +100 On Thu, May 26, 2011 at 9:26 PM, pacific :-) pacific4...@gmail.comwrote: +1

[algogeeks] can ne1 pls help me

2011-05-30 Thread Abdul Rahman Shariff
i had this qn in a previous qpaper for my semeter exams in design and anlysis of algorithems draw an optimal merge pattern tree for the srting abracadabra thnks in advance pls solve this asap i have the xam tomorow -- Ehab Abdul Rahman Shariff -- You received this message because you are

[algogeeks] Re: C Output

2011-05-30 Thread Dave
@vishal: Floats and doubles are stored in different formats, so looking at the first 8 hex digits of the two numbers isn't really helpful. The expression f 0.8 is evaluated as (double)f 0.8, so it would be more useful to print all 16 hex digits of (double)0.8f and 0.8. Then it would be easy to

Re: [algogeeks] can ne1 pls help me

2011-05-30 Thread Abdul Rahman Shariff
thnaq On Mon, May 30, 2011 at 8:00 PM, nagajyothi gunti nagajyothi.gu...@gmail.com wrote: Hi Shariff I thought this document would be a help to you. There is an example with this string. On Mon, May 30, 2011 at 10:16 AM, Abdul Rahman Shariff ears7...@gmail.com wrote: i had this qn in

Re: [algogeeks] SPOJ Problem Help

2011-05-30 Thread oldman
Code::Blocks On Sun, May 29, 2011 at 1:59 AM, Akash Mukherjee akash...@gmail.com wrote: devcpp On Sat, May 28, 2011 at 11:17 PM, sravanreddy001 sravanreddy...@gmail.com wrote: Hi all. Can some one provide a good C editor.. preferable GUI one, that works on windows 7. I'm good with

[algogeeks] Scheduling dp problem - MSFT interview

2011-05-30 Thread ross
You are given a sequence of jobs. The no. of days which each job takes to complete is also provided. You are also given the penalty amount to be paid per day each day a job left done. Give an optimal ordering among jobs to minimize penalty. There are no concurrent jobs. eg: Jobs:

[algogeeks] Re: island puzzle

2011-05-30 Thread himanshu kansal
guys wake up On Fri, May 27, 2011 at 9:24 PM, himanshu kansal himanshukansal...@gmail.com wrote: a king has two sons eric and bob.he wants to divide his islands the islands are in a queue.eric being elder gets the first chancethey both can pick d island alternatively

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
won't this simple algo work ?? start from root node, say it has value 0 at any time if a node has a value v pass v-1 to left subtree and v+1 to right subtree keep track of max and min final answer will be max -min = Diameter of tree. correct me if i m wrong. -- You received this message

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
nope, it will not work :( got a case On Mon, May 30, 2011 at 11:57 PM, sunny agrawal sunny816.i...@gmail.comwrote: won't this simple algo work ?? start from root node, say it has value 0 at any time if a node has a value v pass v-1 to left subtree and v+1 to right subtree keep track of max

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread T3rminal
Right!! that is pretty standard problem but the solution u have given is for undirected graphs and intuitively binary trees are directed. Piyush solution will work for binary tree. On May 30, 2:04 am, anshu mishra anshumishra6...@gmail.com wrote: this is a very standard problem :D start with

Re: [algogeeks] Re: island puzzle

2011-05-30 Thread Carl Barton
It's been posted quite a few times recently. Just check the mailing list. On 30 May 2011 18:46, himanshu kansal himanshukansal...@gmail.com wrote: guys wake up On Fri, May 27, 2011 at 9:24 PM, himanshu kansal himanshukansal...@gmail.com wrote: a king has two sons eric and bob.he

Re: [algogeeks] Re: island puzzle

2011-05-30 Thread Anand
http://anandtechblog.blogspot.com/2010/10/directi-interview-question_3183.html On Mon, May 30, 2011 at 3:54 PM, Carl Barton odysseus.ulys...@gmail.comwrote: It's been posted quite a few times recently. Just check the mailing list. On 30 May 2011 18:46, himanshu kansal