[algogeeks] Sequence problem

2012-06-30 Thread Gaurav Popli
find the nth term for the sequence...
3, 8, 12, 17, 22, 28, 35

-- 
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.



Re: [algogeeks] expectation values..

2012-06-18 Thread Gaurav Popli
http://www.spoj.pl/problems/FAVDICE/

On Sun, Jun 17, 2012 at 8:43 PM, Doom duman...@gmail.com wrote:

 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_problemhttp://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-expectationhttp://www.codechef.com/wiki/tutorial-expectationbut
  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+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en 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.


-- 
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.



Re: [algogeeks] expectation values..

2012-06-17 Thread Gaurav Popli
got it ..thanks!!
and this was not asked in any interview as i know...i read this quesn from
SPOJ..

On Sun, Jun 17, 2012 at 12:13 AM, Amitesh Singh singh.amit...@gmail.comwrote:

 just curious to know if this question is asked in any interviews? Google
 interview?

 --
 Amitesh




 On Sun, Jun 17, 2012 at 12:09 AM, Amitesh Singh 
 singh.amit...@gmail.comwrote:

 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 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.



[algogeeks] expectation values..

2012-06-16 Thread Gaurav Popli
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.



Re: [algogeeks] Re: power func

2012-05-05 Thread Gaurav Popli
yeah you are right im talking abt that quesn only
i got the power part but how could i store that F(n)(the gcd) part
which is supposedly very large..?

On Fri, May 4, 2012 at 3:28 AM, shiv narayan narayan.shiv...@gmail.com wrote:
 it looks you are talking about unlock 1 or 2 on spoj, use your own
 recursive power  function and since result may be very large so at
 every stage take  mod.
 pow(a,b)
 {
 if(b==1)
 return a;
 else
 {
 if(b%2==0)
 return (pow(a,b/2)%mod *pow(a,b/2)%mod) %mod
 else
 return pow(a,b/2)%mod *pow(a,b/2)%mod) %mod)*a)%mod)))  //check
 parenthesis
 }
 }

 On Apr 29, 7:20 pm, Gaurav Popli gpgaurav.n...@gmail.com wrote:
 givenn gcd of two integers a and b,..
 you hvae to find max value of a^b%mod where mod is also given...

 --
 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.



[algogeeks] power func

2012-04-29 Thread Gaurav Popli
givenn gcd of two integers a and b,..
you hvae to find max value of a^b%mod where mod is also given...

-- 
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.



[algogeeks] basic C

2012-04-06 Thread Gaurav Popli
http://www.spoj.pl/problems/HAJIME/
referring to this link
i came up with this soln

typedef/**/struct{unsigned/**/aku;char/**/*const/**/soku}zan;
typedef struct{unsigned(aku);char*const(soku)}zan;

need to know how to remove the space btw the second typedef and struct

-- 
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.



[algogeeks] pascal triangle

2012-03-24 Thread Gaurav Popli
calculate the number of values in the triangle that
are different from 1 and less than or equal to K.
k=2

1   

1   1   

1   2   1   

1   3   3   1   

1   4   6   4   
1   
1   5   10  10  5   
1   
1   6   15  20  15  
6   1

e.g
for k=2
ans is 1
and k=6
ans is 10

-- 
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.



[algogeeks] Array problem

2012-03-11 Thread Gaurav Popli
given an array of size n...
create an array of size n such that ai where ai is the element in the
new array at index location i is equal to sum of all elements in
original array which are smaller than element at posn i...

e.g
ar[]={3,5,1,6,7,8};

ar1[]={0,3,0,9,15,22};

-- 
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.



Re: [algogeeks] puzzle

2012-03-01 Thread Gaurav Popli
great observation
thanks!!

On Wed, Feb 29, 2012 at 10:31 PM, Anurag atri anu.anurag@gmail.com wrote:
 @shady:
 Observation only ..

 On Wed, Feb 29, 2012 at 9:03 PM, shady sinv...@gmail.com wrote:

 anurag how did you reach that solution ?
 can you elaborate...


 On Wed, Feb 29, 2012 at 8:11 PM, Anurag atri anu.anurag@gmail.com
 wrote:

 nth term : (n! + 2^n - n)


 On Wed, Feb 29, 2012 at 11:05 AM, Vaibhav Mittal
 vaibhavmitta...@gmail.com wrote:

 Ntn else is provided..??

 On Feb 28, 2012 12:51 PM, Gaurav Popli abeygau...@gmail.com wrote:

 Given a sequance of natural numbers.

 Find N'th term of this sequence.

 a1=2, a2=4, a3=11, a4=36, a5=147, a6=778 ... ... ... ... aN.


 this is a coding quesn and O(n) soln is also welcome...

 --
 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.




 --
 Regards
 Anurag Atri


 --
 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.




 --
 Regards
 Anurag Atri
 III year
 Computer Engineering
 Delhi College Of Engineering


 --
 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.



[algogeeks] puzzle

2012-02-27 Thread Gaurav Popli
Given a sequance of natural numbers.

Find N'th term of this sequence.

a1=2, a2=4, a3=11, a4=36, a5=147, a6=778 ... ... ... ... aN.


this is a coding quesn and O(n) soln is also welcome...

-- 
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.



Re: [algogeeks] Doubt

2011-08-04 Thread Gaurav Popli
actually the questn should go like this.wud that be good
/optimised with space because we can use more storages for a tree
without freeing them

On Thu, Aug 4, 2011 at 10:09 AM, rajeev bharshetty rajeevr...@gmail.com wrote:
 Since you are maintaining two different data structures ,one for the old
 tree and the other for new tree . I think this isn't considered in-place
 algorithm . The algorithm to be in-place should not use any additional data
 structures .
 Correct me if I am wrong .
 On Thu, Aug 4, 2011 at 2:52 AM, Gaurav Popli abeygau...@gmail.com wrote:

 good quesn.i also want to knowjust in case

 On Thu, Aug 4, 2011 at 2:50 AM, Anurag Narain anuragnar...@gmail.com
 wrote:
  suppose there is a binary tree and i am creating another tree which is
  same
  as the previous one.
  but while creating the new tree i am freeing the nodes of my old
  tree(i.e.,
  i create one node in new tree and delete the corresponding node in old
  tree
  and continue the process till the new tree is formed which is same as
  old
  tree but the old tree now does not exist)
 
 
  would this conversion be considered in-place??
 
  --
  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.




 --
 Regards
 Rajeev N B

 Winners Don't do Different things , they do things Differently

 --
 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.



Re: [algogeeks] Doubt

2011-08-03 Thread Gaurav Popli
good quesn.i also want to knowjust in case

On Thu, Aug 4, 2011 at 2:50 AM, Anurag Narain anuragnar...@gmail.com wrote:
 suppose there is a binary tree and i am creating another tree which is same
 as the previous one.
 but while creating the new tree i am freeing the nodes of my old tree(i.e.,
 i create one node in new tree and delete the corresponding node in old tree
 and continue the process till the new tree is formed which is same as old
 tree but the old tree now does not exist)


 would this conversion be considered in-place??

 --
 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.



Re: [algogeeks] atoi()

2011-07-23 Thread Gaurav Popli
and also ignore starting spaces if dr is any...

On Sun, Jul 24, 2011 at 12:55 AM, hary rathor harry.rat...@gmail.com wrote:
 int number=0;
 read linearly



 if(ch=='-'||ch=='+')
 number=-1;

 ch=str[i];
 chack every char is

 if(ch'0'ch'9') then
 number =number *10+ch-'0';


 --
 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.



Re: [algogeeks] Re: stacks

2011-07-23 Thread Gaurav Popli
it is given in tanenbaum

On Sat, Jul 23, 2011 at 9:49 PM, Pankaj jatka.oppimi...@gmail.com wrote:
 Can you please tell us from where we can find such questions?

 On Sat, Jul 23, 2011 at 4:21 PM, Nikhil Gupta nikhilgupta2...@gmail.com
 wrote:

 Nice question Kamakshi. The person above has given almost a perfect
 answer.
 For example i=3, we will pop the elements one by one from the top of the
 1st stack and pushed to the 2nd stack until the value (top - i) is reached.

 On Sat, Jul 23, 2011 at 3:52 PM, ross jagadish1...@gmail.com wrote:

 Well. the idea of an array is - given an integer 'i', you should
 support RANDOM ACCESS to the ith element in the 1d array.
 Since, we have two stacks, if you want to access an ith element ( say,
 i = 5 ),pop all the top 4 elements from the 1st stack and push it to
 the second stack.
 Now, access the 5th element on top of the 1st stack, then, pop the
 elements from the 2nd stack back and push them to the 1st stack.
 However, access is O(n) due to the inherent property of a stack which
 forbids random access!


 On Jul 23, 2:00 pm, Kamakshii Aggarwal kamakshi...@gmail.com wrote:
  consider a language that does no have arrays...but u can define stack
  data
  type like
  stack s;
  using pop ,push and other operations on  2 stacks,how can one
  dimensions
  array can be implemented??
 
  --
  Regards,
  Kamakshi
  kamakshi...@gmail.com

 --
 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.




 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India

 --
 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.


-- 
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.



Re: [algogeeks] Printf evaluation

2011-07-22 Thread Gaurav Popli
associativity rule is compiler dependent ...thats why undefined...

On Fri, Jul 22, 2011 at 5:46 PM, Kamakshii Aggarwal
kamakshi...@gmail.com wrote:
 undefined behaviour.
 since value of i is changing more than once between two sequence points..
 On Fri, Jul 22, 2011 at 5:42 PM, suresh srinivasan suree...@gmail.com
 wrote:

 Output:
 5,4,3,1

 Explanation:
 Since the brackets acts as right precedence, the execution of the
 statement is from right to left. The comma separates the individual.
 For i++, it prints the current 'i' value and increments it by 1.
 For ++i, it increments the value by 1 and prints the updated value of 'i'.
 --
 Regards,
 Suresh.S

 --
 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.



 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

 --
 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.



Re: [algogeeks] Printf evaluation

2011-07-22 Thread Gaurav Popli
may be im wrongbut i read it somewhere about it...the arguments of
a function are evaluated in a associativity that is compiler
dependent...

for ex...

printf(%d  %d  %d ,fun1(),fun2(),fun3());
the order in which functions are evaluated are compiler dependent

On Fri, Jul 22, 2011 at 7:20 PM, Abhinav Verma
abhinav.verma6...@gmail.com wrote:
 Its not the associativity which is undefined (Associativity has been defined
 clearly by the C Standards for each and every operator). Its the order of
 evaluation between 2 sequence points which is undefined and hence
 compiler-dependent.
 On gcc version 4.4.3, output generated is 5551. On some other compiler, the
 output may differ.

 On Fri, Jul 22, 2011 at 6:09 PM, Gaurav Popli abeygau...@gmail.com wrote:

 associativity rule is compiler dependent ...thats why undefined...

 On Fri, Jul 22, 2011 at 5:46 PM, Kamakshii Aggarwal
 kamakshi...@gmail.com wrote:
  undefined behaviour.
  since value of i is changing more than once between two sequence
  points..
  On Fri, Jul 22, 2011 at 5:42 PM, suresh srinivasan suree...@gmail.com
  wrote:
 
  Output:
  5,4,3,1
 
  Explanation:
  Since the brackets acts as right precedence, the execution of the
  statement is from right to left. The comma separates the individual.
  For i++, it prints the current 'i' value and increments it by 1.
  For ++i, it increments the value by 1 and prints the updated value of
  'i'.
  --
  Regards,
  Suresh.S
 
  --
  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.
 
 
 
  --
  Regards,
  Kamakshi
  kamakshi...@gmail.com
 
  --
  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.


 --
 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.



Re: [algogeeks] Coding..........

2011-07-22 Thread Gaurav Popli
an O(n) soln
traveres the array...as you receive odd number put that index in
queuewhen received an even numb check if queue is empty or
not...if queue is empty the do nothing else swap with the head of the
queue

hope it worksit also maintains the stability of aarray...

On Fri, Jul 22, 2011 at 6:39 PM, Kunal Patil kp101...@gmail.com wrote:
 @Sunny: Excellent explanation ( 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
 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.



Re: [algogeeks] Coding..........

2011-07-22 Thread Gaurav Popli
oh sorry for above soln...it will require many passes and hence inefficient...

On Fri, Jul 22, 2011 at 9:02 PM, Gaurav Popli abeygau...@gmail.com wrote:
 an O(n) soln
 traveres the array...as you receive odd number put that index in
 queuewhen received an even numb check if queue is empty or
 not...if queue is empty the do nothing else swap with the head of the
 queue

 hope it worksit also maintains the stability of aarray...

 On Fri, Jul 22, 2011 at 6:39 PM, Kunal Patil kp101...@gmail.com wrote:
 @Sunny: Excellent explanation ( 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
 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.



Re: [algogeeks] Interview Puzzle - 100 Prisoners and Caps

2011-07-22 Thread Gaurav Popli
or we cud make more easy for prisoners...instead of counting whether
even or notthe person at the back can say the color of the hat
which the prisoner in the immediate front is wearing.
by this atleast 50% prisoners will be relaesed/.
it will all depend on thr cooperation ;)

On Fri, Jul 22, 2011 at 11:25 PM, Vishal Jain jainv...@gmail.com wrote:
 I think Aditi's solution is correct. I was doing the same thing using XOR
 function... So basically I was saying to use XOR and interviewer was asking
 for something better... I could not find this solution...
 Thanks Aditi.
 Thanks  Regards
 Vishal Jain
 MNo: +91-9540611889
 Tweet @jainvis
 Blog @ jainvish.blogspot.com
 Success taste better when target achieved is bigger.

 P We have a responsibility to the environment.

 Before printing this e-mail or any other document, let's ask ourselves
 whether we need a hard copy.


 On Fri, Jul 22, 2011 at 10:19 PM, aditi garg aditi.garg.6...@gmail.com
 wrote:

 I think this can be answered like dis...
 let us say that the persons have decided amongst themselves that if the
 the number of people wearing white in front of dem is even he wud say white
 and if odd he wud say black
 Now suppose the 100th person counts the number of hats and finds it to be
 even... he wud say white...
 now the 99th person will do the same...if he still finds the number to be
 even and since the 100th person sed white(i.e even) he would say black...now
 if the 100th person had sed black (ie odd white) and the count comes out to
 be even thus 99 wud be wearing a white hat...
 Now that 98th person knows dat 99 had sed the correct hat and using the
 same method can say the correct hat color...thus all can be saved except the
 100th prisoner...
 Also note dat the 100th prisoner also has a 50% chance to survive...
 Hope dis helps :)

 On Fri, Jul 22, 2011 at 10:05 PM, Shubham Maheshwari
 shubham@gmail.com wrote:

 could some1 plz post the xplainations ...

 On Fri, Jul 22, 2011 at 8:04 PM, Pankaj jatka.oppimi...@gmail.com
 wrote:

 Chetan,
 No. How could you relate this problem with that? Do you find something
 similar?
 ~
 Pankaj

 On Fri, Jul 22, 2011 at 8:01 PM, chetan kapoor
 chetankapoor...@gmail.com wrote:

 josehus problem???

 On Fri, Jul 22, 2011 at 7:57 PM, Pankaj jatka.oppimi...@gmail.com
 wrote:

 Skipp Riddle,
 Yes.
 100th prisoner will risk his life. Similar puzzle was discuss
 recently. Does anyone remember the name or thread?

 ~
 Pankaj

 On Fri, Jul 22, 2011 at 7:55 PM, SkRiPt KiDdIe
 anuragmsi...@gmail.com wrote:

 Worst case 99 get released.
 Is that correct..?

 --
 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.

 --
 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.

 --
 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.



 --
 Aditi Garg
 Undergraduate Student
 Electronics  Communication Divison
 NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
 Sector 3, Dwarka
 New Delhi
 9718388816

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

Re: [algogeeks] Interview Puzzle - 100 Prisoners and Caps

2011-07-22 Thread Gaurav Popli
oh sorry...i didnt see.yeah..you are rightthanks..

On Sat, Jul 23, 2011 at 1:06 AM, sunny agrawal sunny816.i...@gmail.com wrote:
 But that will save only 50% of the prisoners...as compare to 99.5% in
 that of even Odd case
 Read that post carefully

 On Sat, Jul 23, 2011 at 1:04 AM, Gaurav Popli abeygau...@gmail.com wrote:

 or we cud make more easy for prisoners...instead of counting whether
 even or notthe person at the back can say the color of the hat
 which the prisoner in the immediate front is wearing.
 by this atleast 50% prisoners will be relaesed/.
 it will all depend on thr cooperation ;)

 On Fri, Jul 22, 2011 at 11:25 PM, Vishal Jain jainv...@gmail.com wrote:
  I think Aditi's solution is correct. I was doing the same thing using
  XOR
  function... So basically I was saying to use XOR and interviewer was
  asking
  for something better... I could not find this solution...
  Thanks Aditi.
  Thanks  Regards
  Vishal Jain
  MNo: +91-9540611889
  Tweet @jainvis
  Blog @ jainvish.blogspot.com
  Success taste better when target achieved is bigger.
 
  P We have a responsibility to the environment.
 
  Before printing this e-mail or any other document, let's ask ourselves
  whether we need a hard copy.
 
 
  On Fri, Jul 22, 2011 at 10:19 PM, aditi garg aditi.garg.6...@gmail.com
  wrote:
 
  I think this can be answered like dis...
  let us say that the persons have decided amongst themselves that if the
  the number of people wearing white in front of dem is even he wud say
  white
  and if odd he wud say black
  Now suppose the 100th person counts the number of hats and finds it to
  be
  even... he wud say white...
  now the 99th person will do the same...if he still finds the number to
  be
  even and since the 100th person sed white(i.e even) he would say
  black...now
  if the 100th person had sed black (ie odd white) and the count comes
  out to
  be even thus 99 wud be wearing a white hat...
  Now that 98th person knows dat 99 had sed the correct hat and using the
  same method can say the correct hat color...thus all can be saved
  except the
  100th prisoner...
  Also note dat the 100th prisoner also has a 50% chance to survive...
  Hope dis helps :)
 
  On Fri, Jul 22, 2011 at 10:05 PM, Shubham Maheshwari
  shubham@gmail.com wrote:
 
  could some1 plz post the xplainations ...
 
  On Fri, Jul 22, 2011 at 8:04 PM, Pankaj jatka.oppimi...@gmail.com
  wrote:
 
  Chetan,
  No. How could you relate this problem with that? Do you find
  something
  similar?
  ~
  Pankaj
 
  On Fri, Jul 22, 2011 at 8:01 PM, chetan kapoor
  chetankapoor...@gmail.com wrote:
 
  josehus problem???
 
  On Fri, Jul 22, 2011 at 7:57 PM, Pankaj jatka.oppimi...@gmail.com
  wrote:
 
  Skipp Riddle,
  Yes.
  100th prisoner will risk his life. Similar puzzle was discuss
  recently. Does anyone remember the name or thread?
 
  ~
  Pankaj
 
  On Fri, Jul 22, 2011 at 7:55 PM, SkRiPt KiDdIe
  anuragmsi...@gmail.com wrote:
 
  Worst case 99 get released.
  Is that correct..?
 
  --
  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.
 
  --
  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.
 
  --
  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.
 
 
 
  --
  Aditi Garg
  Undergraduate Student
  Electronics  Communication Divison
  NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
  Sector 3, Dwarka
  New Delhi
  9718388816
 
  --
  You

Re: [algogeeks] C - pre post increment

2011-07-21 Thread Gaurav Popli
dont you think it is illegal using x=x-- or x=--x;??

On Thu, Jul 21, 2011 at 2:56 PM, karthiga m karthichandr...@gmail.com wrote:
 in code  A using pr e- decrement  therefore i gets decremented when
 checking while condition so
 it will print as 9 8 7  6 5 4 3 2 1 .
 in code B using post-decrement  it will prints like 9 8 7 6 5 4 3 2 1 0
 here why zero printing means while checking while condition x-- have
 previous value..therefore at tht time x-- is 1 so while condition
 executing and prints x value as zero.

 On 7/21/11, Reynald reynaldsus...@gmail.com wrote:
 Code: A
 int main()
 {
     int x = 10;
     while ( x = --x)
     printf(  %d , x);
     getchar();
 }

 Code: B
 int main()
 {
     int x = 10;
     while ( x = x--)
     printf(  %d , x);
     getchar();
 }

 Does Code-A and Code-B work similar? Justify.

 --
 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.



-- 
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.



Re: [algogeeks] Re: Ever growing sorted linked list

2011-07-20 Thread Gaurav Popli
i want to ask one thing...the way some are saying first check with 2
then 4 and then 16to reach at that place we are suppose to
traverse it and also hav eto put a condition say like countn or
something...in this case also we are comparing so whats the
usecorrect me if im wrong.

On Wed, Jul 20, 2011 at 6:58 PM, bittu shashank7andr...@gmail.com wrote:
 can be done in O(n) find tow nodes from starting position find two
 nodes p,q such that p  k  k  q as linked list is sorted we have to
 keep going on in right direction complexity will no less then O(N) as
 its linked list there is no notion of binary search sorted linked list
 think out why ?

 only think we can apply some logic to reduce the comparisons that's i
 also think will be gr8 improvement but approach sounds good if start
 comparing the nodes value using multiple of 2 fact .e.g. take an
 integer i=2^j  from j=0 to start comparing 2^0th node, 2^1th node,
 2^2th node2^jth node might be we are able to reduce the number of
 comparisons

 do notify me via gmail if i am wrong if u find difficulty in TC ? else
 happy learning

 if this would have been sorted array then we could have been solved it
 O(logn) suing same approach.


 Thanks
 Shashank Mani
 Computer Science
 Birla Institute of Technology, Mesra

 --
 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.



Re: [algogeeks] Re: Microsoft

2011-07-20 Thread Gaurav Popli
is it given that string alphabets wud be in alphabetical order...??

On Thu, Jul 21, 2011 at 12:04 AM, Kamakshii Aggarwal
kamakshi...@gmail.com wrote:
 first count the no of elements to be printed say it is 'n'.
 now start from n-1 and start expanding the array from right to left..

 On Wed, Jul 20, 2011 at 10:56 PM, surender sanke surend...@gmail.com
 wrote:

 try from back end

 surender

 On Wed, Jul 20, 2011 at 9:54 PM, Soumya Prasad Ukil
 ukil.sou...@gmail.com wrote:

 Two passes over the original array is required.

 On 20 July 2011 08:10, SAMMM somnath.nit...@gmail.com wrote:

 You can do it using stack concept:--

 Pop the element from the end , taking two variable index1, index2 and
 Ch(character to Iterate)

 Eg:-  a1b4  here index1=4 , Ch='b', index2=1;

 Start filling the element of Ch from the extreme end of the array ..
 From right hand side .

 The array will look like this :-

 a b b b b

 In next iteration : Index1=index2,ch=a, index= no value( Underflow)

 repeat the same process giving:-

 a b b b b. (soln).


 Add element at the end .. Like character 'b' is added from the Right
 hand end of the array .


 If any bug in my approach ... comments me ...


 --
 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.




 --
 regards,
 soumya prasad ukil

 --
 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.



 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

 --
 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.



Re: [algogeeks] Ever growing sorted linked list

2011-07-18 Thread Gaurav Popli
i dont understand it..if k is at position an let supposeso to
check at that position dont you have to traverse till that position
...is thr anything else than the head of list...??or i understood
wrongly...??

On Mon, Jul 18, 2011 at 9:55 PM, sagar pareek sagarpar...@gmail.com wrote:
 Update on 2nd line

 2.    if( ptr2=ptr1-next-next...(5 or 10 times) ) goto 3.       else
 make linear search till NULL encounter and exit with the solution

 On Mon, Jul 18, 2011 at 7:41 PM, sagar pareek sagarpar...@gmail.com wrote:

 i have one approach :-

 first compare root-data  and k
 if k is very much greater than root-data then set next=5or10 ur choice

 else set next 2or3  ur choice
 take two pointers ptr1 and ptr2

 now lets take k is much greater than root-data
 then
 1. set ptr1=root //initially
 2. if( ptr2=ptr1-next-next...(5 or 10 times) ) else make linear
 search till NULL encounter
 3. if ptr2-data==k return its position
 4. else if (ptr2-datak) set ptr1=ptr2 goto 2
 5. else traverse the ptr1 upto ptr2, if found return its position else
 return fail

 if anyone has more efficient solution then pls tell  :)
 On Mon, Jul 18, 2011 at 6:53 PM, Dumanshu duman...@gmail.com wrote:

 You have a sorted linked list of integers of some length you don't
 know and it keeps on increasing. You are given a number k. Print the
 position of the number k.
 Basically, you have to search for number k in the ever growing sorted
 list and print its position.

 Please write the complexity of whatever solution you propose.

 --
 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.




 --
 Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD




 --
 Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 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.



Re: [algogeeks] Re: Ever growing sorted linked list

2011-07-18 Thread Gaurav Popli
yeah...im saying to reach position n at which k is placed we have to
trverse n positions from head or not...??
and i didnt understand the use of ever increasing...please elaborate on it..

On Tue, Jul 19, 2011 at 2:08 AM, Dumanshu duman...@gmail.com wrote:
 @Swathi: plz give the TC of ur algo (exponential plus log)

 On Jul 18, 10:14 pm, Swathi chukka.swa...@gmail.com wrote:
 The solution to this problem will be a combination of exponential increase
 and the binary search..

 start = 0;
 end = 0;
 index =0;
 middle = 0;
 while (1)
 {
   if(a[start] == data)
     return start;
   if(a[end] == data)
     return end;
   if(data  end)
   {
    start = end;
    end = pow(start,2); // here we are consider exponential for faster
 search.
    // no need to check any boundary conditions as the array is infinite
    continue;
   }
   else
   {
     // do binary search between start index and end index because data is
 inbetween a[start] and a[end]
   }

 }

 Hope this helps...

 On Mon, Jul 18, 2011 at 10:32 PM, Gaurav Popli 
 gpgaurav.n...@gmail.comwrote:



  i dont understand it..if k is at position an let supposeso to
  check at that position dont you have to traverse till that position
  ...is thr anything else than the head of list...??or i understood
  wrongly...??

  On Mon, Jul 18, 2011 at 9:55 PM, sagar pareek sagarpar...@gmail.com
  wrote:
   Update on 2nd line

   2.    if( ptr2=ptr1-next-next...(5 or 10 times) ) goto 3.
  else
   make linear search till NULL encounter and exit with the solution

   On Mon, Jul 18, 2011 at 7:41 PM, sagar pareek sagarpar...@gmail.com
  wrote:

   i have one approach :-

   first compare root-data  and k
   if k is very much greater than root-data then set next=5or10 ur choice

   else set next 2or3  ur choice
   take two pointers ptr1 and ptr2

   now lets take k is much greater than root-data
   then
   1. set ptr1=root //initially
   2. if( ptr2=ptr1-next-next...(5 or 10 times) ) else make linear
   search till NULL encounter
   3. if ptr2-data==k return its position
   4. else if (ptr2-datak) set ptr1=ptr2 goto 2
   5. else traverse the ptr1 upto ptr2, if found return its position else
   return fail

   if anyone has more efficient solution then pls tell  :)
   On Mon, Jul 18, 2011 at 6:53 PM, Dumanshu duman...@gmail.com wrote:

   You have a sorted linked list of integers of some length you don't
   know and it keeps on increasing. You are given a number k. Print the
   position of the number k.
   Basically, you have to search for number k in the ever growing sorted
   list and print its position.

   Please write the complexity of whatever solution you propose.

   --
   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.

   --
   Regards
   SAGAR PAREEK
   COMPUTER SCIENCE AND ENGINEERING
   NIT ALLAHABAD

   --
   Regards
   SAGAR PAREEK
   COMPUTER SCIENCE AND ENGINEERING
   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.- Hide quoted text -

 - Show quoted text -

 --
 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.



Re: [algogeeks] Re: MICROSOFT

2011-07-18 Thread Gaurav Popli
cant we just dotraverse using recursion and instead of printing it
just pass to function which is making BST??
and is this right as someone above said first sort it and then make BST...
dont we want that root of both Tree to be same or something like that...??


On Tue, Jul 19, 2011 at 2:17 AM, Dumanshu duman...@gmail.com wrote:
 @Balaji: for third question, were u asked to write the code?

 On Jul 18, 10:04 pm, Balaji S balaji.ceg...@gmail.com wrote:
 wats the mistake..

 --
 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.