Re: [algogeeks] Linked List question

2013-01-07 Thread Doom
Thank you for the code snippet.

What I don't understand is 

if( (double)rand() / RAND_MAX   1 / k ) 

Here, Why do we use less than inequality?

Why won't Udit's solution of just using the minimum random number work?

On Tuesday, 1 January 2013 20:57:47 UTC+5:30, Dave wrote:

 @Doom: Yes. It is necessary to go through the entire list. The code could 
 look like this:
  
 int* p = head;
 int k = 1;
 while( head )
 {
 head = head - next;
 k++;
 if( k * (double)rand()  RAND_MAX )
 p = head;
 }
  
 Dave

 On Sunday, December 30, 2012 12:40:28 PM UTC-6, Doom wrote:

 Hi Dave

 Please help me with some additional clarification regarding the 
 implementation of this algo. How do we make use of random number generator?

 And is it necessary to traverse the list until the end? 


 On Friday, 28 December 2012 19:35:07 UTC+5:30, Dave wrote:

 @Sanjeev: Set a pointer p to the first node. Traverse the list. When at 
 the kth node, set p to the kth node with probability 1/k. When you reach 
 the end of the list, return p, which will point to a random node with 
 uniform probability.
  
 Dave

 On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to 
 traverse the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.comwrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com wrote:
  But suppose a random number generate a value 5 and your linked list 
 has only
  four elements. In that case what would be the answer ???
 
 
  On Thu, Dec 27, 2012 at 4:03 PM, Prem Krishna Chettri 
 hpre...@gmail.com
  wrote:
 
  Well my algo will be Something like this
 
  1 Get a Random number. Perhaps You can have the function like 
 Randon(List
  *head, int Randomnumber)
 
  2 Use the function argument Randomnumber to loop the list.
  i.e. for(int count=0;count=Randomnumber;count++ ){
 head = head - next;
  }
 
  3 print (head-value);
 
  4 return ;
 
  Now as we are using byvalue when we return the value of head 
 remains the
  same old head value. So everytime we call we are traversing the 
 same old
  list.
 
   The Random variable can be taken inside the function itself if 
 the user
  is not taking the random value.
   i.e. int Randomnumber = random();  and now the user can calll 
 Simple
  Random(head);
 
 
 
  On Thu, Dec 27, 2012 at 3:31 PM, naveen shukla
  naveenshukla...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com
 Mobile: +91-9411656264

 --





 -- 
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com 



-- 




Re: [algogeeks] Linked List question

2013-01-01 Thread Doom
Hi Dave

Please help me with some additional clarification regarding the 
implementation of this algo. How do we make use of random number generator?

And is it necessary to traverse the list until the end? 


On Friday, 28 December 2012 19:35:07 UTC+5:30, Dave wrote:

 @Sanjeev: Set a pointer p to the first node. Traverse the list. When at 
 the kth node, set p to the kth node with probability 1/k. When you reach 
 the end of the list, return p, which will point to a random node with 
 uniform probability.
  
 Dave

 On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to 
 traverse the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.com wrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com wrote:
  But suppose a random number generate a value 5 and your linked list 
 has only
  four elements. In that case what would be the answer ???
 
 
  On Thu, Dec 27, 2012 at 4:03 PM, Prem Krishna Chettri 
 hpre...@gmail.com
  wrote:
 
  Well my algo will be Something like this
 
  1 Get a Random number. Perhaps You can have the function like 
 Randon(List
  *head, int Randomnumber)
 
  2 Use the function argument Randomnumber to loop the list.
  i.e. for(int count=0;count=Randomnumber;count++ ){
 head = head - next;
  }
 
  3 print (head-value);
 
  4 return ;
 
  Now as we are using byvalue when we return the value of head remains 
 the
  same old head value. So everytime we call we are traversing the same 
 old
  list.
 
   The Random variable can be taken inside the function itself if the 
 user
  is not taking the random value.
   i.e. int Randomnumber = random();  and now the user can calll Simple
  Random(head);
 
 
 
  On Thu, Dec 27, 2012 at 3:31 PM, naveen shukla
  naveenshukla...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com
 Mobile: +91-9411656264

 --





 -- 
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com 



-- 




Re: [algogeeks] expectation values..

2012-06-17 Thread Doom
If we expand it.. E(t) = E(t1) + E(t2) + E(t3) + ... + E(tn);
here I am able to derive E(t1) as N/1 using the expression E(t1) = 1/N + 
((N-1)/N)(E(t1) + 1);
but how do I proceed?
How do I derive the E(t2) and so on??

What do these values mean??
Does it mean like E(t2) is the no. of expected throws to get value 2??

Any help on this?

On Sunday, 17 June 2012 00:09:13 UTC+5:30, amitesh wrote:

 This problem is similar to Coupan collector problem. 
 http://en.wikipedia.org/wiki/Coupon_collector%27s_problem
  
 In your case the answer is 
  
 [image: For N-Dice ; \newline \sum_{i=1}^{N} N/i \newline for\; N =~2 ; 
 \newline \sum_{i=1}^{2} 2/i = 2/1 + 2/2 = 3 \newline]
  
  
 Hope it helps!
  

 -- 
 Amitesh




 On Sat, Jun 16, 2012 at 5:18 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote:

 What is the expected number of throws of his die while it has N sides
 so that each number is rolled at least once?
 e.g
 for n=2 ans 3.00
 n=12 ans is 37.24...
 i refrd to expectation tutuorial at
 http://www.codechef.com/wiki/tutorial-expectation but still couldnt
 get the logic...

 any help?

 --
 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, visit this group at 
 http://groups.google.com/group/algogeeks?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/xLsfC_Gc8z0J.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Find border of a binary tree.

2012-04-08 Thread Doom
75 is omitted because its the border. Think of border like putting an 
elastic rubber band around the tree. Print the nodes being touched by the 
rubber.

On Monday, 9 April 2012 08:12:48 UTC+5:30, Gene wrote:

 Good question.  The problem is not well-defined.  It's possible that 
 75 should be omitted because there are deeper subtrees to the left and 
 right.  But we'll never know for sure because examples don't make a 
 good definition. 



 On Apr 8, 2:29 pm, atul anand atul.87fri...@gmail.com wrote: 
  i guess in the given link 1st example should inculde 75 ?? correect me 
 if i 
  am wrong. 
  
  
  
  
  
  
  
  On Fri, Apr 6, 2012 at 10:53 PM, Doom duman...@gmail.com wrote: 
   Here is the reference: 
  http://stackoverflow.com/questions/3753928/finding-border-of-a-binary... 

  
   None of the proposed solutions is effective enough. Any ideas? 
  
   -- 
   You received this message because you are subscribed to the Google 
 Groups 
   Algorithm Geeks group. 
   To view this discussion on the web visit 
  https://groups.google.com/d/msg/algogeeks/-/xjchdh2I_7MJ. 
   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, visit this group at 
  http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/vCCkW93pMCgJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Find border of a binary tree.

2012-04-06 Thread Doom
Here is the reference:  
http://stackoverflow.com/questions/3753928/finding-border-of-a-binary-tree

None of the proposed solutions is effective enough. Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/xjchdh2I_7MJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Path along the diameter of the binary tree

2012-04-06 Thread Doom
We have seen the question of computing the diameter of binary tree. Any 
ideas to compute the path of nodes along that diameter? No parent pointer 
exists.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/CMNxVKMrfasJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] how to code a deterministic or Non-Deterministic finite state automata model?

2012-04-06 Thread Doom
Any pointers to a code using NFA / DFA computation model?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/UO5Em7j89scJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Pruning number of a binary tree

2012-04-06 Thread Doom
Can any one help me in understanding the concept? Here is the reference 
link:  
http://stackoverflow.com/questions/8288820/pruning-number-of-a-binary-tree

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/mheOlnSKgGYJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: 答复: [algogeeks] Given an array A[1..n] of log n

2012-04-05 Thread Doom
in-place is O(1) auxiliary space. Could you please of something else?

On Thursday, 5 April 2012 10:24:09 UTC+5:30, Rujin Cao wrote:

 =?utf-8?Q?_bit_integers,_sort_them_in-place_in_O(n)_time?=
 MIME-Version: 1.0
 Content-Type: multipart/alternative;
 boundary==_Part_1591_7508851.1333541114758

 --=_Part_1591_7508851.1333541114758
 Content-Type: text/plain; charset=utf-8
 Content-Transfer-Encoding: quoted-printable

 using counting sort with an extra O(log n) space to store the
 appearance count of each number in the range[0,log n].
 And then iterate from begin to end to set each number with its count
 times.
 I'm not sure whether it is appropriate to call it in-place, but at
 least it doesn't use O(n) space.

 Sent from my Windows Phone
 =E5=8F=91=E4=BB=B6=E4=BA=BA: Doom
 =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2012/4/4 20:05
 =E6=94=B6=E4=BB=B6=E4=BA=BA: algogeeks@googlegroups.com
 =E4=B8=BB=E9=A2=98: Re: [algogeeks] Given an array A[1..n] of log n bit 
 int=
 egers,
 sort them in-place in O(n) time
 how are you going to do it in-place?

 On Wednesday, 4 April 2012 13:24:01 UTC+5:30, Siddhartha wrote:
 
  if the length of the binary representation of elements is logn, then the=
 =20
  elements themselves are of size less than 2^log(n)=3Dn.
  as all the elements are less than n, use counting sort!!!
 

 --=20
 You received this message because you are subscribed to the Google Groups 
 =
 Algorithm Geeks group.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/al=
 gogeeks/-/glXPUeyoh8IJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscribe@googleg=
 roups.com.
 For more options, visit this group at 
 http://groups.google.com/group/algoge=
 eks?hl=3Den.


 --=_Part_1591_7508851.1333541114758
 Content-Type: text/html; charset=utf-8
 Content-Transfer-Encoding: quoted-printable

 htmlheadmeta content=3Dtext/html; charset=3Dutf-8 
 http-equiv=3DCont=
 ent-Type/headbodydivdiv style=3Dfont-family: Calibri,sans-serif; 
 =
 font-size: 11pt;using counting sort with an extra O(log n) space to 
 store=
  the appearance count of each number in the range[0,log n].brAnd then 
 ite=
 rate from begin to end to set each number with its count times.brI'm not 
 =
 sure whether it is appropriate to call it in-place, but at least it 
 doesn=
 't use O(n) space.brbrSent from my Windows 
 Phonebr/div/divhrsp=
 an style=3Dfont-family: Tahoma,sans-serif; font-size: 10pt; font-weight: 
 b=
 old;=E5=8F=91=E4=BB=B6=E4=BA=BA: /spanspan style=3Dfont-family: 
 Tahom=
 a,sans-serif; font-size: 10pt;Doom/spanbrspan style=3Dfont-family: 
 =
 Tahoma,sans-serif; font-size: 10pt; font-weight: bold;=E5=8F=91=E9=80=81=
 =E6=97=B6=E9=97=B4: /spanspan style=3Dfont-family: Tahoma,sans-serif; 
 f=
 ont-size: 10pt;2012/4/4 20:05/spanbrspan style=3Dfont-family: 
 Tahom=
 a,sans-serif; font-size: 10pt; font-weight: 
 bold;=E6=94=B6=E4=BB=B6=E4=BA=
 =BA: /spanspan style=3Dfont-family: Tahoma,sans-serif; font-size: 
 10pt;=
 algogeeks@googlegroups.com/spanbrspan style=3Dfont-family: 
 Tahoma,s=
 ans-serif; font-size: 10pt; font-weight: bold;=E4=B8=BB=E9=A2=98: 
 /span=
 span style=3Dfont-family: Tahoma,sans-serif; font-size: 10pt;Re: 
 [algog=
 eeks] Given an array A[1..n] of log n bit integers, sort them in-place in 
 O=
 (n) time/spanbrbr/body/htmlhow are you going to do it 
 in-place?=
 brbrOn Wednesday, 4 April 2012 13:24:01 UTC+5:30, Siddhartha 
  wrote:bl=
 ockquote class=3Dgmail_quote style=3Dmargin: 0;margin-left: 
 0.8ex;border=
 -left: 1px #ccc solid;padding-left: 1ex;if the length of the binary 
 repre=
 sentation of elements is logn, then the elements themselves are of size 
 les=
 s than 2^log(n)=3Dn.divas all the elements are less than n, use counting 
 =
 sort!!!/div
 /blockquote

 p/p

 -- br /
 You received this message because you are subscribed to the Google Groups 
 =
 Algorithm Geeks group.br /
 To view this discussion on the web visit a href=3D
 https://groups.google.c=
 om/d/msg/algogeeks/-/glXPUeyoh8IJ
 https://groups.google.com/d/msg/algogeek=
 s/-/glXPUeyoh8IJ/a.br /=20
 To post to this group, send email to algogeeks@googlegroups.com.br /
 To unsubscribe from this group, send email to 
 algogeeks+unsubscribe@googleg=
 roups.com.br /

 For more options, visit this group at 
 http://groups.google.com/group/algoge=
 eks?hl=3Den.br /

 --=_Part_1591_7508851.1333541114758--



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/LGcbPhxQFrsJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Find the maximum boxes which can fit each other?

2012-04-05 Thread Doom
@Don: Any ideas which oppose the above proposed solution?


On Saturday, 24 March 2012 21:52:49 UTC+5:30, Don wrote:

 Build a graph in which each box is a vertex and there is an edge from 
 A to B if B can fit inside A. Then use the longest path algorithm to 
 find the solution. 
 Don 

 On Mar 24, 1:55 am, Ratan success.rata...@gmail.com wrote: 
  You are given a lot of cuboid boxes with different length, breadth and 
  height. You need to find the maximum subset which can fit into each 
  other. 
  For example: 
  If Box A has LBH as 7 8 9 
  If Box B has LBH as 5 6 8 
  If Box C has LBH as 5 8 7 
  If Box D has LBH as 4 4 4 
  then answer is A,B,D 
  
  A box can fit into another only and only if all dimensions of that is 
  less than the bigger box. Also Rotation of boxes is not possible... 
  
  can ny1 suggest a good algo for this? 
  
  -- 
  -- 
  Ratan | 3rd Year | Information Technology | NIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/C1yQ1v_QAboJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: water-jug problem

2012-04-05 Thread Doom
@Don:

Could you please explain ur tree approach with an example? 

Thanks
Doom

On Tuesday, 3 April 2012 02:52:17 UTC+5:30, Don wrote:

 I did that by building a tree in which each node stores the 
 configuration, including number of steps to that point, amount of 
 water in each bucket, and a pointer to the parent, sibling, and 
 leftmost child. Start out with one node with stepCount set to zero and 
 all the buckets empty. You want the solution with the least number of 
 steps, so use a breadth-first search. For each node, create a list of 
 children based on the following: 

 1. For each bucket which is not full, fill it 
 2. For each bucket which is not empty, empty it 
 3. For each pair of buckets A and B where A is not empty and B is not 
 full, pour A into B 

 When you find a bucket with the desired amount of water, you can trace 
 back through the parent pointers to get the series of moves required 
 to get there. 

 If you just need the minimum number of steps, the problem is much 
 easier. Just use a 99x99x99 table D[99][99][99]. If the bucket 
 capacities are a,b,c, start with all table values set to a large value 
 except 

 D[a][0][0] = D[0][b][0] = D[0][0][c] = 1 

 Then iteratively start with all states with depth d and set all states 
 which can be reached from that state by a single step to d+1 if their 
 current depth is greater than d+1. You'll end up with a table of all 
 states reachable with the set of buckets, and the minimum number of 
 steps to reach each state. 

 Don 


 On Apr 1, 12:57 pm, bharat b bagana.bharatku...@gmail.com wrote: 
 A common puzzle asked during interviews is how to measure 4 liters of 
 water with just two uneven shaped buckets, one of 3 liter another of 
 5 
 liter, in minimum number of steps. To extend and generalize this, 
 write a 
 program to evaluate the minimum number of steps to measure “X” liters 
 of 
 water, with “Y” buckets each having a separate denomination. The 
 assumptions and sample input/output as given below: 
  
 *Assumptions:* 
  
 * * 
 1. Each bucket used for measuring water should be unique in 
denomination and the number of buckets will be = 3 
2. The target amount to be reached has to finally reside in a 
single bucket (at the end of the measuring activity). 
3. The bucket capacities and target amount will be = 99 
4. If there are multiple ways to measure the same amount, only 
one way, having the minimum number of steps, has to be shown in 
  the output. 
If there are multiple minimum steps solutions present, displaying 
 one 
solution should be enough. 
5. The console input as well as the output should be in single 
line and in the format shown below. 
6. You can assume (not mandatory) minimum 2 steps will be 
required. You can ignore the cases where solution can be 
  achieved in single 
step. 
7. You can assume that maximum 10 steps will be required to 
 reach 
the target amount. If any solution requires more than 10 steps 
  to reach the 
target amount, you can stop the calculation and ignore that test 
 case. 
  
 *Input Format:* 
  
 The input will be of the following comma separated format – No. of 
 buckets, capacity of bucket 1, capacity of bucket 2, …, Target amount 
 desired. The following examples will provide more clarity 
  
 *Sl. No.* 
 *Input string* 
 *Explanation* 
 1 
 2,3,5,4 
 Implies that there are 2 buckets of capacity 3 and 5 lts each and the 
target amount desired is 4 lts. 
 2 
 3,4,6,9,7 
 Implies that there are 3 buckets of capacity 4, 6 and 9 lts each and 
 the 
target amount desired is 7 lts. 
  
 . 
  
 *Output Format:* 
  
 Each step should be a 11 bytes field left aligned  right padded with 
 spaces along with the right boundary as “|”. Together “|” character 
 the 
 length should be 12 characters. The following examples will provide 
 more 
 clarity 
  
 *Sl. No.* 
 *Input string* 
 *Expected Output String* 
 1 
 2,3,5,4 
 Fill 2 |Move 2 to 1|Empty 1|Move 2 to 1|Fill 2 |Move 2 to 
 1| 
 2 
 3,4,6,9,7 
 Fill 1 |Move 1 to 2|Fill 3 |Move 3 to 2| 
  
 * * 
  
 *Let’s explain 1**st**  output sample in more detail*: As explained 
 earlier, effectively the input 2,3,5,4 means there are 2 buckets of 
 capacity 3 liter and 5 liter and using these two buckets we have to 
 measure 
 4 liter (which is the target). 
  
The answer is: Fill 2 |Move 2 to 1|Empty 1|Move 2 to 
 1|Fill 
2 |Move 2 to 1| 
  
Let’s explain the answer also for test case 1: 
  
 *Step #* 
 *Step Description* 
 *Status  of 3 liter bucket (Bucket 1)* 
 *Status  of 5 liter bucket (Bucket 2)* 
 *Explanation* 
 Step 1 
 Fill

Re: [algogeeks] Given an array A[1..n] of log n bit integers, sort them in-place in O(n) time

2012-04-04 Thread Doom
how are you going to do it in-place?

On Wednesday, 4 April 2012 13:24:01 UTC+5:30, Siddhartha wrote:

 if the length of the binary representation of elements is logn, then the 
 elements themselves are of size less than 2^log(n)=n.
 as all the elements are less than n, use counting sort!!!


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/glXPUeyoh8IJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Find the maximum boxes which can fit each other?

2012-04-03 Thread Doom
What is wrong with atul's solution of longest decreasing subsequece on 
length after sorting on area? I think the relationship is transitive as 
well.
e.g. box a fits inside b.
box b fits inside c
by transitivity, box a fits inside c.

Isn't this fine?

On Saturday, 24 March 2012 22:25:33 UTC+5:30, Don wrote:

 There is more to it than a longest increasing subsequence because the 
 greater than relationship is not transitive. 
 Don 

 On Mar 24, 3:05 am, atul anand atul.87fri...@gmail.com wrote: 
  ok you need to put box into a box... 
  so first requirnment willl be to sort on the basis of area of box. 
  after this bcoz you are adding one box into another...the box you are 
  putting inside big box ..shud have base length less than a big box or it 
  wont fit in...even if its area is smaller.. 
  now we reduced this problem of finding longest inc subsequence on the 
 basis 
  of base length. 
  On 24 Mar 2012 13:14, Ratan success.rata...@gmail.com wrote: 
  
  
  
   @atul can u plzz describe in detail the algo of modified subsequence 
   prob used here i m nt able to get it ... though tried a lot 
  
   On Sat, Mar 24, 2012 at 1:05 PM, atul anand atul.87fri...@gmail.com 
   wrote: 
it is modified longest increasing subsequence problem.. 
  
On 24 Mar 2012 12:26, Ratan success.rata...@gmail.com wrote: 
  
You are given a lot of cuboid boxes with different length, breadth 
 and 
height. You need to find the maximum subset which can fit into each 
other. 
For example: 
If Box A has LBH as 7 8 9 
If Box B has LBH as 5 6 8 
If Box C has LBH as 5 8 7 
If Box D has LBH as 4 4 4 
then answer is A,B,D 
  
A box can fit into another only and only if all dimensions of that 
 is 
less than the bigger box. Also Rotation of boxes is not possible... 
  
can ny1 suggest a good algo for this? 
  
-- 
-- 
Ratan | 3rd Year | Information Technology | NIT ALLAHABAD 
  
-- 
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, visit this group at 
   http://groups.google.com/group/algogeeks?hl=en. 
  
-- 
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, visit this group at 
   http://groups.google.com/group/algogeeks?hl=en. 
  
   -- 
   -- 
   Ratan | 3rd Year | Information Technology | NIT ALLAHABAD 
  
   -- 
   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, visit this group at 
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - 
  
  - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/a06lUGOcKvgJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Given an array A[1..n] of log n bit integers, sort them in-place in O(n) time

2012-04-03 Thread Doom
Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/aGzMcjTFcAYJ.
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.