[algogeeks] Re: C aps output

2011-05-20 Thread viswanath vellaiappan
Hello,
 I guess 
http://betterexplained.com/articles/understanding-big-and-little-endian-byte-order/
will help you to understand better. Basically the output will depend
on endianess of the system. I guess your machine were you ran this
program is little endiness machine. Let me know if you have any doubt.

~Viswanath.

On May 20, 8:19 pm, siva viknesh  wrote:
> main()
> {
> int i = 257;
> int *iPtr = &i;
> printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );}
>
> Answer:
> 1 1
>
> main()
> {
> int i = 258;
> int *iPtr = &i;
> printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );}
>
> Answer:
> 2 1
>
> ..can anybody explain how??
> --
> Regards,
> $iva

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

2011-05-20 Thread arjoo kumar
534 is the correct answer

On Fri, May 20, 2011 at 8:47 AM, Bhavesh agrawal wrote:

>
>
> 1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
> travel.
> total bananas are 3000 and distance have to travel from A to B is 1000km.
>
> So how many max bananas he can take from A to B.   (he'll eat in return
> travel  too)
>
> --
> 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] first fit bin packing

2011-05-20 Thread ankit sambyal
@MK: When we insert a value, we first delete that bin from the tree, then we
change the old root value and then we reinsert that bin into the tree.



On Sat, May 14, 2011 at 5:26 PM, MK  wrote:

> Not sure what you are suggesting. If you "bring to the root which has
> capacity to hold"  then it looks like you are disturbing the order of
> the bins.
>
> On Sat, May 14, 2011 at 1:34 PM, pacific :-) 
> wrote:
> > i think we can use heaps for this problem..bring to the root which has
> > capacity to hold and pick the root each time. If the root cannot
> accomodate
> > then no other node will be able to accomodate.
> >
> > On Sat, May 14, 2011 at 1:26 AM, MK  wrote:
> >>
> >> Consider the first fit strategy for online bin packing.
> >>
> >> So if you have N bins numbered 1, 2, 3..N and you are given value V,
> >> you scan them from left to right and insert V into the first bin that
> >> currently has enough capacity.
> >>
> >> In the naieve case, N insertions will take O(N^2) time.
> >>
> >> How can this be done in NlogN time?
> >>
> >> --
> >> 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,
> > chinna.
> >
> > --
> > 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] SPOJ problem: HASHIT

2011-05-20 Thread ankit sambyal
Hey guys , I am getting wrong answer in  :
http://www.spoj.pl/problems/HASHIT/.   Somebdy plz check it out or provide
some test cases. This code works fine with the test cases provided and even
my own test cases.

The following is my code:

#include
#include
int main()
{
int num_tcases,num_ops,i,j,k,l,n,x,m,y,count;
int occupied[101];
char table[101][16];
char temp[20],temp1[20];
scanf("%d",&num_tcases);

for(x=0;xhttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Print Subsets

2011-05-20 Thread immanuel kingston
I think your soln will print repetitions also.


On Mon, May 16, 2011 at 2:34 PM, Piyush Sinha wrote:

>
>
> *int ref[] = {2,3,6,7,8};*
> *void printcombination(int n,int index,int i)
> {
>  static int a[100];
>  int j;
>  if (n == 0)
>  {
>  for(j=0;j   printf("%d  ",a[j]);
>  printf("\n");
>  }
>  else if(n>0)
>  {
>  for(j=i;j<5;j++)
>  {
>  a[index]=ref[j];
>  printcombination(n-ref[j],index+1,j);
>  }
>  }
> }  *
> *main()
> {
> int n;
> printf("enter value of n :");
> scanf("%d",&n);
> printcombination(n,0,0);
> }
> *
> On Fri, May 13, 2011 at 2:40 AM, amit  wrote:
>
>> Given a set of numbers eg:{2,3,6,7,8} . any one who is playing the
>> game can score points only from this set using the numbers in that
>> set. given a number, print all the possible ways of scoring that many
>> points. Repetition of combinations are not allowed.
>>
>> eg:
>> 1. 6 points can be scored as
>> 6
>> 3+3
>> 2+2+2
>>
>> 2. 7 can be scored as
>> 7
>> 2+2+3
>> but 2+3+2 and 3+2+2 is not allowed as they are repetitions of 2+2+3
>>
>> --
>> 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.
>>
>>
>
>
> --
> PIYUSH SINHA
> IIIT, 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: sum of two

2011-05-20 Thread anuj agarwal
@Dave: He is talking of a better hash function. You did not mention the hash
function which you will use.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Sat, May 21, 2011 at 9:59 AM, Dave  wrote:

> @Apoorve: See my response at
> http://groups.google.com/group/algogeeks/msg/72419fb69ce97774.
>
> Dave
>
> On May 20, 10:05 am, Apoorve Mohan  wrote:
> > @dave: i think this can be handled using a good hash function(an onto
> > function). then the space complexity will also be O(n). What say???
> >
> >
> >
> >
> >
> > On Fri, May 20, 2011 at 8:31 PM, Dave  wrote:
> > > @Aakash: And tell me how map works. Is making an entry O(1) regardless
> > > of the value of the entry? For example, is it O(n) to map the sequence
> > > 1, 4, 9, 16, 25, ..., n^2?
> >
> > > Dave
> >
> > > On May 20, 9:39 am, Aakash Johari  wrote:
> > > > @Dave: I got you. I will have to check before pushing the element in
> map.
> >
> > > > On Fri, May 20, 2011 at 7:30 AM, Dave 
> wrote:
> > > > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > > > happens.
> >
> > > > > Dave
> >
> > > > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > > > int main()
> > > > > > {
> > > > > > int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > > > int i;
> > > > > > int sum;
> > > > > > int flag = 0;
> >
> > > > > > map m;
> >
> > > > > > for ( i = 0; i < 10; i++ ) {
> > > > > > m[a[i]] = 1;
> > > > > > }
> >
> > > > > > sum = 13;
> >
> > > > > > for ( i = 0; i < 10; i++ ) {
> > > > > > if ( m[sum - a[i]] == 1 ) {
> > > > > > flag = 1;
> > > > > > break;
> > > > > > }
> > > > > > }
> >
> > > > > > if ( flag == 1 )
> > > > > > cout << a[i] << " " << sum - a[i] << endl;
> >
> > > > > > return 0;
> >
> > > > > > }
> > > > > > On Fri, May 20, 2011 at 7:01 AM, hari 
> wrote:
> > > > > > > We can sort using STL sort function in main() before function
> call
> > > of
> > > > > > > arraysum().
> >
> > > > > > > On May 20, 6:49 am, Gunjan Sharma 
> > > wrote:
> > > > > > > > First of all there is an infinite loop in this code
> > > > > > > > Secondly it works only for sorted array.
> >
> > > > > > > > On Fri, May 20, 2011 at 7:16 PM, hari 
> > > wrote:
> > > > > > > > > In while loop have i,j which points first and last index of
> > > array.
> > > > > In
> > > > > > > > > while loop, Check the sum of a[i],a[j], If sum i or
> > > > > else
> > > > > > > > > decrement j. Run the while loop till i >
> > > > > > > > > CODE:
> >
> > > > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > > > while(i > > > > > > > > {
> > > > > > > > >  int p=0;
> > > > > > > > >  int b[10]; //to store index of selected nos
> > > > > > > > >  sum=a[i]+a[j];
> > > > > > > > >  if (sum==k)
> > > > > > > > >  {
> > > > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > > > >  }
> > > > > > > > >  elseif(sum > > > > > > > >  i++;
> > > > > > > > >  else(sum>k)
> > > > > > > > >  j++;
> > > > > > > > >  return b;
> > > > > > > > > }
> >
> > > > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > > > given an array of integers, and an integer k, find out
> two
> > > > > elements
> > > > > > > > > > from the array whose sum is k in O(n) time. if no such
> > > element
> > > > > exists
> > > > > > > > > > output none.
> >
> > > > > > > > > --
> > > > > > > > > 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
> > > > > > > > Gunjan Sharma
> > > > > > > > B.Tech IV year CSE
> >
> > > > > > > > Contact No- +91 9997767077
> >
> > > > > > > --
> > > > > > > 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.
> >
> > > > > > --
> > > > > > -Aakash Johari
> > > > > > (IIIT Allahabad)- 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

Re: [algogeeks] Re: nearest neighbour

2011-05-20 Thread immanuel kingston
@Dave:

Sorry my bad. Yes in that case, I cant think of a solution in O(n). I guess
your solution of sorting O(nlogn) is the best one in that case.

Thanks,
Immanuel

On Sat, May 21, 2011 at 2:20 AM, Dave  wrote:

> @Immanuel: It still looks like you are finding the nearest neighbors
> of only one point, while the problem was to find the neighbors of
> _each_ of the given points.
>
> Dave
>
> On May 20, 3:07 pm, immanuel kingston 
> wrote:
> > I guess a  solution exists.
> >
> > Have a maxHeap of k elements in our case its 3.
> >
> > Iterate through the array, compare the (difference between the position
> > along a number
> > line between ) and the top element of the maxHeap. It it happens to be
> > lesser than the top element, pop off the top element and push the current
> > element into the maxHeap. Proceeding till the end of the array we will be
> > getting the 3 friends of a given person.
> >
> > Hope I am not wrong.
> >
> > Thanks,
> > Immanuel
> >
> >
> >
> > On Thu, May 19, 2011 at 7:33 PM, Dave  wrote:
> > > @Sravanreddy001: You are to find _each_ person's friends. Can you do
> > > that in O(n)?
> >
> > > Dave
> >
> > > On May 19, 8:59 am, sravanreddy001  wrote:
> > > > Also, I think there is no need for sorting the number, its still okey
> if
> > > the
> > > > 3rd person is standing 1st and has the lowest number line value.
> >
> > > > And, finding the closest 3 number takes, 3*n time.. so.. its O(n)
> running
> > > > time..
> >
> > > > @Dave.. good catch.. :)
> >
> > > --
> > > 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: PUZZLE

2011-05-20 Thread anuj agarwal
@Dave: The problem statement says, the elephant can take 1000 at a time.
If he take max 1000, and eat 1 banana in each 1 km travel, he will be having
0 after 1000 Km.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Sat, May 21, 2011 at 9:57 AM, Dave  wrote:

> @Wladimir: According to the problem statement, the elephant starts out
> with 3,000 bananas. I am saying that the elephant can deliver 534
> bananas to the destination 1,000 km away.
>
> Dave
>
> On May 20, 7:22 pm, Wladimir Tavares  wrote:
> > with 534 , the elephant can travel only 534 Km! I am right?
> > Wladimir Araujo Tavares
> > *Federal University of Ceará
> >
> > *
> >
> >
> >
> > On Fri, May 20, 2011 at 8:36 PM, Dave  wrote:
> > > Upon reading the problem more carefully, the answer is 534 bananas,
> > > not 533-1/3.
> >
> > > Dave
> >
> > > On May 20, 3:43 pm, Dave  wrote:
> > > > @Bhavesh: 533-1/3.
> >
> > > > Dave
> >
> > > > On May 20, 10:47 am, Bhavesh agrawal  wrote:
> >
> > > > > 1 elephant can take 1000 banana at a time and eat 1 banana after
> each
> > > 1km
> > > > > travel.
> > > > > total bananas are 3000 and distance have to travel from A to B is
> > > 1000km.
> >
> > > > > So how many max bananas he can take from A to B.   (he'll eat in
> return
> > > > > travel  too)- 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.- 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.



[algogeeks] Re: sum of two

2011-05-20 Thread Dave
@Apoorve: See my response at 
http://groups.google.com/group/algogeeks/msg/72419fb69ce97774.

Dave

On May 20, 10:05 am, Apoorve Mohan  wrote:
> @dave: i think this can be handled using a good hash function(an onto
> function). then the space complexity will also be O(n). What say???
>
>
>
>
>
> On Fri, May 20, 2011 at 8:31 PM, Dave  wrote:
> > @Aakash: And tell me how map works. Is making an entry O(1) regardless
> > of the value of the entry? For example, is it O(n) to map the sequence
> > 1, 4, 9, 16, 25, ..., n^2?
>
> > Dave
>
> > On May 20, 9:39 am, Aakash Johari  wrote:
> > > @Dave: I got you. I will have to check before pushing the element in map.
>
> > > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > > happens.
>
> > > > Dave
>
> > > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > > int main()
> > > > > {
> > > > >         int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > >         int i;
> > > > >         int sum;
> > > > >         int flag = 0;
>
> > > > >         map m;
>
> > > > >         for ( i = 0; i < 10; i++ ) {
> > > > >                 m[a[i]] = 1;
> > > > >         }
>
> > > > >         sum = 13;
>
> > > > >         for ( i = 0; i < 10; i++ ) {
> > > > >                 if ( m[sum - a[i]] == 1 ) {
> > > > >                         flag = 1;
> > > > >                         break;
> > > > >                 }
> > > > >         }
>
> > > > >         if ( flag == 1 )
> > > > >                 cout << a[i] << " " << sum - a[i] << endl;
>
> > > > >         return 0;
>
> > > > > }
> > > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > > > We can sort using STL sort function in main() before function call
> > of
> > > > > > arraysum().
>
> > > > > > On May 20, 6:49 am, Gunjan Sharma 
> > wrote:
> > > > > > > First of all there is an infinite loop in this code
> > > > > > > Secondly it works only for sorted array.
>
> > > > > > > On Fri, May 20, 2011 at 7:16 PM, hari 
> > wrote:
> > > > > > > > In while loop have i,j which points first and last index of
> > array.
> > > > In
> > > > > > > > while loop, Check the sum of a[i],a[j], If sum > > > else
> > > > > > > > decrement j. Run the while loop till i
> > > > > > > > CODE:
>
> > > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > > while(i > > > > > > > {
> > > > > > > >  int p=0;
> > > > > > > >  int b[10];     //to store index of selected nos
> > > > > > > >  sum=a[i]+a[j];
> > > > > > > >  if (sum==k)
> > > > > > > >  {
> > > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > > >  }
> > > > > > > >  elseif(sum > > > > > > >  i++;
> > > > > > > >  else(sum>k)
> > > > > > > >  j++;
> > > > > > > >  return b;
> > > > > > > > }
>
> > > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > > given an array of integers, and an integer k, find out two
> > > > elements
> > > > > > > > > from the array whose sum is k in O(n) time. if no such
> > element
> > > > exists
> > > > > > > > > output none.
>
> > > > > > > > --
> > > > > > > > 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
> > > > > > > Gunjan Sharma
> > > > > > > B.Tech IV year CSE
>
> > > > > > > Contact No- +91 9997767077
>
> > > > > > --
> > > > > > 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.
>
> > > > > --
> > > > > -Aakash Johari
> > > > > (IIIT Allahabad)- 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.
>
> > > --
> > > -Aakash Johari
> > > (IIIT Allahabad)- 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...@googlegro

[algogeeks] Re: PUZZLE

2011-05-20 Thread Dave
@Wladimir: According to the problem statement, the elephant starts out
with 3,000 bananas. I am saying that the elephant can deliver 534
bananas to the destination 1,000 km away.

Dave

On May 20, 7:22 pm, Wladimir Tavares  wrote:
> with 534 , the elephant can travel only 534 Km! I am right?
> Wladimir Araujo Tavares
> *Federal University of Ceará
>
> *
>
>
>
> On Fri, May 20, 2011 at 8:36 PM, Dave  wrote:
> > Upon reading the problem more carefully, the answer is 534 bananas,
> > not 533-1/3.
>
> > Dave
>
> > On May 20, 3:43 pm, Dave  wrote:
> > > @Bhavesh: 533-1/3.
>
> > > Dave
>
> > > On May 20, 10:47 am, Bhavesh agrawal  wrote:
>
> > > > 1 elephant can take 1000 banana at a time and eat 1 banana after each
> > 1km
> > > > travel.
> > > > total bananas are 3000 and distance have to travel from A to B is
> > 1000km.
>
> > > > So how many max bananas he can take from A to B.   (he'll eat in return
> > > > travel  too)- 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.- 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.



Re: [algogeeks] C aps output

2011-05-20 Thread Alin Rus
On Fri, May 20, 2011 at 3:19 PM, siva viknesh  wrote:
>
> main()
> {
> int i = 257;
> int *iPtr = &i;
> printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
> }
> Answer:
> 1 1
>

i = 10001

first case *((char *)iPtr) cast to char 8 bits, discard first bit
0001  ==> 1
second *((char *)iPtr+1) cast to char 8bit address of pointer of type
char (8 bits) + 1 (next 8 bits) ==> 1


[ 0001]   [ 0001] = 257
*((char *)iPtr+1)*((char *)iPtr


>
> main()
> {
> int i = 258;
> int *iPtr = &i;
> printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
> }
> Answer:
> 2 1
>

same as above.

>
>
> ..can anybody explain how??
> --
> Regards,
> $iva
>
> --
> 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.
>



-- 
Alin Rus

-- 
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] Array problem

2011-05-20 Thread Anurag Bhatia
Just need some clarification; sorry I joined the thread late. What are we
trying maximize? A[j] -A[i] such that i wrote:

> @ Piyush: Excellent Solution...It appears both Correct and O(n)...Good work
> !![?]
>
> Just a minor correction in your algo.[?]
>
> * while(B[i] * j++;
> must also check for J's bound as:
> **while ( j < ( sizeof(A)/sizeof(A[0]) )* && *B[i]  j++;
> Or it will crash when J goes out of bound and we try to reference C[j].
>
> Nywayz..thnx for the solution and algo !!
> *
>
> --
> 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.

<<363.gif>><<360.gif>>

[algogeeks] c aps ..output discrepancy !!!

2011-05-20 Thread siva viknesh
hi

#include
main()
{
int a=2,*f1,*f2;
f1=f2=&a;
*f2+=*f2+=a+=2.5;
printf("\n%d %d %d",a,*f1,*f2);
}



for this code in code blocks IDE got 8 8 8 as op

 in http://ideone.com/ok850 got 12 12 12

   in 175 c aps pdf it has been given as 16 16 16 as
output 

so this code also has something to do with SEQUENCE POINTS 

is sequence points applicable for pointers too ??

the output varies based on compiler or underlying machine architecture

can anybody give clear picture about sequence points and whats happening in
this code...thanks in advance :)

-- 
Regards,
$iva

-- 
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: sum of two

2011-05-20 Thread Apoorve Mohan
@dave: i think this can be handled using a good hash function(an onto
function). then the space complexity will also be O(n). What say???

On Fri, May 20, 2011 at 8:31 PM, Dave  wrote:

> @Aakash: And tell me how map works. Is making an entry O(1) regardless
> of the value of the entry? For example, is it O(n) to map the sequence
> 1, 4, 9, 16, 25, ..., n^2?
>
> Dave
>
> On May 20, 9:39 am, Aakash Johari  wrote:
> > @Dave: I got you. I will have to check before pushing the element in map.
> >
> >
> >
> >
> >
> > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > happens.
> >
> > > Dave
> >
> > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > int main()
> > > > {
> > > > int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > int i;
> > > > int sum;
> > > > int flag = 0;
> >
> > > > map m;
> >
> > > > for ( i = 0; i < 10; i++ ) {
> > > > m[a[i]] = 1;
> > > > }
> >
> > > > sum = 13;
> >
> > > > for ( i = 0; i < 10; i++ ) {
> > > > if ( m[sum - a[i]] == 1 ) {
> > > > flag = 1;
> > > > break;
> > > > }
> > > > }
> >
> > > > if ( flag == 1 )
> > > > cout << a[i] << " " << sum - a[i] << endl;
> >
> > > > return 0;
> >
> > > > }
> > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > > We can sort using STL sort function in main() before function call
> of
> > > > > arraysum().
> >
> > > > > On May 20, 6:49 am, Gunjan Sharma 
> wrote:
> > > > > > First of all there is an infinite loop in this code
> > > > > > Secondly it works only for sorted array.
> >
> > > > > > On Fri, May 20, 2011 at 7:16 PM, hari 
> wrote:
> > > > > > > In while loop have i,j which points first and last index of
> array.
> > > In
> > > > > > > while loop, Check the sum of a[i],a[j], If sum > > else
> > > > > > > decrement j. Run the while loop till i >
> > > > > > > CODE:
> >
> > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > while(i > > > > > > {
> > > > > > >  int p=0;
> > > > > > >  int b[10]; //to store index of selected nos
> > > > > > >  sum=a[i]+a[j];
> > > > > > >  if (sum==k)
> > > > > > >  {
> > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > >  }
> > > > > > >  elseif(sum > > > > > >  i++;
> > > > > > >  else(sum>k)
> > > > > > >  j++;
> > > > > > >  return b;
> > > > > > > }
> >
> > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > given an array of integers, and an integer k, find out two
> > > elements
> > > > > > > > from the array whose sum is k in O(n) time. if no such
> element
> > > exists
> > > > > > > > output none.
> >
> > > > > > > --
> > > > > > > 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
> > > > > > Gunjan Sharma
> > > > > > B.Tech IV year CSE
> >
> > > > > > Contact No- +91 9997767077
> >
> > > > > --
> > > > > 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.
> >
> > > > --
> > > > -Aakash Johari
> > > > (IIIT Allahabad)- 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.
> >
> > --
> > -Aakash Johari
> > (IIIT Allahabad)- 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.
>
>


-- 
regards

Apoorve Mohan

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

Re: [algogeeks] GOOGLE Q

2011-05-20 Thread Ashim Kapoor
How will BFS give a rearrangement ?

-- 
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] first fit bin packing

2011-05-20 Thread MK
Not sure what you are suggesting. If you "bring to the root which has
capacity to hold"  then it looks like you are disturbing the order of
the bins.

On Sat, May 14, 2011 at 1:34 PM, pacific :-)  wrote:
> i think we can use heaps for this problem..bring to the root which has
> capacity to hold and pick the root each time. If the root cannot accomodate
> then no other node will be able to accomodate.
>
> On Sat, May 14, 2011 at 1:26 AM, MK  wrote:
>>
>> Consider the first fit strategy for online bin packing.
>>
>> So if you have N bins numbered 1, 2, 3..N and you are given value V,
>> you scan them from left to right and insert V into the first bin that
>> currently has enough capacity.
>>
>> In the naieve case, N insertions will take O(N^2) time.
>>
>> How can this be done in NlogN time?
>>
>> --
>> 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,
> chinna.
>
> --
> 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] PUZZLE

2011-05-20 Thread Apoorve Mohan
@piyush: how???

On Sat, May 21, 2011 at 12:19 AM, Piyush Sinha wrote:

> 500
>
> On 5/20/11, Bhavesh agrawal  wrote:
> > 1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
> > travel.
> > total bananas are 3000 and distance have to travel from A to B is 1000km.
> >
> > So how many max bananas he can take from A to B.   (he'll eat in return
> > travel  too)
> >
> > --
> > 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.
> >
> >
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926 *
>
> --
> 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

Apoorve Mohan

-- 
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] Array problem

2011-05-20 Thread Amit Jaspal
@ Above

I think your solution would not work for A[] = {9,6,3,2,8,1}

Ans is A[4]-A[1] > 0 i.e 4-1 = 3.

On Tue, May 17, 2011 at 9:57 PM, Kunal Patil  wrote:

> Ohh..If it is so...Sorry !![?]  I understood it the different way...[?]
> But if the question is as mentioned in your 2nd case then also I believe
> there is O(n) solution.[?]
>
> Maintain
> two pointers: *START* and *END*
> two variables: max1 and max2
> Assume arr[MAX_SIZE] to be the array containing the given elements.
>
> Algorithm:
> *1) Initially, make START point to zeroth element and END pointing to last
> element of the array.
> 2) Calculate max1 as:
> 2a) Compare arr[**START**] and arr[**END**].
>If arr[**START**] < arr[**END**]
>   {
>  max1 = **END** - **START**;
>  Jump to 3rd step
>   }
> 2b) If arr[**START**] >= arr[**END**]
>{
>  **END**-- ;
>  jump to step 2a and repeat this procedure till **
> END** != **START*
> *   }
> 3) Reset **END** so that it points to last element of the array.
> 4) Calculate max2 as:
> 4a) Compare arr[**START**] and arr[**END**].
>If arr[**START**] < arr[**END**]
>   {
>  max2 = **END** - **START**;
>  Jump to 5th step
>   }
> 4b) If arr**[START**] >= arr[**END**]
>{
> **START**++ ;
>  jump to step 4a and repeat this procedure till **
> START** != **END*
> *}
> 5) Return max( max1, max2)*
>
> Hope this algo is clear.
> This algo makes two passes over the array. Thus it is O(2n) = O(n)..[?]
> Let me know if this algo fails for any case you can think of..[?]
>
> --
> 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.
>



-- 
Amit Jaspal.

Men do less than they ought,
unless they do all they can

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

<<363.gif>><<361.gif>><<33D.gif>><<322.gif>><<360.gif>>

Re: [algogeeks] Re: Google Q

2011-05-20 Thread MK
On Sat, May 14, 2011 at 12:55 PM, pacific :-)  wrote:
> Will not a balanced binary tree do the job ? if we will pick the root each
> time for the median.
>

You cannot do it with a vanilla balanced binary tree.

But you can, if you use an augmented tree in the following sense - In
each node of the tree, store the number of nodes in the subtree rooted
at that node.
So , for eg,
- the root node will store N where N is the total number of nodes in the tree,
- number stored in left child of root + number stored in right child
of root = N - 1

Then, to find the element appearing at the N/2th position in an
inorder walk (i.e. the median) is given by Find(root, N/2) where Find
is defined like so -

Node* Find(Node* ptr, int position)
{
int ptrpos = ptr->left->numchildren + 1;
if(ptrpos == position) return ptr;
else if(ptrpos >position) return Find(ptr->left, position);
else return Find(ptr->right, position - ptrpos);
}



> On Sat, May 14, 2011 at 9:10 PM, Dave  wrote:
>>
>> @Ashish: The idea is to keep two heaps, a max-heap of the smallest
>> half of the elements and a min-heap of the largest elements. You
>> insert incoming elements into the appropriate heap. If the result is
>> that the number of elements in the two heaps differs by more than 1,
>> then you move the top element from the longer heap into the other one,
>> thereby equalzing the number of elements. Thus, inserting an element
>> is an O(log n) operation. To get the median, it is the top element of
>> the longer heap, or, if the heaps are of equal length, it is the
>> average of the two top elements. This is O(1).
>>
>> Dave
>>
>> On May 14, 8:34 am, Ashish Goel  wrote:
>> > not clear, can u elaborate..
>> >
>> > Best Regards
>> > Ashish Goel
>> > "Think positive and find fuel in failure"
>> > +919985813081
>> > +919966006652
>> >
>> > On Fri, May 13, 2011 at 7:15 PM, Bhavesh agrawal
>> > wrote:
>> >
>> >
>> >
>> > > This problem can be solved using 2 heaps and the median can always be
>> > > accessed in O(1) time ,the first node.
>> >
>> > > --
>> > > 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.
>>
>
>
>
> --
> regards,
> chinna.
>
> --
> 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] C aps output

2011-05-20 Thread siva viknesh
main()
{
int i = 257;
int *iPtr = &i;
printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}
Answer:
1 1


main()
{
int i = 258;
int *iPtr = &i;
printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}
Answer:
2 1



..can anybody explain how??
-- 
Regards,
$iva

-- 
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] number distribution algo

2011-05-20 Thread venkat kumar
Given a set of numbers,how to find whether it is uniformly distributed?

-- 
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: sum of two

2011-05-20 Thread Apoorve Mohan
1. use radix sort and sort the array.
2. take two pointers(say i and j). Point the first to head and the second to
the tail of the array. then check for a[i] + a[j]. If this sum is greater
the decrement the pointer j else if the sum is less than k increment the i
pointer.
If you get the sum equal to k then stop else move untill j > i.

I think this solution will have O(n) time complexity and O(n space
complexity).

On Fri, May 20, 2011 at 7:22 PM, Aakash Johari wrote:

> One possible solution is using maps. But i think that won't be in O(n)
>
>
> On Fri, May 20, 2011 at 6:49 AM, Gunjan Sharma 
> wrote:
>
>> First of all there is an infinite loop in this code
>> Secondly it works only for sorted array.
>>
>>
>> On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
>>
>>> In while loop have i,j which points first and last index of array. In
>>> while loop, Check the sum of a[i],a[j], If sum>> decrement j. Run the while loop till i>>
>>> CODE:
>>>
>>> int arraysum(int a[], int k, int i, int j)
>>> while(i>> {
>>>  int p=0;
>>>  int b[10]; //to store index of selected nos
>>>  sum=a[i]+a[j];
>>>  if (sum==k)
>>>  {
>>>  b[p++]=i;b[p++]=j;
>>>  }
>>>  elseif(sum>>  i++;
>>>  else(sum>k)
>>>  j++;
>>>  return b;
>>> }
>>>
>>> On May 20, 4:38 am, amit  wrote:
>>> > given an array of integers, and an integer k, find out two elements
>>> > from the array whose sum is k in O(n) time. if no such element exists
>>> > output none.
>>>
>>> --
>>> 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
>> Gunjan Sharma
>> B.Tech IV year CSE
>>
>>  Contact No- +91 9997767077
>>
>>  --
>> 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.
>>
>
>
>
> --
> -Aakash Johari
> (IIIT 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.
>



-- 
regards

Apoorve Mohan

-- 
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: sum of two

2011-05-20 Thread Wladimir Tavares
A good example of trade-off space-time!

Somebody know the Speedup theorem?
Wladimir Araujo Tavares
*Federal University of Ceará

*




On Fri, May 20, 2011 at 12:05 PM, Aakash Johari wrote:

> @Dave: This is what is still a doubt to me. I have searched but couldn't
> get the info regarding this.
>
>
> On Fri, May 20, 2011 at 8:01 AM, Dave  wrote:
>
>> @Aakash: And tell me how map works. Is making an entry O(1) regardless
>> of the value of the entry? For example, is it O(n) to map the sequence
>> 1, 4, 9, 16, 25, ..., n^2?
>>
>> Dave
>>
>> On May 20, 9:39 am, Aakash Johari  wrote:
>> > @Dave: I got you. I will have to check before pushing the element in
>> map.
>> >
>> >
>> >
>> >
>> >
>> > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
>> > > @Aakash: Yeah, but try the same array with sum = 6 and see what
>> > > happens.
>> >
>> > > Dave
>> >
>> > > On May 20, 9:04 am, Aakash Johari  wrote:
>> > > > int main()
>> > > > {
>> > > > int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
>> > > > int i;
>> > > > int sum;
>> > > > int flag = 0;
>> >
>> > > > map m;
>> >
>> > > > for ( i = 0; i < 10; i++ ) {
>> > > > m[a[i]] = 1;
>> > > > }
>> >
>> > > > sum = 13;
>> >
>> > > > for ( i = 0; i < 10; i++ ) {
>> > > > if ( m[sum - a[i]] == 1 ) {
>> > > > flag = 1;
>> > > > break;
>> > > > }
>> > > > }
>> >
>> > > > if ( flag == 1 )
>> > > > cout << a[i] << " " << sum - a[i] << endl;
>> >
>> > > > return 0;
>> >
>> > > > }
>> > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
>> > > > > We can sort using STL sort function in main() before function call
>> of
>> > > > > arraysum().
>> >
>> > > > > On May 20, 6:49 am, Gunjan Sharma 
>> wrote:
>> > > > > > First of all there is an infinite loop in this code
>> > > > > > Secondly it works only for sorted array.
>> >
>> > > > > > On Fri, May 20, 2011 at 7:16 PM, hari 
>> wrote:
>> > > > > > > In while loop have i,j which points first and last index of
>> array.
>> > > In
>> > > > > > > while loop, Check the sum of a[i],a[j], If sum> or
>> > > else
>> > > > > > > decrement j. Run the while loop till i> >
>> > > > > > > CODE:
>> >
>> > > > > > > int arraysum(int a[], int k, int i, int j)
>> > > > > > > while(i> > > > > > > {
>> > > > > > >  int p=0;
>> > > > > > >  int b[10]; //to store index of selected nos
>> > > > > > >  sum=a[i]+a[j];
>> > > > > > >  if (sum==k)
>> > > > > > >  {
>> > > > > > >  b[p++]=i;b[p++]=j;
>> > > > > > >  }
>> > > > > > >  elseif(sum> > > > > > >  i++;
>> > > > > > >  else(sum>k)
>> > > > > > >  j++;
>> > > > > > >  return b;
>> > > > > > > }
>> >
>> > > > > > > On May 20, 4:38 am, amit  wrote:
>> > > > > > > > given an array of integers, and an integer k, find out two
>> > > elements
>> > > > > > > > from the array whose sum is k in O(n) time. if no such
>> element
>> > > exists
>> > > > > > > > output none.
>> >
>> > > > > > > --
>> > > > > > > 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
>> > > > > > Gunjan Sharma
>> > > > > > B.Tech IV year CSE
>> >
>> > > > > > Contact No- +91 9997767077
>> >
>> > > > > --
>> > > > > 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.
>> >
>> > > > --
>> > > > -Aakash Johari
>> > > > (IIIT Allahabad)- 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.
>> >
>> > --
>> > -Aakash Johari
>> > (IIIT Allahabad)- 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 emai

Re: [algogeeks] Re: PUZZLE

2011-05-20 Thread Wladimir Tavares
with 534 , the elephant can travel only 534 Km! I am right?
Wladimir Araujo Tavares
*Federal University of Ceará

*




On Fri, May 20, 2011 at 8:36 PM, Dave  wrote:

> Upon reading the problem more carefully, the answer is 534 bananas,
> not 533-1/3.
>
> Dave
>
> On May 20, 3:43 pm, Dave  wrote:
> > @Bhavesh: 533-1/3.
> >
> > Dave
> >
> > On May 20, 10:47 am, Bhavesh agrawal  wrote:
> >
> >
> >
> > > 1 elephant can take 1000 banana at a time and eat 1 banana after each
> 1km
> > > travel.
> > > total bananas are 3000 and distance have to travel from A to B is
> 1000km.
> >
> > > So how many max bananas he can take from A to B.   (he'll eat in return
> > > travel  too)- 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] GOOGLE Q

2011-05-20 Thread Amit Jaspal
Use Product of Primes as Hash function , this would give no collision in
case of anagrams.

On Tue, May 17, 2011 at 9:53 PM, Anand  wrote:

> For any given word.
> - Find the lexicographic ordering and calculate it hash.
> - Find all permutation of the string
> - Check each permutation if it's a valid word
> -  if so store it at the same hash index.
>
>
>
> On Tue, May 17, 2011 at 7:16 AM, Ashish Goel  wrote:
>
>> hash..
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> On Tue, May 17, 2011 at 11:36 AM, Piyush Sinha 
>> wrote:
>>
>>> Given an English word in the form of a string, how can you quickly
>>> find all valid
>>> anagrams for that string (all valid rearrangements of the letters that
>>> form valid
>>> English words)?
>>> --
>>> *Piyush Sinha*
>>> *IIIT, Allahabad*
>>> *+91-8792136657*
>>> *+91-7483122727*
>>> *https://www.facebook.com/profile.php?id=10655377926 *
>>>
>>> --
>>> 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.
>



-- 
Amit Jaspal.

Men do less than they ought,
unless they do all they can

-- 
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] Array problem

2011-05-20 Thread Terence

Try this case:
1000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1

On 2011-5-18 0:27, Kunal Patil wrote:

Ohh..If it is so...Sorry !!  I understood it the different way...
But if the question is as mentioned in your 2nd case then also I 
believe there is O(n) solution.


Maintain
two pointers: *START* and *END*
two variables: max1 and max2
Assume arr[MAX_SIZE] to be the array containing the given elements.

Algorithm:
*1) Initially, make START point to zeroth element and END pointing to 
last element of the array.

2) Calculate max1 as:
2a) Compare arr[**START**] and arr[**END**].
   If arr[**START**] < arr[**END**]
  {
 max1 = **END**- **START**;
 Jump to 3rd step
  }
2b) If arr[**START**] >= arr[**END**]
   {
**END**-- ;
 jump to step 2a and repeat this procedure 
till **END**!= **START*

*   }
3) Reset **END**so that it points to last element of the array.
4) Calculate max2 as:
4a) Compare arr[**START**] and arr[**END**].
   If arr[**START**] < arr[**END**]
  {
 max2 = **END**- **START**;
 Jump to 5th step
  }
4b) If arr**[START**] >= arr[**END**]
   {
**START**++ ;
 jump to step 4a and repeat this procedure 
till **START**!= **END*

*   }
5) Return max( max1, max2)*

Hope this algo is clear.
This algo makes two passes over the array. Thus it is O(2n) = O(n)..
Let me know if this algo fails for any case you can think of..
--
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] Re: sum of two

2011-05-20 Thread SVIX
ah... u're right... dull moment... friday evening... not the first
dull moment today, i can assure u :)

On May 20, 4:39 pm, Dave  wrote:
> @SVIX: Yes, simple hasing will work. After processing the first 4
> numbers, the hash table contains 1, 2, 3, and 6. When you process the
> second 6, you search for 12 - 6 = 6 and find it. The two numbers in
> the array that sum to 12 are 6 and 6. What's the problem with that?
>
> Dave
>
> On May 20, 6:29 pm, SVIX  wrote:
>
>
>
>
>
>
>
> > @Dave... one more thought...
>
> > lets say the array is {1,2,3,6,6} (duplicate numbers) and u wanna
> > see if 2 numbers add up to 12 simple hashing wont work...
>
> > On May 20, 8:01 am, Dave  wrote:
>
> > > @Aakash: And tell me how map works. Is making an entry O(1) regardless
> > > of the value of the entry? For example, is it O(n) to map the sequence
> > > 1, 4, 9, 16, 25, ..., n^2?
>
> > > Dave
>
> > > On May 20, 9:39 am, Aakash Johari  wrote:
>
> > > > @Dave: I got you. I will have to check before pushing the element in 
> > > > map.
>
> > > > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > > > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > > > happens.
>
> > > > > Dave
>
> > > > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > > > int main()
> > > > > > {
> > > > > >         int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > > >         int i;
> > > > > >         int sum;
> > > > > >         int flag = 0;
>
> > > > > >         map m;
>
> > > > > >         for ( i = 0; i < 10; i++ ) {
> > > > > >                 m[a[i]] = 1;
> > > > > >         }
>
> > > > > >         sum = 13;
>
> > > > > >         for ( i = 0; i < 10; i++ ) {
> > > > > >                 if ( m[sum - a[i]] == 1 ) {
> > > > > >                         flag = 1;
> > > > > >                         break;
> > > > > >                 }
> > > > > >         }
>
> > > > > >         if ( flag == 1 )
> > > > > >                 cout << a[i] << " " << sum - a[i] << endl;
>
> > > > > >         return 0;
>
> > > > > > }
> > > > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > > > > We can sort using STL sort function in main() before function 
> > > > > > > call of
> > > > > > > arraysum().
>
> > > > > > > On May 20, 6:49 am, Gunjan Sharma  
> > > > > > > wrote:
> > > > > > > > First of all there is an infinite loop in this code
> > > > > > > > Secondly it works only for sorted array.
>
> > > > > > > > On Fri, May 20, 2011 at 7:16 PM, hari  
> > > > > > > > wrote:
> > > > > > > > > In while loop have i,j which points first and last index of 
> > > > > > > > > array.
> > > > > In
> > > > > > > > > while loop, Check the sum of a[i],a[j], If sum > > > > > > > > or
> > > > > else
> > > > > > > > > decrement j. Run the while loop till i
> > > > > > > > > CODE:
>
> > > > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > > > while(i > > > > > > > > {
> > > > > > > > >  int p=0;
> > > > > > > > >  int b[10];     //to store index of selected nos
> > > > > > > > >  sum=a[i]+a[j];
> > > > > > > > >  if (sum==k)
> > > > > > > > >  {
> > > > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > > > >  }
> > > > > > > > >  elseif(sum > > > > > > > >  i++;
> > > > > > > > >  else(sum>k)
> > > > > > > > >  j++;
> > > > > > > > >  return b;
> > > > > > > > > }
>
> > > > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > > > given an array of integers, and an integer k, find out two
> > > > > elements
> > > > > > > > > > from the array whose sum is k in O(n) time. if no such 
> > > > > > > > > > element
> > > > > exists
> > > > > > > > > > output none.
>
> > > > > > > > > --
> > > > > > > > > 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
> > > > > > > > Gunjan Sharma
> > > > > > > > B.Tech IV year CSE
>
> > > > > > > > Contact No- +91 9997767077
>
> > > > > > > --
> > > > > > > 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.
>
> > > > > > --
> > > > > > -Aakash Johari
> > > > > > (IIIT Allahabad)- Hide quoted text -
>
> > > > > > - Show quoted text -
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups
> > 

[algogeeks] Re: sum of two

2011-05-20 Thread Dave
@SVIX: Yes, simple hasing will work. After processing the first 4
numbers, the hash table contains 1, 2, 3, and 6. When you process the
second 6, you search for 12 - 6 = 6 and find it. The two numbers in
the array that sum to 12 are 6 and 6. What's the problem with that?

Dave

On May 20, 6:29 pm, SVIX  wrote:
> @Dave... one more thought...
>
> lets say the array is {1,2,3,6,6} (duplicate numbers) and u wanna
> see if 2 numbers add up to 12 simple hashing wont work...
>
> On May 20, 8:01 am, Dave  wrote:
>
>
>
> > @Aakash: And tell me how map works. Is making an entry O(1) regardless
> > of the value of the entry? For example, is it O(n) to map the sequence
> > 1, 4, 9, 16, 25, ..., n^2?
>
> > Dave
>
> > On May 20, 9:39 am, Aakash Johari  wrote:
>
> > > @Dave: I got you. I will have to check before pushing the element in map.
>
> > > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > > happens.
>
> > > > Dave
>
> > > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > > int main()
> > > > > {
> > > > >         int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > >         int i;
> > > > >         int sum;
> > > > >         int flag = 0;
>
> > > > >         map m;
>
> > > > >         for ( i = 0; i < 10; i++ ) {
> > > > >                 m[a[i]] = 1;
> > > > >         }
>
> > > > >         sum = 13;
>
> > > > >         for ( i = 0; i < 10; i++ ) {
> > > > >                 if ( m[sum - a[i]] == 1 ) {
> > > > >                         flag = 1;
> > > > >                         break;
> > > > >                 }
> > > > >         }
>
> > > > >         if ( flag == 1 )
> > > > >                 cout << a[i] << " " << sum - a[i] << endl;
>
> > > > >         return 0;
>
> > > > > }
> > > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > > > We can sort using STL sort function in main() before function call 
> > > > > > of
> > > > > > arraysum().
>
> > > > > > On May 20, 6:49 am, Gunjan Sharma  wrote:
> > > > > > > First of all there is an infinite loop in this code
> > > > > > > Secondly it works only for sorted array.
>
> > > > > > > On Fri, May 20, 2011 at 7:16 PM, hari  
> > > > > > > wrote:
> > > > > > > > In while loop have i,j which points first and last index of 
> > > > > > > > array.
> > > > In
> > > > > > > > while loop, Check the sum of a[i],a[j], If sum > > > else
> > > > > > > > decrement j. Run the while loop till i
> > > > > > > > CODE:
>
> > > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > > while(i > > > > > > > {
> > > > > > > >  int p=0;
> > > > > > > >  int b[10];     //to store index of selected nos
> > > > > > > >  sum=a[i]+a[j];
> > > > > > > >  if (sum==k)
> > > > > > > >  {
> > > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > > >  }
> > > > > > > >  elseif(sum > > > > > > >  i++;
> > > > > > > >  else(sum>k)
> > > > > > > >  j++;
> > > > > > > >  return b;
> > > > > > > > }
>
> > > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > > given an array of integers, and an integer k, find out two
> > > > elements
> > > > > > > > > from the array whose sum is k in O(n) time. if no such element
> > > > exists
> > > > > > > > > output none.
>
> > > > > > > > --
> > > > > > > > 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
> > > > > > > Gunjan Sharma
> > > > > > > B.Tech IV year CSE
>
> > > > > > > Contact No- +91 9997767077
>
> > > > > > --
> > > > > > 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.
>
> > > > > --
> > > > > -Aakash Johari
> > > > > (IIIT Allahabad)- 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.
>
> > > --
> > > -Aakash Johari
> > > (IIIT Allahabad)- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--

[algogeeks] Re: PUZZLE

2011-05-20 Thread Dave
Upon reading the problem more carefully, the answer is 534 bananas,
not 533-1/3.

Dave

On May 20, 3:43 pm, Dave  wrote:
> @Bhavesh: 533-1/3.
>
> Dave
>
> On May 20, 10:47 am, Bhavesh agrawal  wrote:
>
>
>
> > 1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
> > travel.
> > total bananas are 3000 and distance have to travel from A to B is 1000km.
>
> > So how many max bananas he can take from A to B.   (he'll eat in return
> > travel  too)- 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.



[algogeeks] Re: sum of two

2011-05-20 Thread SVIX
@Dave... one more thought...

lets say the array is {1,2,3,6,6} (duplicate numbers) and u wanna
see if 2 numbers add up to 12 simple hashing wont work...

On May 20, 8:01 am, Dave  wrote:
> @Aakash: And tell me how map works. Is making an entry O(1) regardless
> of the value of the entry? For example, is it O(n) to map the sequence
> 1, 4, 9, 16, 25, ..., n^2?
>
> Dave
>
> On May 20, 9:39 am, Aakash Johari  wrote:
>
>
>
>
>
>
>
> > @Dave: I got you. I will have to check before pushing the element in map.
>
> > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > happens.
>
> > > Dave
>
> > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > int main()
> > > > {
> > > >         int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > >         int i;
> > > >         int sum;
> > > >         int flag = 0;
>
> > > >         map m;
>
> > > >         for ( i = 0; i < 10; i++ ) {
> > > >                 m[a[i]] = 1;
> > > >         }
>
> > > >         sum = 13;
>
> > > >         for ( i = 0; i < 10; i++ ) {
> > > >                 if ( m[sum - a[i]] == 1 ) {
> > > >                         flag = 1;
> > > >                         break;
> > > >                 }
> > > >         }
>
> > > >         if ( flag == 1 )
> > > >                 cout << a[i] << " " << sum - a[i] << endl;
>
> > > >         return 0;
>
> > > > }
> > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > > We can sort using STL sort function in main() before function call of
> > > > > arraysum().
>
> > > > > On May 20, 6:49 am, Gunjan Sharma  wrote:
> > > > > > First of all there is an infinite loop in this code
> > > > > > Secondly it works only for sorted array.
>
> > > > > > On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > > > > > > In while loop have i,j which points first and last index of array.
> > > In
> > > > > > > while loop, Check the sum of a[i],a[j], If sum > > else
> > > > > > > decrement j. Run the while loop till i
> > > > > > > CODE:
>
> > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > while(i > > > > > > {
> > > > > > >  int p=0;
> > > > > > >  int b[10];     //to store index of selected nos
> > > > > > >  sum=a[i]+a[j];
> > > > > > >  if (sum==k)
> > > > > > >  {
> > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > >  }
> > > > > > >  elseif(sum > > > > > >  i++;
> > > > > > >  else(sum>k)
> > > > > > >  j++;
> > > > > > >  return b;
> > > > > > > }
>
> > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > given an array of integers, and an integer k, find out two
> > > elements
> > > > > > > > from the array whose sum is k in O(n) time. if no such element
> > > exists
> > > > > > > > output none.
>
> > > > > > > --
> > > > > > > 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
> > > > > > Gunjan Sharma
> > > > > > B.Tech IV year CSE
>
> > > > > > Contact No- +91 9997767077
>
> > > > > --
> > > > > 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.
>
> > > > --
> > > > -Aakash Johari
> > > > (IIIT Allahabad)- 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.
>
> > --
> > -Aakash Johari
> > (IIIT Allahabad)- 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.



[algogeeks] Good opportunity for Salesforce.com Developer in Columbus, OH

2011-05-20 Thread sohail panzer
Dear Professional,
Hope you are doing well.
I am a technical recruiter with Panzer Solutions LLC Software Implementing
and IT consulting company located in CT. Please go through the Job
Description and send me your updated resume with contact information.

*Please reply at soh...@panzersolutions.com*

Title  :   Salesforce.com Developer
Location   :   Columbus, OH
Duration  :   2 years contract
MUST ME A US CITIZEN OR EAD OR GREENCARD HOLDER.


Requirements
Seasoned Developer with:
1+ years experience as with Salesforce.com Development, Architecture, Design
and Support
Good Personality
Visualforce
Apex

Plusses
Certs/Degree

Responsibilities
This position requires the ability to lead the design, architecture,
development and going support for the SalesForce.com CRM solution. The
candidate must have hands on experience with SalesForce.com. Ability to
mentor technical team members on the process and deliver excellent
presentation, technical design, and architecture documentation. Work with
business representatives, business analysts to quickly understand
requirements. Evaluate, select, implement, and integrate technology tools
into a client solution. .



Thank you,

Sohail Khan | Technical Recruiter
Panzer Solutions LLc
45 Stuart Ave, K
Norwalk, CT 06850 USA
Voice: 203-813-2052
soh...@panzersolutions.com
URL: www.panzersolutions.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.



[algogeeks] Re: sum of two

2011-05-20 Thread SVIX
@Dave.. never mind... i understood what u meant...

On May 20, 4:18 pm, SVIX  wrote:
> @ I didn't get that... could u please elaborate a little more?
>
> for each integer, search for something sounds like O(n^2)
>
> On May 20, 7:26 am, Dave  wrote:
>
>
>
>
>
>
>
> > @Amit: Use a hash table. For each integer x[i] in the array, search
> > for k - x[i]. If found, x[i] and k - x[i] are your pair of integers.
> > Otherwise, add x[i] to the hash table and advance the loop. Output
> > "none" if you get to the end of the array without a hit.
>
> > Dave
>
> > On May 20, 6:38 am, amit  wrote:
>
> > > given an array of integers, and an integer k, find out two elements
> > > from the array whose sum is k in O(n) time. if no such element exists
> > > output none.

-- 
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] Re: sum of two

2011-05-20 Thread SVIX
@ I didn't get that... could u please elaborate a little more?

for each integer, search for something sounds like O(n^2)

On May 20, 7:26 am, Dave  wrote:
> @Amit: Use a hash table. For each integer x[i] in the array, search
> for k - x[i]. If found, x[i] and k - x[i] are your pair of integers.
> Otherwise, add x[i] to the hash table and advance the loop. Output
> "none" if you get to the end of the array without a hit.
>
> Dave
>
> On May 20, 6:38 am, amit  wrote:
>
>
>
>
>
>
>
> > given an array of integers, and an integer k, find out two elements
> > from the array whose sum is k in O(n) time. if no such element exists
> > output none.

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

2011-05-20 Thread amit kumar
533

On Sat, May 21, 2011 at 2:13 AM, Dave  wrote:

> @Bhavesh: 533-1/3.
>
> Dave
>
> On May 20, 10:47 am, Bhavesh agrawal  wrote:
> > 1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
> > travel.
> > total bananas are 3000 and distance have to travel from A to B is 1000km.
> >
> > So how many max bananas he can take from A to B.   (he'll eat in return
> > travel  too)
>
> --
> 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] Re: nearest neighbour

2011-05-20 Thread Dave
@Immanuel: It still looks like you are finding the nearest neighbors
of only one point, while the problem was to find the neighbors of
_each_ of the given points.

Dave

On May 20, 3:07 pm, immanuel kingston 
wrote:
> I guess a  solution exists.
>
> Have a maxHeap of k elements in our case its 3.
>
> Iterate through the array, compare the (difference between the position
> along a number
> line between ) and the top element of the maxHeap. It it happens to be
> lesser than the top element, pop off the top element and push the current
> element into the maxHeap. Proceeding till the end of the array we will be
> getting the 3 friends of a given person.
>
> Hope I am not wrong.
>
> Thanks,
> Immanuel
>
>
>
> On Thu, May 19, 2011 at 7:33 PM, Dave  wrote:
> > @Sravanreddy001: You are to find _each_ person's friends. Can you do
> > that in O(n)?
>
> > Dave
>
> > On May 19, 8:59 am, sravanreddy001  wrote:
> > > Also, I think there is no need for sorting the number, its still okey if
> > the
> > > 3rd person is standing 1st and has the lowest number line value.
>
> > > And, finding the closest 3 number takes, 3*n time.. so.. its O(n) running
> > > time..
>
> > > @Dave.. good catch.. :)
>
> > --
> > 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.



[algogeeks] Re: PUZZLE

2011-05-20 Thread Dave
@Bhavesh: 533-1/3.

Dave

On May 20, 10:47 am, Bhavesh agrawal  wrote:
> 1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
> travel.
> total bananas are 3000 and distance have to travel from A to B is 1000km.
>
> So how many max bananas he can take from A to B.   (he'll eat in return
> travel  too)

-- 
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: how to find a smallest prime bigger than a given number

2011-05-20 Thread immanuel kingston
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes


On Thu, May 19, 2011 at 1:47 AM, Don  wrote:

> Yes. Use a sieve.
> Don
>
> On May 17, 11:36 pm, wujin chen  wrote:
> > @Dave, thanks for your reply.
> > i know that, i can only check  from 6*n - 1 and 6*n + 1..
> > assume that, n=1 , and  we begin from k=1667, the number needed to
> check
> > is 10001,10003
> > but to determin 10001 is prime or not costs a lot, right?
> > when the n is huge, it will be not feasible.
> >
> > is there some math principle to solve this problem easily?
> >
> > 2011/5/18 Dave 
> >
> > > @Wujin: Well, obviously, you don't have to check _every_ number one-by-
> > > one. If n > 1, you can ignore every even number. Furthermore, if n >
> > > 3, you can ignore every odd multiple of 3. That means that you need to
> > > check only numbers of the form 6*n - 1 and 6*n + 1.
> >
> > > Dave
> >
> > > On May 17, 9:09 pm, wujin chen  wrote:
> > > > given a number n, compute the smallest prime that is bigger than n.
> > > > for example, n=8, then the smallest prime that bigger than 8 is 11.
> >
> > > > i wonder whether there is an effective way, rather than check every
> > > number
> > > > bigger than n one by one.
> >
> > > > thanks.
> >
> > > --
> > > 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: nearest neighbour

2011-05-20 Thread immanuel kingston
I guess a  solution exists.

Have a maxHeap of k elements in our case its 3.

Iterate through the array, compare the (difference between the position
along a number
line between ) and the top element of the maxHeap. It it happens to be
lesser than the top element, pop off the top element and push the current
element into the maxHeap. Proceeding till the end of the array we will be
getting the 3 friends of a given person.

Hope I am not wrong.

Thanks,
Immanuel

On Thu, May 19, 2011 at 7:33 PM, Dave  wrote:

> @Sravanreddy001: You are to find _each_ person's friends. Can you do
> that in O(n)?
>
> Dave
>
> On May 19, 8:59 am, sravanreddy001  wrote:
> > Also, I think there is no need for sorting the number, its still okey if
> the
> > 3rd person is standing 1st and has the lowest number line value.
> >
> > And, finding the closest 3 number takes, 3*n time.. so.. its O(n) running
> > time..
> >
> > @Dave.. good catch.. :)
>
> --
> 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: GOOGLE Q

2011-05-20 Thread immanuel kingston
Preprocess the Dictionary into a hash table where the key is the sorted
string of each word and the value being the A list that contains that
particular word.(O(nlogn * linked list insertion time some k)  )

Now for each given word, sort it(O(nlogn)) and find get the list of words
that are anagrams to the given word by looking up the HashTable(O(1)).

Thanks,
Immanuel

On Thu, May 19, 2011 at 11:11 PM, pacific :-)  wrote:

> If we were given two strings and asked to check if they have the same
> characters (anagrams) :
>
> @ gene : you are sorting them both ,and trying to match.
> cost : sort the first string + sort the second string + compare i.e k * k +
> k * k + k .. k is the length of the string.
> I presume that bubble sort is nearly optimal for smaller strings if u
> consider the overall performance ( its O(n^2) but smaller constants than the
> O(nlogn) with larger constants in say quicksort.
>
> Rather i would suggest , take each character and check that in the other
> string. O( k * k) ..in the average case you might do even less than nearly
> O(k * k/ 2) if the two strings are not same.
>
> On Wed, May 18, 2011 at 10:31 AM, anuj agarwal wrote:
>
>> Same method as Gene told.
>> Only enhancement u can made is start from the word nearer to sorted string
>> and compare till the nearest word of the reverse of sorted string.
>> You don't need to check the whole dictionary.
>>
>> Anuj Agarwal
>>
>> Engineering is the art of making what you want from things you can get.
>>
>>
>>
>> On Wed, May 18, 2011 at 6:01 AM, Gene  wrote:
>>
>>> Sort the characters in the string. Go through the dictionary sorting the
>>> characters in each word in turn.  Print the words whose sorted versions
>>> match the sorted string.
>>>
>>> You can quickly print all equivalence classes of anagrams in the
>>> dictionary by hashing with the sorted strings as keys. It only takes a few
>>> seconds to get them all this way with a 2-line perl or ruby script.
>>>
>>> --
>>> 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,
> chinna.
>
>  --
> 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: strings

2011-05-20 Thread immanuel kingston
Even my recursive solution will not work. :). Nice catch.!!.

int interleaved(char *s1, char *s2, char *s3) {
 if (s1 == null && s2== null && s3==null) return 1;
 if (s3==null) return 0;
 if (s1 != null && *s1 == *s3 && s2 != null && *s2 == *s3) return
interleaved(s1+1,s2,s3+1) || return interleaved(s1, s2+1,s3+1);
 if (s1 != null && *s1 == *s3) return interleaved(s1+1,s2,s3+1);
 else if (s2 != null && *s2 == *s3) return interleaved(s1, s2+1,s3+1);
 return 0;
}

int interleaved(char *s1, char *s2, char *s3) {
  if (s1 == null && s2== null && s3==null) return 1;
  if (s3==null) return 0;
  while (*s3) {
  // Added code here. So now its no more a iterative solution.
  if (s1 != null && *s1 == *s3 && s2 != null && *s2 == *s3)  return
interleaved(s1+1,s2,s3+1) || return interleaved(s1, s2+1,s3+1);
  if (s1 != null && *s1 == *s3) {
  s1++;
  }
  else if (s2 != null && *s2 == *s3) {
  s2++;
  } else {
  return 0;
  }
s3++;
}
return (s1 == null) && (s2 == null) && (s3 == null);
}

On Sat, May 21, 2011 at 1:05 AM, Don  wrote:

> Your iterative solution does not work in cases where both s1 and s2
> have the next character in s3, but only choosing the s2 character next
> will result in correct interleaving.
>
> s1 = "ab"
> s2 = "axb"
> s3 = "axabb"
>
> Your iterative solution will say that these are not interleaved, but
> they really are.
>
> Don
>
> On May 20, 2:21 pm, immanuel kingston 
> wrote:
> > A Recursive solution:
> >
> > int interleaved(char *s1, char *s2, char *s3) {
> >  if (s1 == null && s2== null && s3==null) return 1;
> >  if (s3==null) return 0;
> >  if (s1 != null && *s1 == *s3) return interleaved(s1+1,s2,s3+1);
> >  else if (s2 != null && *s2 == *s3) return interleaved(s1,
> s2+1,s3+1);
> >  return 0;
> >
> > }
> >
> > Iterative solution:
> > int interleaved(char *s1, char *s2, char *s3) {
> >  if (s1 == null && s2== null && s3==null) return 1;
> >  if (s3==null) return 0;
> >  while (*s3) {
> >  if (s1 != null && *s1 == *s3) {
> >  s1++;
> >  }
> >  else if (s2 != null && *s2 == *s3) {
> >  s2++;
> >  } else {
> >  return 0;
> >  }
> >  s3++;
> >  }
> >  return (s1 == null) && (s2 == null) && (s3 == null);
> >
> > }
> >
> > Thanks,
> > Immanuel
> >
> > On Fri, May 20, 2011 at 8:42 PM, Don  wrote:
> > > This is the same algorithm as my previous solution. Both produce the
> > > correct result, but this one does not have tail recursion, so it will
> > > run faster.
> >
> > > bool interleaved2(char *s1, char *s2, char *s3)
> > > {
> > >  while(1)
> > >  {
> > >if (!s1[0] && !s2[0] && !s3[0]) return true;
> > >if (s1[0] == s3[0])
> > >{
> > >  if (s2[0] == s3[0])
> > >  {
> > >if (interleaved2(s1+1, s2++,s3+1)) return true;
> > >  }
> > >  else ++s1;
> > >}
> > >else
> > >{
> > >  if (s2[0] == s3[0]) ++s2;
> > >  else return false;
> > >}
> > >++s3;
> > >   }
> > > }
> >
> > > On May 19, 1:33 pm, Piyush Sinha  wrote:
> > > > Design an algorithm to find whether a given string is formed by the
> > > > interleaving of two given strings or not. e.g. s1= aabccabc s2=
> dbbabc
> > > s3=
> > > > aabdbbccababcc Given s1,s2,s3 design an efficient algorithm to find
> > > whether
> > > > s3 is formed from the interleaving of s1 and s2
> >
> > > > --
> > > > *Piyush Sinha*
> > > > *IIIT, Allahabad*
> > > > *+91-8792136657*
> > > > *+91-7483122727*
> > > > *https://www.facebook.com/profile.php?id=10655377926*
> >
> > > --
> > > 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] Re: strings

2011-05-20 Thread Don
Your iterative solution does not work in cases where both s1 and s2
have the next character in s3, but only choosing the s2 character next
will result in correct interleaving.

s1 = "ab"
s2 = "axb"
s3 = "axabb"

Your iterative solution will say that these are not interleaved, but
they really are.

Don

On May 20, 2:21 pm, immanuel kingston 
wrote:
> A Recursive solution:
>
> int interleaved(char *s1, char *s2, char *s3) {
>      if (s1 == null && s2== null && s3==null) return 1;
>      if (s3==null) return 0;
>      if (s1 != null && *s1 == *s3) return interleaved(s1+1,s2,s3+1);
>      else if (s2 != null && *s2 == *s3) return interleaved(s1, s2+1,s3+1);
>      return 0;
>
> }
>
> Iterative solution:
> int interleaved(char *s1, char *s2, char *s3) {
>      if (s1 == null && s2== null && s3==null) return 1;
>      if (s3==null) return 0;
>      while (*s3) {
>          if (s1 != null && *s1 == *s3) {
>              s1++;
>          }
>          else if (s2 != null && *s2 == *s3) {
>              s2++;
>          } else {
>              return 0;
>          }
>          s3++;
>      }
>      return (s1 == null) && (s2 == null) && (s3 == null);
>
> }
>
> Thanks,
> Immanuel
>
> On Fri, May 20, 2011 at 8:42 PM, Don  wrote:
> > This is the same algorithm as my previous solution. Both produce the
> > correct result, but this one does not have tail recursion, so it will
> > run faster.
>
> > bool interleaved2(char *s1, char *s2, char *s3)
> > {
> >  while(1)
> >  {
> >    if (!s1[0] && !s2[0] && !s3[0]) return true;
> >    if (s1[0] == s3[0])
> >    {
> >      if (s2[0] == s3[0])
> >      {
> >        if (interleaved2(s1+1, s2++,s3+1)) return true;
> >      }
> >      else ++s1;
> >    }
> >    else
> >    {
> >      if (s2[0] == s3[0]) ++s2;
> >      else return false;
> >    }
> >    ++s3;
> >   }
> > }
>
> > On May 19, 1:33 pm, Piyush Sinha  wrote:
> > > Design an algorithm to find whether a given string is formed by the
> > > interleaving of two given strings or not. e.g. s1= aabccabc s2= dbbabc
> > s3=
> > > aabdbbccababcc Given s1,s2,s3 design an efficient algorithm to find
> > whether
> > > s3 is formed from the interleaving of s1 and s2
>
> > > --
> > > *Piyush Sinha*
> > > *IIIT, Allahabad*
> > > *+91-8792136657*
> > > *+91-7483122727*
> > > *https://www.facebook.com/profile.php?id=10655377926*
>
> > --
> > 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] Re: strings

2011-05-20 Thread Don
There are some things which could be done to make the program run
faster in some cases.
For example, either version of my solution above will take a very long
time to determine that these inputs are not interleaved:

s1 = "aa"
s2 = "aa"
s3 =
"aaab"

Adding code at the beginning to be sure that s3 has the same number of
instances of each character as s1 and s2 would be quick and would make
that case much faster.

Don

On May 20, 10:12 am, Don  wrote:
> This is the same algorithm as my previous solution. Both produce the
> correct result, but this one does not have tail recursion, so it will
> run faster.
>
> bool interleaved2(char *s1, char *s2, char *s3)
> {
>   while(1)
>   {
>     if (!s1[0] && !s2[0] && !s3[0]) return true;
>     if (s1[0] == s3[0])
>     {
>       if (s2[0] == s3[0])
>       {
>         if (interleaved2(s1+1, s2++,s3+1)) return true;
>       }
>       else ++s1;
>     }
>     else
>     {
>       if (s2[0] == s3[0]) ++s2;
>       else return false;
>     }
>     ++s3;
>   }
>
> }
>
> On May 19, 1:33 pm, Piyush Sinha  wrote:
>
> > Design an algorithm to find whether a given string is formed by the
> > interleaving of two given strings or not. e.g. s1= aabccabc s2= dbbabc s3=
> > aabdbbccababcc Given s1,s2,s3 design an efficient algorithm to find whether
> > s3 is formed from the interleaving of s1 and s2
>
> > --
> > *Piyush Sinha*
> > *IIIT, Allahabad*
> > *+91-8792136657*
> > *+91-7483122727*
> > *https://www.facebook.com/profile.php?id=10655377926*
>
>

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

2011-05-20 Thread immanuel kingston
A Recursive solution:

int interleaved(char *s1, char *s2, char *s3) {
 if (s1 == null && s2== null && s3==null) return 1;
 if (s3==null) return 0;
 if (s1 != null && *s1 == *s3) return interleaved(s1+1,s2,s3+1);
 else if (s2 != null && *s2 == *s3) return interleaved(s1, s2+1,s3+1);
 return 0;
}

Iterative solution:
int interleaved(char *s1, char *s2, char *s3) {
 if (s1 == null && s2== null && s3==null) return 1;
 if (s3==null) return 0;
 while (*s3) {
 if (s1 != null && *s1 == *s3) {
 s1++;
 }
 else if (s2 != null && *s2 == *s3) {
 s2++;
 } else {
 return 0;
 }
 s3++;
 }
 return (s1 == null) && (s2 == null) && (s3 == null);
}

Thanks,
Immanuel

On Fri, May 20, 2011 at 8:42 PM, Don  wrote:

> This is the same algorithm as my previous solution. Both produce the
> correct result, but this one does not have tail recursion, so it will
> run faster.
>
> bool interleaved2(char *s1, char *s2, char *s3)
> {
>  while(1)
>  {
>if (!s1[0] && !s2[0] && !s3[0]) return true;
>if (s1[0] == s3[0])
>{
>  if (s2[0] == s3[0])
>  {
>if (interleaved2(s1+1, s2++,s3+1)) return true;
>  }
>  else ++s1;
>}
>else
>{
>  if (s2[0] == s3[0]) ++s2;
>  else return false;
>}
>++s3;
>   }
> }
>
> On May 19, 1:33 pm, Piyush Sinha  wrote:
> > Design an algorithm to find whether a given string is formed by the
> > interleaving of two given strings or not. e.g. s1= aabccabc s2= dbbabc
> s3=
> > aabdbbccababcc Given s1,s2,s3 design an efficient algorithm to find
> whether
> > s3 is formed from the interleaving of s1 and s2
> >
> > --
> > *Piyush Sinha*
> > *IIIT, Allahabad*
> > *+91-8792136657*
> > *+91-7483122727*
> > *https://www.facebook.com/profile.php?id=10655377926*
>
> --
> 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: Google Q

2011-05-20 Thread immanuel kingston
Adding to Dave's Explanation.

Algo goes something like this,

while Adding a random number
- Have two heaps ie a MaxHeap(For storing numbers less than the median) and
a MinHeap(for numbers > the median).
- We will make sure that the median is the top element in the maxHeap
meaning that the MaxHeap will always be one greater than or equal to the
size of the minHeap
- If the size of the two heaps are equal and if the random number is greater
than the value in the min heap,remove the top element from the min heap and
push it to the max heap and push the random number into the minHeap. else
push the random number into the maxHeap
- If the size of the two heaps are not equal(assuming that the maxHeap has
one more than the minHeap) and if the random number is greater than or equal
to the value in the min heap, push it to the maxHeap else, remove the top
element from the maxHeap and push it to the minHeap and push the random
number into the minHeap.

getMedian():
- if the size of the two heaps are equal, select the average of the top
elements of the two heaps.
- if the size of the two heaps are equal, select the top element from the
heap with more elements.

Thanks,
Immanuel





On Fri, May 20, 2011 at 10:55 PM, Anand  wrote:

> @ Dave. Nice explanation
>
>
> On Fri, May 20, 2011 at 6:06 AM, saurabh agrawal wrote:
>
>> Thanks Dave.
>>
>> On Wed, May 18, 2011 at 8:01 PM, Dave  wrote:
>>
>>> @Saurabh: You look at the top elements in the two heaps. If the new
>>> number is between the values of the top of the heaps, you add it to
>>> the shorter of the two heaps, or to either heap if they are of equal
>>> length. If the new number is larger than the min of the min-heap, you
>>> add it to the min-heap. If it is smaller than the max of the max-heap,
>>> you add it to the max heap. If the resulting two heaps differ in
>>> length by more than one element, you move the top element from the
>>> longer heap into the shorter heap. Since the heaps start off empty and
>>> you add only one number at a time, the result of a step of the
>>> algorithm is that the two heaps will differ in size by at most one
>>> element. Thus, the smaller half of the numbers will be in the max-heap
>>> and the larger half will be in the min-heap.
>>>
>>> Dave
>>>
>>> On May 18, 8:29 am, saurabh agrawal  wrote:
>>> > Dave,
>>> > u said:" a max-heap of the smallest
>>> > half of the elements"
>>> > but if the number are randomply generated, then how will you get to
>>> know
>>> > whether a number belongs to smallest half OR lager half..
>>> > i didnt got it...
>>> >
>>> >
>>> >
>>> > On Sat, May 14, 2011 at 9:10 PM, Dave  wrote:
>>> > > @Ashish: The idea is to keep two heaps, a max-heap of the smallest
>>> > > half of the elements and a min-heap of the largest elements. You
>>> > > insert incoming elements into the appropriate heap. If the result is
>>> > > that the number of elements in the two heaps differs by more than 1,
>>> > > then you move the top element from the longer heap into the other
>>> one,
>>> > > thereby equalzing the number of elements. Thus, inserting an element
>>> > > is an O(log n) operation. To get the median, it is the top element of
>>> > > the longer heap, or, if the heaps are of equal length, it is the
>>> > > average of the two top elements. This is O(1).
>>> >
>>> > > Dave
>>> >
>>> > > On May 14, 8:34 am, Ashish Goel  wrote:
>>> > > > not clear, can u elaborate..
>>> >
>>> > > > Best Regards
>>> > > > Ashish Goel
>>> > > > "Think positive and find fuel in failure"
>>> > > > +919985813081
>>> > > > +919966006652
>>> >
>>> > > > On Fri, May 13, 2011 at 7:15 PM, Bhavesh agrawal <
>>> agr.bhav...@gmail.com
>>> > > >wrote:
>>> >
>>> > > > > This problem can be solved using 2 heaps and the median can
>>> always be
>>> > > > > accessed in O(1) time ,the first node.
>>> >
>>> > > > > --
>>> > > > > 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.- 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 unsubscrib

Re: [algogeeks] PUZZLE

2011-05-20 Thread Piyush Sinha
500

On 5/20/11, Bhavesh agrawal  wrote:
> 1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
> travel.
> total bananas are 3000 and distance have to travel from A to B is 1000km.
>
> So how many max bananas he can take from A to B.   (he'll eat in return
> travel  too)
>
> --
> 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.
>
>


-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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: Google Q

2011-05-20 Thread Anand
@ Dave. Nice explanation

On Fri, May 20, 2011 at 6:06 AM, saurabh agrawal wrote:

> Thanks Dave.
>
> On Wed, May 18, 2011 at 8:01 PM, Dave  wrote:
>
>> @Saurabh: You look at the top elements in the two heaps. If the new
>> number is between the values of the top of the heaps, you add it to
>> the shorter of the two heaps, or to either heap if they are of equal
>> length. If the new number is larger than the min of the min-heap, you
>> add it to the min-heap. If it is smaller than the max of the max-heap,
>> you add it to the max heap. If the resulting two heaps differ in
>> length by more than one element, you move the top element from the
>> longer heap into the shorter heap. Since the heaps start off empty and
>> you add only one number at a time, the result of a step of the
>> algorithm is that the two heaps will differ in size by at most one
>> element. Thus, the smaller half of the numbers will be in the max-heap
>> and the larger half will be in the min-heap.
>>
>> Dave
>>
>> On May 18, 8:29 am, saurabh agrawal  wrote:
>> > Dave,
>> > u said:" a max-heap of the smallest
>> > half of the elements"
>> > but if the number are randomply generated, then how will you get to know
>> > whether a number belongs to smallest half OR lager half..
>> > i didnt got it...
>> >
>> >
>> >
>> > On Sat, May 14, 2011 at 9:10 PM, Dave  wrote:
>> > > @Ashish: The idea is to keep two heaps, a max-heap of the smallest
>> > > half of the elements and a min-heap of the largest elements. You
>> > > insert incoming elements into the appropriate heap. If the result is
>> > > that the number of elements in the two heaps differs by more than 1,
>> > > then you move the top element from the longer heap into the other one,
>> > > thereby equalzing the number of elements. Thus, inserting an element
>> > > is an O(log n) operation. To get the median, it is the top element of
>> > > the longer heap, or, if the heaps are of equal length, it is the
>> > > average of the two top elements. This is O(1).
>> >
>> > > Dave
>> >
>> > > On May 14, 8:34 am, Ashish Goel  wrote:
>> > > > not clear, can u elaborate..
>> >
>> > > > Best Regards
>> > > > Ashish Goel
>> > > > "Think positive and find fuel in failure"
>> > > > +919985813081
>> > > > +919966006652
>> >
>> > > > On Fri, May 13, 2011 at 7:15 PM, Bhavesh agrawal <
>> agr.bhav...@gmail.com
>> > > >wrote:
>> >
>> > > > > This problem can be solved using 2 heaps and the median can always
>> be
>> > > > > accessed in O(1) time ,the first node.
>> >
>> > > > > --
>> > > > > 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.- 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.
>

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

2011-05-20 Thread Bhavesh agrawal
1 elephant can take 1000 banana at a time and eat 1 banana after each 1km
travel.
total bananas are 3000 and distance have to travel from A to B is 1000km.

So how many max bananas he can take from A to B.   (he'll eat in return
travel  too)

-- 
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] Re: strings

2011-05-20 Thread Don
This is the same algorithm as my previous solution. Both produce the
correct result, but this one does not have tail recursion, so it will
run faster.

bool interleaved2(char *s1, char *s2, char *s3)
{
  while(1)
  {
if (!s1[0] && !s2[0] && !s3[0]) return true;
if (s1[0] == s3[0])
{
  if (s2[0] == s3[0])
  {
if (interleaved2(s1+1, s2++,s3+1)) return true;
  }
  else ++s1;
}
else
{
  if (s2[0] == s3[0]) ++s2;
  else return false;
}
++s3;
  }
}

On May 19, 1:33 pm, Piyush Sinha  wrote:
> Design an algorithm to find whether a given string is formed by the
> interleaving of two given strings or not. e.g. s1= aabccabc s2= dbbabc s3=
> aabdbbccababcc Given s1,s2,s3 design an efficient algorithm to find whether
> s3 is formed from the interleaving of s1 and s2
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926*

-- 
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: sum of two

2011-05-20 Thread Aakash Johari
@Dave: This is what is still a doubt to me. I have searched but couldn't get
the info regarding this.

On Fri, May 20, 2011 at 8:01 AM, Dave  wrote:

> @Aakash: And tell me how map works. Is making an entry O(1) regardless
> of the value of the entry? For example, is it O(n) to map the sequence
> 1, 4, 9, 16, 25, ..., n^2?
>
> Dave
>
> On May 20, 9:39 am, Aakash Johari  wrote:
> > @Dave: I got you. I will have to check before pushing the element in map.
> >
> >
> >
> >
> >
> > On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > happens.
> >
> > > Dave
> >
> > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > int main()
> > > > {
> > > > int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > int i;
> > > > int sum;
> > > > int flag = 0;
> >
> > > > map m;
> >
> > > > for ( i = 0; i < 10; i++ ) {
> > > > m[a[i]] = 1;
> > > > }
> >
> > > > sum = 13;
> >
> > > > for ( i = 0; i < 10; i++ ) {
> > > > if ( m[sum - a[i]] == 1 ) {
> > > > flag = 1;
> > > > break;
> > > > }
> > > > }
> >
> > > > if ( flag == 1 )
> > > > cout << a[i] << " " << sum - a[i] << endl;
> >
> > > > return 0;
> >
> > > > }
> > > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > > We can sort using STL sort function in main() before function call
> of
> > > > > arraysum().
> >
> > > > > On May 20, 6:49 am, Gunjan Sharma 
> wrote:
> > > > > > First of all there is an infinite loop in this code
> > > > > > Secondly it works only for sorted array.
> >
> > > > > > On Fri, May 20, 2011 at 7:16 PM, hari 
> wrote:
> > > > > > > In while loop have i,j which points first and last index of
> array.
> > > In
> > > > > > > while loop, Check the sum of a[i],a[j], If sum > > else
> > > > > > > decrement j. Run the while loop till i >
> > > > > > > CODE:
> >
> > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > while(i > > > > > > {
> > > > > > >  int p=0;
> > > > > > >  int b[10]; //to store index of selected nos
> > > > > > >  sum=a[i]+a[j];
> > > > > > >  if (sum==k)
> > > > > > >  {
> > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > >  }
> > > > > > >  elseif(sum > > > > > >  i++;
> > > > > > >  else(sum>k)
> > > > > > >  j++;
> > > > > > >  return b;
> > > > > > > }
> >
> > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > given an array of integers, and an integer k, find out two
> > > elements
> > > > > > > > from the array whose sum is k in O(n) time. if no such
> element
> > > exists
> > > > > > > > output none.
> >
> > > > > > > --
> > > > > > > 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
> > > > > > Gunjan Sharma
> > > > > > B.Tech IV year CSE
> >
> > > > > > Contact No- +91 9997767077
> >
> > > > > --
> > > > > 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.
> >
> > > > --
> > > > -Aakash Johari
> > > > (IIIT Allahabad)- 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.
> >
> > --
> > -Aakash Johari
> > (IIIT Allahabad)- 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.
>
>


-- 
-Aakash Johari
(IIIT 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+u

[algogeeks] Re: sum of two

2011-05-20 Thread Dave
@Aakash: And tell me how map works. Is making an entry O(1) regardless
of the value of the entry? For example, is it O(n) to map the sequence
1, 4, 9, 16, 25, ..., n^2?

Dave

On May 20, 9:39 am, Aakash Johari  wrote:
> @Dave: I got you. I will have to check before pushing the element in map.
>
>
>
>
>
> On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:
> > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > happens.
>
> > Dave
>
> > On May 20, 9:04 am, Aakash Johari  wrote:
> > > int main()
> > > {
> > >         int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > >         int i;
> > >         int sum;
> > >         int flag = 0;
>
> > >         map m;
>
> > >         for ( i = 0; i < 10; i++ ) {
> > >                 m[a[i]] = 1;
> > >         }
>
> > >         sum = 13;
>
> > >         for ( i = 0; i < 10; i++ ) {
> > >                 if ( m[sum - a[i]] == 1 ) {
> > >                         flag = 1;
> > >                         break;
> > >                 }
> > >         }
>
> > >         if ( flag == 1 )
> > >                 cout << a[i] << " " << sum - a[i] << endl;
>
> > >         return 0;
>
> > > }
> > > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > > We can sort using STL sort function in main() before function call of
> > > > arraysum().
>
> > > > On May 20, 6:49 am, Gunjan Sharma  wrote:
> > > > > First of all there is an infinite loop in this code
> > > > > Secondly it works only for sorted array.
>
> > > > > On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > > > > > In while loop have i,j which points first and last index of array.
> > In
> > > > > > while loop, Check the sum of a[i],a[j], If sum > else
> > > > > > decrement j. Run the while loop till i
> > > > > > CODE:
>
> > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > while(i > > > > > {
> > > > > >  int p=0;
> > > > > >  int b[10];     //to store index of selected nos
> > > > > >  sum=a[i]+a[j];
> > > > > >  if (sum==k)
> > > > > >  {
> > > > > >  b[p++]=i;b[p++]=j;
> > > > > >  }
> > > > > >  elseif(sum > > > > >  i++;
> > > > > >  else(sum>k)
> > > > > >  j++;
> > > > > >  return b;
> > > > > > }
>
> > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > given an array of integers, and an integer k, find out two
> > elements
> > > > > > > from the array whose sum is k in O(n) time. if no such element
> > exists
> > > > > > > output none.
>
> > > > > > --
> > > > > > 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
> > > > > Gunjan Sharma
> > > > > B.Tech IV year CSE
>
> > > > > Contact No- +91 9997767077
>
> > > > --
> > > > 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.
>
> > > --
> > > -Aakash Johari
> > > (IIIT Allahabad)- 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.
>
> --
> -Aakash Johari
> (IIIT Allahabad)- 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.



Re: [algogeeks] Re: sum of two

2011-05-20 Thread Aakash Johari
@Dave: I got you. I will have to check before pushing the element in map.

On Fri, May 20, 2011 at 7:30 AM, Dave  wrote:

> @Aakash: Yeah, but try the same array with sum = 6 and see what
> happens.
>
> Dave
>
> On May 20, 9:04 am, Aakash Johari  wrote:
> > int main()
> > {
> > int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > int i;
> > int sum;
> > int flag = 0;
> >
> > map m;
> >
> > for ( i = 0; i < 10; i++ ) {
> > m[a[i]] = 1;
> > }
> >
> > sum = 13;
> >
> > for ( i = 0; i < 10; i++ ) {
> > if ( m[sum - a[i]] == 1 ) {
> > flag = 1;
> > break;
> > }
> > }
> >
> > if ( flag == 1 )
> > cout << a[i] << " " << sum - a[i] << endl;
> >
> > return 0;
> >
> >
> >
> >
> >
> > }
> > On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > > We can sort using STL sort function in main() before function call of
> > > arraysum().
> >
> > > On May 20, 6:49 am, Gunjan Sharma  wrote:
> > > > First of all there is an infinite loop in this code
> > > > Secondly it works only for sorted array.
> >
> > > > On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > > > > In while loop have i,j which points first and last index of array.
> In
> > > > > while loop, Check the sum of a[i],a[j], If sum else
> > > > > decrement j. Run the while loop till i >
> > > > > CODE:
> >
> > > > > int arraysum(int a[], int k, int i, int j)
> > > > > while(i > > > > {
> > > > >  int p=0;
> > > > >  int b[10]; //to store index of selected nos
> > > > >  sum=a[i]+a[j];
> > > > >  if (sum==k)
> > > > >  {
> > > > >  b[p++]=i;b[p++]=j;
> > > > >  }
> > > > >  elseif(sum > > > >  i++;
> > > > >  else(sum>k)
> > > > >  j++;
> > > > >  return b;
> > > > > }
> >
> > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > given an array of integers, and an integer k, find out two
> elements
> > > > > > from the array whose sum is k in O(n) time. if no such element
> exists
> > > > > > output none.
> >
> > > > > --
> > > > > 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
> > > > Gunjan Sharma
> > > > B.Tech IV year CSE
> >
> > > > Contact No- +91 9997767077
> >
> > > --
> > > 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.
> >
> > --
> > -Aakash Johari
> > (IIIT Allahabad)- 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.
>
>


-- 
-Aakash Johari
(IIIT 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.



[algogeeks] Re: sum of two

2011-05-20 Thread Dave
@Aakash: Yeah, but try the same array with sum = 6 and see what
happens.

Dave

On May 20, 9:04 am, Aakash Johari  wrote:
> int main()
> {
>         int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
>         int i;
>         int sum;
>         int flag = 0;
>
>         map m;
>
>         for ( i = 0; i < 10; i++ ) {
>                 m[a[i]] = 1;
>         }
>
>         sum = 13;
>
>         for ( i = 0; i < 10; i++ ) {
>                 if ( m[sum - a[i]] == 1 ) {
>                         flag = 1;
>                         break;
>                 }
>         }
>
>         if ( flag == 1 )
>                 cout << a[i] << " " << sum - a[i] << endl;
>
>         return 0;
>
>
>
>
>
> }
> On Fri, May 20, 2011 at 7:01 AM, hari  wrote:
> > We can sort using STL sort function in main() before function call of
> > arraysum().
>
> > On May 20, 6:49 am, Gunjan Sharma  wrote:
> > > First of all there is an infinite loop in this code
> > > Secondly it works only for sorted array.
>
> > > On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > > > In while loop have i,j which points first and last index of array. In
> > > > while loop, Check the sum of a[i],a[j], If sum > > > decrement j. Run the while loop till i
> > > > CODE:
>
> > > > int arraysum(int a[], int k, int i, int j)
> > > > while(i > > > {
> > > >  int p=0;
> > > >  int b[10];     //to store index of selected nos
> > > >  sum=a[i]+a[j];
> > > >  if (sum==k)
> > > >  {
> > > >  b[p++]=i;b[p++]=j;
> > > >  }
> > > >  elseif(sum > > >  i++;
> > > >  else(sum>k)
> > > >  j++;
> > > >  return b;
> > > > }
>
> > > > On May 20, 4:38 am, amit  wrote:
> > > > > given an array of integers, and an integer k, find out two elements
> > > > > from the array whose sum is k in O(n) time. if no such element exists
> > > > > output none.
>
> > > > --
> > > > 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
> > > Gunjan Sharma
> > > B.Tech IV year CSE
>
> > > Contact No- +91 9997767077
>
> > --
> > 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.
>
> --
> -Aakash Johari
> (IIIT Allahabad)- 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.



[algogeeks] Re: sum of two

2011-05-20 Thread Dave
@Amit: Use a hash table. For each integer x[i] in the array, search
for k - x[i]. If found, x[i] and k - x[i] are your pair of integers.
Otherwise, add x[i] to the hash table and advance the loop. Output
"none" if you get to the end of the array without a hit.

Dave

On May 20, 6:38 am, amit  wrote:
> given an array of integers, and an integer k, find out two elements
> from the array whose sum is k in O(n) time. if no such element exists
> output none.

-- 
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] Re: sum of two

2011-05-20 Thread hari
We can sort using STL sort function in main() before function call of
arraysum().

On May 20, 6:49 am, Gunjan Sharma  wrote:
> First of all there is an infinite loop in this code
> Secondly it works only for sorted array.
>
>
>
>
>
>
>
>
>
> On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > In while loop have i,j which points first and last index of array. In
> > while loop, Check the sum of a[i],a[j], If sum > decrement j. Run the while loop till i
> > CODE:
>
> > int arraysum(int a[], int k, int i, int j)
> > while(i > {
> >  int p=0;
> >  int b[10];     //to store index of selected nos
> >  sum=a[i]+a[j];
> >  if (sum==k)
> >  {
> >  b[p++]=i;b[p++]=j;
> >  }
> >  elseif(sum >  i++;
> >  else(sum>k)
> >  j++;
> >  return b;
> > }
>
> > On May 20, 4:38 am, amit  wrote:
> > > given an array of integers, and an integer k, find out two elements
> > > from the array whose sum is k in O(n) time. if no such element exists
> > > output none.
>
> > --
> > 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
> Gunjan Sharma
> B.Tech IV year CSE
>
> Contact No- +91 9997767077

-- 
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: sum of two

2011-05-20 Thread Aakash Johari
int main()
{
int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
int i;
int sum;
int flag = 0;

map m;

for ( i = 0; i < 10; i++ ) {
m[a[i]] = 1;
}

sum = 13;

for ( i = 0; i < 10; i++ ) {
if ( m[sum - a[i]] == 1 ) {
flag = 1;
break;
}
}

if ( flag == 1 )
cout << a[i] << " " << sum - a[i] << endl;

return 0;
}

On Fri, May 20, 2011 at 7:01 AM, hari  wrote:

> We can sort using STL sort function in main() before function call of
> arraysum().
>
> On May 20, 6:49 am, Gunjan Sharma  wrote:
> > First of all there is an infinite loop in this code
> > Secondly it works only for sorted array.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > > In while loop have i,j which points first and last index of array. In
> > > while loop, Check the sum of a[i],a[j], If sum > > decrement j. Run the while loop till i >
> > > CODE:
> >
> > > int arraysum(int a[], int k, int i, int j)
> > > while(i > > {
> > >  int p=0;
> > >  int b[10]; //to store index of selected nos
> > >  sum=a[i]+a[j];
> > >  if (sum==k)
> > >  {
> > >  b[p++]=i;b[p++]=j;
> > >  }
> > >  elseif(sum > >  i++;
> > >  else(sum>k)
> > >  j++;
> > >  return b;
> > > }
> >
> > > On May 20, 4:38 am, amit  wrote:
> > > > given an array of integers, and an integer k, find out two elements
> > > > from the array whose sum is k in O(n) time. if no such element exists
> > > > output none.
> >
> > > --
> > > 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
> > Gunjan Sharma
> > B.Tech IV year CSE
> >
> > Contact No- +91 9997767077
>
> --
> 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.
>
>


-- 
-Aakash Johari
(IIIT 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.



Re: [algogeeks] Re: sum of two

2011-05-20 Thread Gunjan Sharma
makes it O(nlg(n))

On Fri, May 20, 2011 at 7:31 PM, hari  wrote:

> We can sort using STL sort function in main() before function call of
> arraysum().
>
> On May 20, 6:49 am, Gunjan Sharma  wrote:
> > First of all there is an infinite loop in this code
> > Secondly it works only for sorted array.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
> > > In while loop have i,j which points first and last index of array. In
> > > while loop, Check the sum of a[i],a[j], If sum > > decrement j. Run the while loop till i >
> > > CODE:
> >
> > > int arraysum(int a[], int k, int i, int j)
> > > while(i > > {
> > >  int p=0;
> > >  int b[10]; //to store index of selected nos
> > >  sum=a[i]+a[j];
> > >  if (sum==k)
> > >  {
> > >  b[p++]=i;b[p++]=j;
> > >  }
> > >  elseif(sum > >  i++;
> > >  else(sum>k)
> > >  j++;
> > >  return b;
> > > }
> >
> > > On May 20, 4:38 am, amit  wrote:
> > > > given an array of integers, and an integer k, find out two elements
> > > > from the array whose sum is k in O(n) time. if no such element exists
> > > > output none.
> >
> > > --
> > > 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
> > Gunjan Sharma
> > B.Tech IV year CSE
> >
> > Contact No- +91 9997767077
>
> --
> 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
Gunjan Sharma
B.Tech IV year CSE

Contact No- +91 9997767077

-- 
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: sum of two

2011-05-20 Thread Aakash Johari
One possible solution is using maps. But i think that won't be in O(n)

On Fri, May 20, 2011 at 6:49 AM, Gunjan Sharma wrote:

> First of all there is an infinite loop in this code
> Secondly it works only for sorted array.
>
>
> On Fri, May 20, 2011 at 7:16 PM, hari  wrote:
>
>> In while loop have i,j which points first and last index of array. In
>> while loop, Check the sum of a[i],a[j], If sum> decrement j. Run the while loop till i>
>> CODE:
>>
>> int arraysum(int a[], int k, int i, int j)
>> while(i> {
>>  int p=0;
>>  int b[10]; //to store index of selected nos
>>  sum=a[i]+a[j];
>>  if (sum==k)
>>  {
>>  b[p++]=i;b[p++]=j;
>>  }
>>  elseif(sum>  i++;
>>  else(sum>k)
>>  j++;
>>  return b;
>> }
>>
>> On May 20, 4:38 am, amit  wrote:
>> > given an array of integers, and an integer k, find out two elements
>> > from the array whose sum is k in O(n) time. if no such element exists
>> > output none.
>>
>> --
>> 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
> Gunjan Sharma
> B.Tech IV year CSE
>
> Contact No- +91 9997767077
>
>  --
> 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.
>



-- 
-Aakash Johari
(IIIT 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.



Re: [algogeeks] Re: sum of two

2011-05-20 Thread Gunjan Sharma
First of all there is an infinite loop in this code
Secondly it works only for sorted array.

On Fri, May 20, 2011 at 7:16 PM, hari  wrote:

> In while loop have i,j which points first and last index of array. In
> while loop, Check the sum of a[i],a[j], If sum decrement j. Run the while loop till i
> CODE:
>
> int arraysum(int a[], int k, int i, int j)
> while(i {
>  int p=0;
>  int b[10]; //to store index of selected nos
>  sum=a[i]+a[j];
>  if (sum==k)
>  {
>  b[p++]=i;b[p++]=j;
>  }
>  elseif(sum  i++;
>  else(sum>k)
>  j++;
>  return b;
> }
>
> On May 20, 4:38 am, amit  wrote:
> > given an array of integers, and an integer k, find out two elements
> > from the array whose sum is k in O(n) time. if no such element exists
> > output none.
>
> --
> 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
Gunjan Sharma
B.Tech IV year CSE

Contact No- +91 9997767077

-- 
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] Re: sum of two

2011-05-20 Thread hari
In while loop have i,j which points first and last index of array. In
while loop, Check the sum of a[i],a[j], If sumk)
  j++;
 return b;
}

On May 20, 4:38 am, amit  wrote:
> given an array of integers, and an integer k, find out two elements
> from the array whose sum is k in O(n) time. if no such element exists
> output none.

-- 
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: Google Q

2011-05-20 Thread saurabh agrawal
Thanks Dave.

On Wed, May 18, 2011 at 8:01 PM, Dave  wrote:

> @Saurabh: You look at the top elements in the two heaps. If the new
> number is between the values of the top of the heaps, you add it to
> the shorter of the two heaps, or to either heap if they are of equal
> length. If the new number is larger than the min of the min-heap, you
> add it to the min-heap. If it is smaller than the max of the max-heap,
> you add it to the max heap. If the resulting two heaps differ in
> length by more than one element, you move the top element from the
> longer heap into the shorter heap. Since the heaps start off empty and
> you add only one number at a time, the result of a step of the
> algorithm is that the two heaps will differ in size by at most one
> element. Thus, the smaller half of the numbers will be in the max-heap
> and the larger half will be in the min-heap.
>
> Dave
>
> On May 18, 8:29 am, saurabh agrawal  wrote:
> > Dave,
> > u said:" a max-heap of the smallest
> > half of the elements"
> > but if the number are randomply generated, then how will you get to know
> > whether a number belongs to smallest half OR lager half..
> > i didnt got it...
> >
> >
> >
> > On Sat, May 14, 2011 at 9:10 PM, Dave  wrote:
> > > @Ashish: The idea is to keep two heaps, a max-heap of the smallest
> > > half of the elements and a min-heap of the largest elements. You
> > > insert incoming elements into the appropriate heap. If the result is
> > > that the number of elements in the two heaps differs by more than 1,
> > > then you move the top element from the longer heap into the other one,
> > > thereby equalzing the number of elements. Thus, inserting an element
> > > is an O(log n) operation. To get the median, it is the top element of
> > > the longer heap, or, if the heaps are of equal length, it is the
> > > average of the two top elements. This is O(1).
> >
> > > Dave
> >
> > > On May 14, 8:34 am, Ashish Goel  wrote:
> > > > not clear, can u elaborate..
> >
> > > > Best Regards
> > > > Ashish Goel
> > > > "Think positive and find fuel in failure"
> > > > +919985813081
> > > > +919966006652
> >
> > > > On Fri, May 13, 2011 at 7:15 PM, Bhavesh agrawal <
> agr.bhav...@gmail.com
> > > >wrote:
> >
> > > > > This problem can be solved using 2 heaps and the median can always
> be
> > > > > accessed in O(1) time ,the first node.
> >
> > > > > --
> > > > > 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.- 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.



[algogeeks] sum of two

2011-05-20 Thread amit
given an array of integers, and an integer k, find out two elements
from the array whose sum is k in O(n) time. if no such element exists
output none.

-- 
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] [brain teaser ] A Logic Riddle 20 may

2011-05-20 Thread amit kumar
none

On Fri, May 20, 2011 at 12:44 PM, Lavesh Rawat wrote:

> *
> A Logic Riddle
>
> Which sentence is correct; 'Three times two IS seven' or 'Three times two
> ARE seven'?
>
> For Solution: Click 
> Here
>
>
>
> --
>
> "Never explain yourself. Your friends don’t need it and
> your enemies won’t believe it" .*
>
> --
> 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] [brain teaser ] A Logic Riddle 20 may

2011-05-20 Thread Lavesh Rawat
*
A Logic Riddle

Which sentence is correct; 'Three times two IS seven' or 'Three times two
ARE seven'?

For Solution: Click
Here



-- 

"Never explain yourself. Your friends don’t need it and
your enemies won’t believe it" .*

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