[algogeeks] kth smallest element in 2 sorted arrays

2013-06-09 Thread rahul sharma
Please suggest logm+logn aproach...
can be easily done in o(k)


How to do in logm +logn

plz suggest algo

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: Median of two sorted arrays of different sizes

2013-06-09 Thread rahul sharma
@doncan u plz explain the approach used.I didnt get this.

On 4/25/13, Don  wrote:
> Let's say you have two arrays: A[x] and B[y].
> The median is the (x+y)/2th value.
> If A[i] is the median, then B[(x+y)/2-i] <= A[i] and B[(x+y)/2-i+1] >=
> A[i].
> You can use a binary search to find the point where that condition
> occurs. Of course you want to search on the smaller array.
> You'll need some logic at the end to determine if the median is in A
> or in B.
>
> // Input arrays A and B, sizeA <= sizeB
> int A[sizeA];
> int B[sizeB];
>
> int min = 0;
> int max = sizeA;
> const int medianPos = (sizeA + sizeB) / 2;
> while(max >= min)
> {
>   i = (min + max) / 2;
>   j = medianPos-i;
>   if (B[j] > A[i]) min = i+1;
>   else if (B[j+1] < A[i]) max = i-1;
>   else break;
> }
>
> printf("Median is %d\n", (A[i] > B[j]) ? A[i] : B[j]);
>
> Don
>
> On Apr 24, 1:19 pm, rahul sharma  wrote:
>> IS this code correct?
>>
>> float findMedianUtil( int A[], int N, int B[], int M )
>> {
>>     // If the smaller array has only one element
>>     if( N == 1 )
>>     {
>>         // Case 1: If the larger array also has one element, simply call
>> MO2()
>>         if( M == 1 )
>>             return MO2( A[0], B[0] );
>>
>>         // Case 2: If the larger array has odd number of elements, then
>> consider
>>         // the middle 3 elements of larger array and the only element of
>>         // smaller array. Take few examples like following
>>         // A = {9}, B[] = {5, 8, 10, 20, 30} and
>>         // A[] = {1}, B[] = {5, 8, 10, 20, 30}
>>         if( M & 1 )
>>             return MO2( B[M/2], MO3(A[0], B[M/2 - 1], B[M/2 + 1]) );
>>
>>         // Case 3: If the larger array has even number of element, then
>> median
>>         // will be one of the following 3 elements
>>         // ... The middle two elements of larger array
>>         // ... The only element of smaller array
>>         return MO3( B[M/2], B[M/2 - 1], A[0] );
>>     }
>>
>>     // If the smaller array has two elements
>>     else if( N == 2 )
>>     {
>>         // Case 4: If the larger array also has two elements, simply call
>> MO4()
>>         if( M == 2 )
>>             return MO4( A[0], A[1], B[0], B[1] );
>>
>>         // Case 5: If the larger array has odd number of elements, then
>> median
>>         // will be one of the following 3 elements
>>         // 1. Middle element of larger array
>>         // 2. Max of first element of smaller array and element just
>>         //    before the middle in bigger array
>>         // 3. Min of second element of smaller array and element just
>>         //    after the middle in bigger array
>>         if( M & 1 )
>>             return MO3 ( B[M/2],
>>                          max( A[0], B[M/2 - 1] ),
>>                          min( A[1], B[M/2 + 1] )
>>                        );
>>
>>         // Case 6: If the larger array has even number of elements, then
>>         // median will be one of the following 4 elements
>>         // 1) & 2) The middle two elements of larger array
>>         // 3) Max of first element of smaller array and element
>>         //    just before the first middle element in bigger array
>>         // 4. Min of second element of smaller array and element
>>         //    just after the second middle in bigger array
>>         return MO4 ( B[M/2],
>>                      B[M/2 - 1],
>>                      max( A[0], B[M/2 - 2] ),
>>                      min( A[1], B[M/2 + 1] )
>>                    );
>>     }
>>
>>     int idxA = ( N - 1 ) / 2;
>>     int idxB = ( M - 1 ) / 2;
>>
>>      /* if A[idxA] <= B[idxB], then median must exist in
>>         A[idxA] and B[idxB] */
>>     if( A[idxA] <= B[idxB] )
>>         return findMedianUtil( A + idxA, N / 2 + 1, B, M - idxA );
>>
>>     /* if A[idxA] > B[idxB], then median must exist in
>>        A[...idxA] and B[idxB] */
>>     return findMedianUtil( A, N / 2 + 1, B + idxA, M - idxA );
>>
>> }
>>
>> In the end I suspect the following part:-
>>
>>   if( A[idxA] <= B[idxB] )
>>         return findMedianUtil( A + idxA, N / 2 + 1, B, M - idxA );
>>
>>     /* if A[idxA] > B[idxB], then median must exist in
>>        A[...idxA] and B[idxB] */
>>     return findMedianUtil( A, N / 2 + 1, B + idxA, M - idxA );
>>
>> plz comment
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Minimum number of coins to SUM to S

2013-06-05 Thread rahul sharma
yes clasic DP


On Wed, May 29, 2013 at 8:54 PM, Ravi Ranjan wrote:

> @DAve
>
> any proper reason or link to proof that at least twice can be solved using
> greedy but others are not??
>
>
> On Tue, May 28, 2013 at 12:41 PM, Shashwat Kumar <
> shashwatkmr@gmail.com> wrote:
>
>> This seems to be Coin Change problem. Just google that.
>>
>>
>> On Tue, May 28, 2013 at 12:42 AM, Adolfo Ccanto wrote:
>>
>>> Can you write the constraints for this problem?
>>> thanks.
>>> Adolfo
>>>
>>>
>>> 2013/5/18 rahul sharma 
>>>
>>>> Minimum of coins to sum s
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>>
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>>
>>>
>>
>>
>>
>> --
>> Shashwat Kumar
>> Third year Undergraduate student
>> Department of Computer Science and Engineering
>> IIT Kharagpur
>>
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] Re: t9 dictionary

2013-06-05 Thread rahul sharma
Can i implement by trie which is having structure as 9 pointers for 9
digits..like if it comes 4663...i will make a path 4663 from root to leaf
and in end i will have a linked list to store dataany more optimized
solution anyone having???plz suggest


On Thu, May 30, 2013 at 2:37 AM, rahul sharma wrote:

> how to implement with trie.???is trie the best way..plz provide me raw
> algo to start with,
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] A Juggling Algorithm

2013-06-05 Thread rahul sharma
Can anybody explain me how juggling algo works for array rotation ???Whats
the logic behind this?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: searching all matching words in a Trie with a given filter.

2013-06-05 Thread rahul sharma
wat exaclty the question is.
We have to make a tire with filter or we have a trie(whole dictionary) and
we have to check filter out the elements.

plz explain question


On Wed, May 29, 2013 at 7:55 PM, Don  wrote:

> There has to be some way to know that a node is the end of a word, and
> to know what that word is. This might be done by using a parent
> pointer which lets you traverse the trie back to the root, rebuilding
> the word, or you could keep track of the word as you traverse down the
> trie. Putting the whole word in the node where the word ends would be
> the most simple and time-efficient approach, if you have the memory to
> support it.
>
> Here is a different way to do it, if the trie has a "wordEnd" flag and
> does not store the word in the node.
>
> void findWords(trie *root, char *filter, String word="")
> {
> if (!root) return;
>
> if (*filter == 0)  // When you reach the end of the filter at the
> end of a valid word, add the word.
> {
> if (root->wordEnd) words.add(word);
> }
> else if (*filter == '.')   // Search for words with any letter
> {
> for(int i = 'a'; i <= 'z' ; ++i)
> findWords(root->link[i], filter+1, word+i);
> }
> else  // Search for words with the required letter
> {
>  findWords(root->link[*filter], filter+1, word+*filter);
> }
> }
>
> On May 28, 11:36 pm, avinesh saini  wrote:
> > Thank you Don, I was also trying in similar way. But here I'm confused
> how
> > you are storing the traversed words. Are you adding whole words at the
> node
> > on which word is ending during insertion.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Wed, May 29, 2013 at 12:36 AM, Don  wrote:
> > > void findWords(trie *root, char *filter)
> > > {
> > > if (!root) return;
> >
> > > if (*filter == 0)  // When you reach the end of the filter at the
> > > end of a valid word, add the word.
> > > {
> > > if (root->words) words.add(root->word);
> > > }
> > > else if (*filter == '.')   // Search for words with any letter
> > > {
> > > for(int i = 'a'; i <= 'z' ; ++i)
> > > findWords(root->link[i], filter+1);
> > > }
> > > else  // Search for words with the required letter
> > > {
> > >  findWords(root->link[*filter], filter+1);
> > > }
> > > }
> >
> > > On May 28, 4:47 am, avinesh saini  wrote:
> > > > How to search all the matching words for a filter in a trie.
> > > > e.g.
> > > > searching by filter  "...r..m" will find all the words(of length =
> 7) in
> > > > trie in which 4th character is 'r' and 7th character is 'm'.
> >
> > > > --
> > > > *
> > > > *
> > > > *thanks & regards,*
> > > > *Avinesh
> > > > *
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an
> > > email to algogeeks+unsubscr...@googlegroups.com.
> >
> > --
> > *
> > *
> > *thanks & regards,*
> > *Avinesh
> > *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] t9 dictionary

2013-06-05 Thread rahul sharma
how to implement with trie.???is trie the best way..plz provide me raw algo
to start with,

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] searching all matching words in a Trie with a given filter.

2013-05-29 Thread rahul sharma
@don u r searching in a previously built trie with the given filter...then
wat is this add fxn doing?correct me if m getting u wrng
On Wednesday, May 29, 2013, avinesh saini  wrote:
> Thank you Don, I was also trying in similar way. But here I'm confused
how you are storing the traversed words. Are you adding whole words at the
node on which word is ending during insertion.
>
>
> On Wed, May 29, 2013 at 12:36 AM, Don  wrote:
>>
>> void findWords(trie *root, char *filter)
>> {
>> if (!root) return;
>>
>> if (*filter == 0)  // When you reach the end of the filter at the
>> end of a valid word, add the word.
>> {
>> if (root->words) words.add(root->word);
>> }
>> else if (*filter == '.')   // Search for words with any letter
>> {
>> for(int i = 'a'; i <= 'z' ; ++i)
>> findWords(root->link[i], filter+1);
>> }
>> else  // Search for words with the required letter
>> {
>>  findWords(root->link[*filter], filter+1);
>> }
>> }
>>
>> On May 28, 4:47 am, avinesh saini  wrote:
>> > How to search all the matching words for a filter in a trie.
>> > e.g.
>> > searching by filter  "...r..m" will find all the words(of length = 7)
in
>> > trie in which 4th character is 'r' and 7th character is 'm'.
>> >
>> > --
>> > *
>> > *
>> > *thanks & regards,*
>> > *Avinesh
>> > *
>>
>> --
>> You received this message because you are subscribed to the Google
Groups "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send
an email to algogeeks+unsubscr...@googlegroups.com.
>>
>>
>
>
>
> --
>
> thanks & regards,
> Avinesh
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread rahul sharma
@don..you are counting in an integer only...correct if wrng?


On Wed, May 22, 2013 at 7:28 PM, Don  wrote:

> My program works with any numbers.
> Don
>
> On May 22, 3:45 am, Pramida Tumma  wrote:
> > This above program works only if the array contains consecutive numbers
> > starting from 1 to n. What to do if the array contains random numbers?
> >
> >
> >
> >
> >
> >
> >
> > On Fri, May 17, 2013 at 6:55 PM, Don  wrote:
> > > Counting the set bits in one integer is not the problem which was
> > > asked.
> > > However, I think that something like this is both faster and more easy
> > > to understand than what you have written:
> >
> > > int bitCount(unsigned int x)
> > > {
> > >int result = 0;
> > >while(x)
> > >{
> > >   if (x & 1) ++result;
> > >   x >>= 1;
> > >}
> > >return result;
> > > }
> >
> > > On May 17, 8:32 am, bhargav  wrote:
> > > > as bitwise operators are fast can count by following logic, works
> oly fr
> > > > +ve, just a tweak will make it to work with -ves also ..
> >
> > > > #include 
> > > > main() {
> > > > unsigned int x=12312,a;
> > > > a=x<<1;
> > > > //printf("%u",a);
> > > > int count=0;
> > > > while(x>0) {
> > > > a = x<<1;
> > > > //printf("%u \n",a);
> > > > if(a > > > count++;
> > > > x=a;}
> >
> > > > printf("%d\n",count );
> > > > getch();
> >
> > > > }
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an
> > > email to algogeeks+unsubscr...@googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] [Adobe]Generate all possible combinations (of r elements) inside an array of size N

2013-05-27 Thread rahul sharma
 Generate all possible combinations (of r elements) inside an array of size
N
E.g. arr [] = {2,8,14} All possible combinations of r=2 will be {2,8},
{8,14}, {14,2}

Asked in adobe

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread rahul sharma
@don...i got  it...its complexity is logn..how?


On Thu, May 23, 2013 at 11:10 AM, rahul sharma wrote:

> @don..you are counting in an integer only...correct if wrng?
>
>
> On Wed, May 22, 2013 at 7:28 PM, Don  wrote:
>
>> My program works with any numbers.
>> Don
>>
>> On May 22, 3:45 am, Pramida Tumma  wrote:
>> > This above program works only if the array contains consecutive numbers
>> > starting from 1 to n. What to do if the array contains random numbers?
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Fri, May 17, 2013 at 6:55 PM, Don  wrote:
>> > > Counting the set bits in one integer is not the problem which was
>> > > asked.
>> > > However, I think that something like this is both faster and more easy
>> > > to understand than what you have written:
>> >
>> > > int bitCount(unsigned int x)
>> > > {
>> > >int result = 0;
>> > >while(x)
>> > >{
>> > >   if (x & 1) ++result;
>> > >   x >>= 1;
>> > >}
>> > >return result;
>> > > }
>> >
>> > > On May 17, 8:32 am, bhargav  wrote:
>> > > > as bitwise operators are fast can count by following logic, works
>> oly fr
>> > > > +ve, just a tweak will make it to work with -ves also ..
>> >
>> > > > #include 
>> > > > main() {
>> > > > unsigned int x=12312,a;
>> > > > a=x<<1;
>> > > > //printf("%u",a);
>> > > > int count=0;
>> > > > while(x>0) {
>> > > > a = x<<1;
>> > > > //printf("%u \n",a);
>> > > > if(a> > > > count++;
>> > > > x=a;}
>> >
>> > > > printf("%d\n",count );
>> > > > getch();
>> >
>> > > > }
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "Algorithm Geeks" group.
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an
>> > > email to algogeeks+unsubscr...@googlegroups.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] least common ancestore bst

2013-05-27 Thread rahul sharma
then solution i posted aboive is correct in that case???plz comment


On Fri, May 17, 2013 at 9:49 AM, avinesh saini wrote:

> If one node is parent of other then Parent Node is lowest common ancestor.
> Source- http://en.wikipedia.org/wiki/Lowest_common_ancestor (just read it)
>
>
> On Mon, May 13, 2013 at 1:42 AM, rahul sharma wrote:
>
>> [image: BST_LCA]
>> what should be ancestor of 12 and 14.it should be 12 or
>> 14...if 12 then for 20 and 22 also it is 20...if 12 ans 14 has
>> ancestor as 8 then for 20 and 22 it is NULL.
>>
>> @allplz give me clear one line definition in case if one node is
>> parent of other then what is LCA
>>
>>
>> On Sun, Apr 21, 2013 at 10:32 PM, Tushar Patil 
>> wrote:
>>
>>> @rahul : It's fine solution, but can we check  the root->data == n1 ||
>>> n2 before calling function recursively, I think if we check this condition
>>> 1st it will reduce unnecessary function calls.
>>>Correct me if i am wrong?
>>> Thanks,
>>> Tushar Patil.
>>>
>>>
>>>
>>> On Sun, Apr 21, 2013 at 10:26 PM, rahul sharma 
>>> wrote:
>>>
>>>> int leastCommanAncestor(struct node* root, int n1, int n2)
>>>> {
>>>>  if(root==NULL)
>>>>  return -1;
>>>>  if(root->data>n1 && root->data>n2)
>>>>  return leastCommanAncestor(root->left,n1,n2);
>>>>  else if(root->datadata>>>  return leastCommanAncestor(root->right,n1,n2);
>>>>  return root->data;
>>>>
>>>> }
>>>>
>>>> Does this code miss any case?N suppose if we have to find LCA of n1 and
>>>> n2 and suppose n1 is parent of n2 ..then this will return n1..is this fyn
>>>> or if n1 is parent of n2 then we should return -1??
>>>>
>>>> Plz. comment
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>>
>>
>
>
>
> --
> *
> *
> *regards,*
> *Avinesh Kumar
> National Institute of Technology, Calicut.*
> *Kerala- 673601*
> *+91 7849080702*
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread rahul sharma
guys ..i got solution here
http://www.geeksforgeeks.org/program-to-count-number-of-set-bits-in-an-big-array/

plz tell how its complexity is logn.


On Fri, May 17, 2013 at 6:55 PM, Don  wrote:

> Counting the set bits in one integer is not the problem which was
> asked.
> However, I think that something like this is both faster and more easy
> to understand than what you have written:
>
> int bitCount(unsigned int x)
> {
>int result = 0;
>while(x)
>{
>   if (x & 1) ++result;
>   x >>= 1;
>}
>return result;
> }
>
> On May 17, 8:32 am, bhargav  wrote:
> > as bitwise operators are fast can count by following logic, works oly fr
> > +ve, just a tweak will make it to work with -ves also ..
> >
> > #include 
> > main() {
> > unsigned int x=12312,a;
> > a=x<<1;
> > //printf("%u",a);
> > int count=0;
> > while(x>0) {
> > a = x<<1;
> > //printf("%u \n",a);
> > if(a > count++;
> > x=a;}
> >
> > printf("%d\n",count );
> > getch();
> >
> >
> >
> >
> >
> >
> >
> > }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] lexographic permutations complexity

2013-05-27 Thread rahul sharma
following is code from geeks for geeks.
Please tell how the complexity of this in n*n!
n*n! times loop will be executed and then wat about the statements in
loop??
reference:-
http://www.geeksforgeeks.org/lexicographic-permutations-of-string/(second
method)

void reverse(char str[], int l, int h)
{
   while (l < h)
   {
   swap(&str[l], &str[h]);
   l++;
   h--;
   }
}

// Print all permutations of str in sorted order
void sortedPermutations ( char str[] )
{
// Get size of string
int size = strlen(str);

// Sort the string in increasing order
qsort( str, size, sizeof( str[0] ), compare );

// Print permutations one by one
bool isFinished = false;
while ( ! isFinished )
{
// print this permutation
printf ("%s \n", str);

// Find the rightmost character which is smaller than its next
// character. Let us call it 'first char'
int i;
for ( i = size - 2; i >= 0; --i )
   if (str[i] < str[i+1])
  break;

// If there is no such chracter, all are sorted in decreasing order,
// means we just printed the last permutation and we are done.
if ( i == -1 )
isFinished = true;
else
{
// Find the ceil of 'first char' in right of first character.
// Ceil of a character is the smallest character greater than it
int ceilIndex = findCeil( str, str[i], i + 1, size - 1 );

// Swap first and second characters
swap( &str[i], &str[ceilIndex] );

// reverse the string on right of 'first char'
reverse( str, i + 1, size - 1 );
}
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread rahul sharma
and how this is working
void init()
{
bitCount[0] = 0;
for(int i = 1; i < 65536; ++i) bitCount[i] = bitCount[i/2] + (i&1);
}
it is working fine..but plz tell the logic behind this


On Thu, May 23, 2013 at 11:12 AM, rahul sharma wrote:

>
> @don...i got  it...its complexity is logn..how?
>
>
> On Thu, May 23, 2013 at 11:10 AM, rahul sharma wrote:
>
>> @don..you are counting in an integer only...correct if wrng?
>>
>>
>> On Wed, May 22, 2013 at 7:28 PM, Don  wrote:
>>
>>> My program works with any numbers.
>>> Don
>>>
>>> On May 22, 3:45 am, Pramida Tumma  wrote:
>>> > This above program works only if the array contains consecutive numbers
>>> > starting from 1 to n. What to do if the array contains random numbers?
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, May 17, 2013 at 6:55 PM, Don  wrote:
>>> > > Counting the set bits in one integer is not the problem which was
>>> > > asked.
>>> > > However, I think that something like this is both faster and more
>>> easy
>>> > > to understand than what you have written:
>>> >
>>> > > int bitCount(unsigned int x)
>>> > > {
>>> > >int result = 0;
>>> > >while(x)
>>> > >{
>>> > >   if (x & 1) ++result;
>>> > >   x >>= 1;
>>> > >}
>>> > >return result;
>>> > > }
>>> >
>>> > > On May 17, 8:32 am, bhargav  wrote:
>>> > > > as bitwise operators are fast can count by following logic, works
>>> oly fr
>>> > > > +ve, just a tweak will make it to work with -ves also ..
>>> >
>>> > > > #include 
>>> > > > main() {
>>> > > > unsigned int x=12312,a;
>>> > > > a=x<<1;
>>> > > > //printf("%u",a);
>>> > > > int count=0;
>>> > > > while(x>0) {
>>> > > > a = x<<1;
>>> > > > //printf("%u \n",a);
>>> > > > if(a>> > > > count++;
>>> > > > x=a;}
>>> >
>>> > > > printf("%d\n",count );
>>> > > > getch();
>>> >
>>> > > > }
>>> >
>>> > > --
>>> > > You received this message because you are subscribed to the Google
>>> Groups
>>> > > "Algorithm Geeks" group.
>>> > > To unsubscribe from this group and stop receiving emails from it,
>>> send an
>>> > > email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>>
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread rahul sharma
@pramidathat can be done in 0(n)..lets say int takes 4 bytes
i will make and array of first 256 numbers ...
while finding for inte i will take a char pointer pointing to first byte
and then using array of 256 int i will count in that byte and increent
array and count in it.and so on...access all the 4 bits...0(1) to create
the first 256 numbers array and 0(n) to access array.hope m clear


On Wed, May 22, 2013 at 1:15 PM, Pramida Tumma wrote:

> This above program works only if the array contains consecutive numbers
> starting from 1 to n. What to do if the array contains random numbers?
>
>
> On Fri, May 17, 2013 at 6:55 PM, Don  wrote:
>
>> Counting the set bits in one integer is not the problem which was
>> asked.
>> However, I think that something like this is both faster and more easy
>> to understand than what you have written:
>>
>> int bitCount(unsigned int x)
>> {
>>int result = 0;
>>while(x)
>>{
>>   if (x & 1) ++result;
>>   x >>= 1;
>>}
>>return result;
>> }
>>
>> On May 17, 8:32 am, bhargav  wrote:
>> > as bitwise operators are fast can count by following logic, works oly fr
>> > +ve, just a tweak will make it to work with -ves also ..
>> >
>> > #include 
>> > main() {
>> > unsigned int x=12312,a;
>> > a=x<<1;
>> > //printf("%u",a);
>> > int count=0;
>> > while(x>0) {
>> > a = x<<1;
>> > //printf("%u \n",a);
>> > if(a> > count++;
>> > x=a;}
>> >
>> > printf("%d\n",count );
>> > getch();
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] Minimum number of coins to SUM to S

2013-05-27 Thread rahul sharma
Minimum of coins to sum s

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] least common ancestore bst

2013-05-16 Thread rahul sharma
[image: BST_LCA]
what should be ancestor of 12 and 14.it should be 12 or
14...if 12 then for 20 and 22 also it is 20...if 12 ans 14 has
ancestor as 8 then for 20 and 22 it is NULL.

@allplz give me clear one line definition in case if one node is parent
of other then what is LCA


On Sun, Apr 21, 2013 at 10:32 PM, Tushar Patil wrote:

> @rahul : It's fine solution, but can we check  the root->data == n1 || n2
> before calling function recursively, I think if we check this condition 1st
> it will reduce unnecessary function calls.
>   Correct me if i am wrong?
> Thanks,
> Tushar Patil.
>
>
>
> On Sun, Apr 21, 2013 at 10:26 PM, rahul sharma wrote:
>
>> int leastCommanAncestor(struct node* root, int n1, int n2)
>> {
>>  if(root==NULL)
>>  return -1;
>>  if(root->data>n1 && root->data>n2)
>>  return leastCommanAncestor(root->left,n1,n2);
>>  else if(root->datadata>  return leastCommanAncestor(root->right,n1,n2);
>>  return root->data;
>>
>> }
>>
>> Does this code miss any case?N suppose if we have to find LCA of n1 and
>> n2 and suppose n1 is parent of n2 ..then this will return n1..is this fyn
>> or if n1 is parent of n2 then we should return -1??
>>
>> Plz. comment
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] Next higher number with same number of set bits

2013-05-12 Thread rahul sharma
unsigned snoob(unsigned x) {
unsigned smallest, ripple, ones;
// x = xxx0  
smallest = x & -x; //  0001 
ripple = x + smallest; // xxx1  
ones = x ^ ripple; // 0001  
ones = (ones >> 2)/smallest; //   0111
return ripple | ones; // xxx1  0111
}


please expalin the reason for right shifting by 2Although results are
coming ok..but
wats the logic behind this..


Plz comment.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] count number of set bits in an (big) array (Asked in Google interview)

2013-05-12 Thread rahul sharma
I was searching for google questions and got this question.Use look up to
do it in bext way


What is best time complexity for this..
plz post algo too

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] MS written Reasoning question

2013-05-03 Thread rahul sharma
@ashish...4 all selected...remaining 2 to be selected..1 m,ba 1
betch makes one 2 mba and 1 mca...but as it is not only option coz we can
put 2 mcas at 2 remaing pos so this is not true...3 are ignored 4th must be
true..


On Mon, Apr 29, 2013 at 7:37 AM, ashish gupta wrote:

> Ans is  1 M.A + 2 B.Tech + 2 MBA + 1 MCA.
>
> Explanation:
>
> (1) Exactly one must be an MA.
> (2) Given: "2 b.tech are seleceted" and the statement "if at least one
> btech is selected then exactly 2 MBA are selected (vice versa condition)"
> So exactly 2 MBA will be selected.
> (3) Remaining 1 would be MCA.
>
>
> So ans would be (d)
>
> option (b) is not correct as it says that only 2 mba and only 1 mca are
> selected but the total no of selected candidates are 6.
>
> --
> Ashish
>
>
> On Fri, Apr 26, 2013 at 11:32 PM, rahul sharma wrote:
>
>> 10 candidates appear for an interview and 6 selected.
>> 2-M.A
>> 2-MCA
>> 4-BTECH
>>  2-MBA.
>> If at least one MBA is selected then exactly 2 btech are selected and
>> vice versa.
>> Of six candidates,exactly one must be an MA cndidate
>>
>> question:- which of the following statementsis definitely true:,if 2
>> btech are selected:
>>
>> a- two mca and 2 ma are selected.
>> b- only 2 mbas and  only one mca is selected
>> c-one MBA and two MAs are selected.
>> d- Two MBAs are selected.
>>
>>
>> My approach:- we are with 2 btech,one ma,one mba
>>
>> remaining two can be 1 mba+1mca
>> or 2 mcas
>>
>> But correct option is d.
>> How is this definitely true and b is not??
>> plz comment
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] MS written Reasoning question

2013-04-28 Thread rahul sharma
10 candidates appear for an interview and 6 selected.
2-M.A
2-MCA
4-BTECH
2-MBA.
If at least one MBA is selected then exactly 2 btech are selected and vice
versa.
Of six candidates,exactly one must be an MA cndidate

question:- which of the following statementsis definitely true:,if 2 btech
are selected:

a- two mca and 2 ma are selected.
b- only 2 mbas and  only one mca is selected
c-one MBA and two MAs are selected.
d- Two MBAs are selected.


My approach:- we are with 2 btech,one ma,one mba

remaining two can be 1 mba+1mca
or 2 mcas

But correct option is d.
How is this definitely true and b is not??
plz comment

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Find the number of islands/connected components

2013-04-26 Thread rahul sharma
got the islands...but first we scan each element then also dfs for them if
all are 1..then how it can be o(row*col)...plz explain me complexity ofr
this


On Fri, Apr 26, 2013 at 2:07 PM, atul anand  wrote:

> {*1*,* 1*, 0, 0, 0},
> {0, *1*, 0, 0, *1*
> },
> {*1*, 0, 0, *1*, *1*},
> {0, 0, 0, 0, 0},
> {*1*, 0, *1*, 0, *1*}
>
> above different set of color represent different island.Simple DFS is used to 
> find all the island
>
>
>
> On Fri, Apr 26, 2013 at 3:11 AM, Don  wrote:
>
>> The complexity is still O(ROWS*COLS) because each location in the
>> matrix will be visited once by the loop and once by DFS. Once a
>> location has been visited by DFS, it is marked as visited and can't be
>> visited again.
>> Don
>>
>> On Apr 25, 5:11 pm, rahul sharma  wrote:
>> > What will be complexity if all elements in matrix are 1..
>> >
>> > when first dfs will call then all matrix will be scanned setting each
>> > element to visited...
>> > then again loop contiues to scan all the elements..plz explain
>> >
>> > On Thu, Apr 11, 2013 at 2:04 AM, rahul sharma > >wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > {*1*,* 1*, 0, 0, 0},
>> > > {0, *1*, 0, 0, *1*},
>> > > {*1*, 0, 0, *1*, *1*},
>> > > {0, 0, 0, 0, 0},
>> > > {*1*, 0, *1*, 0, *1*}
>> >
>> > > Can anybody eplain how there are 5 islands in above matrix..thnx in
>> advance
>> >
>> > > source:-http://www.geeksforgeeks.org/find-number-of-islands/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Find the number of islands/connected components

2013-04-25 Thread rahul sharma
What will be complexity if all elements in matrix are 1..

when first dfs will call then all matrix will be scanned setting each
element to visited...
then again loop contiues to scan all the elements..plz explain


On Thu, Apr 11, 2013 at 2:04 AM, rahul sharma wrote:

> {*1*,* 1*, 0, 0, 0},
> {0, *1*, 0, 0, *1*},
> {*1*, 0, 0, *1*, *1*},
> {0, 0, 0, 0, 0},
> {*1*, 0, *1*, 0, *1*}
>
>
> Can anybody eplain how there are 5 islands in above matrix..thnx in advance
>
> source:-http://www.geeksforgeeks.org/find-number-of-islands/
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Find the number of islands/connected components

2013-04-25 Thread rahul sharma
@don..can u plz tell me how the complexity of this
http://www.geeksforgeeks.org/find-number-of-islands/ is ROW*COL?


On Thu, Apr 11, 2013 at 4:35 PM, rahul sharma wrote:

>
> M not getting matrix..is it adjacencyif simple 1 means connected
> components then first wehave 3 ones..then in second line 3 ones form 1 more
> island..hw in last row 3 islands are formed..these are 3 1 means three
> independent nodes...m I ryt?
>
> On Thursday, April 11, 2013, Arpit Sood  wrote:
> > islands are five as for each cell we assume all surrounding positions to
> be connected... so if coordinates are (x,y) then it is connected to (x+1,
> y), (x-1, y), (x+1, y+1), (x-1, y+1), (x+1, y-1), (x-1, y-1), (x, y-1), (x,
> y+1
> >
> >
> > On Thu, Apr 11, 2013 at 9:35 AM, rahul sharma 
> wrote:
> >>
> >> I didnt get..plz explain more...thnx
> >>
> >> On Thursday, April 11, 2013, Don  wrote:
> >> > Reformatting to make it easier to see:
> >> >
> >> > 11000
> >> > 01001
> >> > 10011
> >> > 0
> >> > 10101
> >> >
> >> > In this case an "island" is any set of "1's" which are connected
> >> > vertically, horizontally, or diagonally.
> >> > So the five islands are
> >> >
> >> > 11000
> >> > 01002
> >> > 10022
> >> > 0
> >> > 30405
> >> >
> >> > Don
> >> >
> >> > On Apr 10, 4:34 pm, rahul sharma  wrote:
> >> >> {*1*,* 1*, 0, 0, 0},
> >> >> {0, *1*, 0, 0, *1*},
> >> >> {*1*, 0, 0, *1*, *1*},
> >> >> {0, 0, 0, 0, 0},
> >> >> {*1*, 0, *1*, 0, *1*}
> >> >>
> >> >> Can anybody eplain how there are 5 islands in above matrix..thnx in
> advance
> >> >>
> >> >> source:-http://www.geeksforgeeks.org/find-number-of-islands/
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> >> > To unsubscribe from this group and stop receiving emails from it,
> send an email to algogeeks+unsubscr...@googlegroups.com.
> >> > For more options, visit https://groups.google.com/groups/opt_out.
> >> >
> >> >
> >> >
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an email to algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit https://groups.google.com/groups/opt_out.
> >>
> >>
> >
> >
> >
> > --
> > Regards,
> > Arpit Sood
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> >
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Median of two sorted arrays of different sizes

2013-04-24 Thread rahul sharma
IS this code correct?

float findMedianUtil( int A[], int N, int B[], int M )
{
// If the smaller array has only one element
if( N == 1 )
{
// Case 1: If the larger array also has one element, simply call MO2()
if( M == 1 )
return MO2( A[0], B[0] );

// Case 2: If the larger array has odd number of elements, then consider
// the middle 3 elements of larger array and the only element of
// smaller array. Take few examples like following
// A = {9}, B[] = {5, 8, 10, 20, 30} and
// A[] = {1}, B[] = {5, 8, 10, 20, 30}
if( M & 1 )
return MO2( B[M/2], MO3(A[0], B[M/2 - 1], B[M/2 + 1]) );

// Case 3: If the larger array has even number of element, then median
// will be one of the following 3 elements
// ... The middle two elements of larger array
// ... The only element of smaller array
return MO3( B[M/2], B[M/2 - 1], A[0] );
}

// If the smaller array has two elements
else if( N == 2 )
{
// Case 4: If the larger array also has two elements, simply call MO4()
if( M == 2 )
return MO4( A[0], A[1], B[0], B[1] );

// Case 5: If the larger array has odd number of elements, then median
// will be one of the following 3 elements
// 1. Middle element of larger array
// 2. Max of first element of smaller array and element just
//before the middle in bigger array
// 3. Min of second element of smaller array and element just
//after the middle in bigger array
if( M & 1 )
return MO3 ( B[M/2],
 max( A[0], B[M/2 - 1] ),
 min( A[1], B[M/2 + 1] )
   );

// Case 6: If the larger array has even number of elements, then
// median will be one of the following 4 elements
// 1) & 2) The middle two elements of larger array
// 3) Max of first element of smaller array and element
//just before the first middle element in bigger array
// 4. Min of second element of smaller array and element
//just after the second middle in bigger array
return MO4 ( B[M/2],
 B[M/2 - 1],
 max( A[0], B[M/2 - 2] ),
 min( A[1], B[M/2 + 1] )
   );
}

int idxA = ( N - 1 ) / 2;
int idxB = ( M - 1 ) / 2;

 /* if A[idxA] <= B[idxB], then median must exist in
A[idxA] and B[idxB] */
if( A[idxA] <= B[idxB] )
return findMedianUtil( A + idxA, N / 2 + 1, B, M - idxA );

/* if A[idxA] > B[idxB], then median must exist in
   A[...idxA] and B[idxB] */
return findMedianUtil( A, N / 2 + 1, B + idxA, M - idxA );
}

In the end I suspect the following part:-

  if( A[idxA] <= B[idxB] )
return findMedianUtil( A + idxA, N / 2 + 1, B, M - idxA );

/* if A[idxA] > B[idxB], then median must exist in
   A[...idxA] and B[idxB] */
return findMedianUtil( A, N / 2 + 1, B + idxA, M - idxA );

plz comment

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: least common ancestore bst

2013-04-21 Thread rahul sharma
I am not clear about the definition.Plz confirm in case one node is parent
of other then whether that parent node is ancestor or it is -1.And plz
confirm above code if it miss any case


On Mon, Apr 22, 2013 at 1:13 AM, Dave  wrote:

> @Rahul: You must know if a node is its own ancestor or not. This is a
> matter of definition.
>
> If a node is its own ancestor, and if n1 is an ancestor of n2, then n1 is
> the least common ancestor of n1 and n2.
>
> If a node is not its own ancestor, and if n1 is an ancestor of n2, then
> the parent of n1 is the least common ancestor.
>
> It seems that common usage is that a node is its own ancestor; see, e.g.,
> http://en.wikipedia.org/wiki/Lowest_common_ancestor.
>
> Dave
>
> On Sunday, April 21, 2013 11:56:01 AM UTC-5, rahul sharma wrote:
>
>> int leastCommanAncestor(struct node* root, int n1, int n2)
>> {
>>  if(root==NULL)
>>  return -1;
>>  if(root->data>n1 && root->data>n2)
>>  return leastCommanAncestor(root->**left,n1,n2);
>>  else if(root->datadata>  return leastCommanAncestor(root->**right,n1,n2);
>>  return root->data;
>>
>> }
>>
>> Does this code miss any case?N suppose if we have to find LCA of n1 and
>> n2 and suppose n1 is parent of n2 ..then this will return n1..is this fyn
>> or if n1 is parent of n2 then we should return -1??
>>
>> Plz. comment
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] least common ancestore bst

2013-04-21 Thread rahul sharma
int leastCommanAncestor(struct node* root, int n1, int n2)
{
 if(root==NULL)
 return -1;
 if(root->data>n1 && root->data>n2)
 return leastCommanAncestor(root->left,n1,n2);
 else if(root->datadataright,n1,n2);
 return root->data;

}

Does this code miss any case?N suppose if we have to find LCA of n1 and n2
and suppose n1 is parent of n2 ..then this will return n1..is this fyn or
if n1 is parent of n2 then we should return -1??

Plz. comment

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Interview Question

2013-04-19 Thread rahul sharma
search the previous posts before posting

search for
[algogeeks] Amazon Interview Question
you will get this

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: algorithm to sort based on frequency.

2013-04-16 Thread rahul sharma
Can anyone give me example using hash+linked list method ..although i got
dave method.but still...


On Tue, Apr 16, 2013 at 8:58 PM, Dave  wrote:

> @Varun: Here is an algorithm using sorting only:
>
> 1. Append an index onto each number, so your example becomes {{4,0},
> {3,1}, {2,2}, etc.}
>
> 2. Sort the numbers and their associated indices into ascending order by
> number. Your example becomes {{2,2}, {2,6}, {3,1}, {4,0}, {4,4}, etc.}. If
> the sort is not stable, the indices on equal numbers may not be in order,
> as I've shown here, but that doesn't matter. It will be taken care of in
> the next step.
>
> 3. Scan the array, and collapse every sequence of adjacent entries with
> equal numbers into one entry with the lowest index, and append the
> frequency to the entry. Your example becomes {{2,2,2}, {3,1,1}, {4,0,2},
> etc.}
>
> 4. Sort the array with frequency as the primary key and index as the
> secondary key. You get {{4,0,2}, {2,2,2}, {6,5,2}, {3,1,1}, {5,1,3}}.
>
> 5. Reexpand the array by repeating each number according to its frequency,
> giving {4,4,2,2,6,6,3,5}.
>
> Dave
>
> On Wednesday, February 1, 2012 2:58:43 AM UTC-6, Varun wrote:
>
>> I was asked this question sometime during an interview.
>>
>> WE have an array of known length. The elements in array can be repetitive.
>> now sort the array based on frequency of occurrence of each element in
>> array.
>> Eg: a= {4.3.2.5.4.6.2.6}
>> after sorting a={4,4,2,2,6,6,3,5}
>>
>> 4,2,6 all occurs twice, in this case retain the order in which they
>> appeared in original array.
>> I was able to give a solution using hashing the elements of the array to
>> a new array, and if hash matches, incrementing the count, and then sort the
>> hash values. Later, re scan the array to retain the order in case there's a
>> match in frequency of any two element.
>>
>> Looking for better alternatives.
>> Please pour in.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: algorithm to sort based on frequency.

2013-04-16 Thread rahul sharma
@don.can u plz explain with example.


On Wed, Feb 1, 2012 at 9:29 PM, Don  wrote:

> Build a hashmap with the array value as a key mapping to a struct
> which contains the key, frequency, and location of first occurance.
> Then sort the hashed elements comparing first by frequency and
> breaking ties based on first occurance. Then iterate through the
> sorted elements and fill in the array. All steps are O(n) except for
> the sort, so the overall complexity is O(n*log n).
> Don
>
> On Feb 1, 2:58 am, Varun  wrote:
> > I was asked this question sometime during an interview.
> >
> > WE have an array of known length. The elements in array can be
> repetitive.
> > now sort the array based on frequency of occurrence of each element in
> > array.
> > Eg: a= {4.3.2.5.4.6.2.6}
> > after sorting a={4,4,2,2,6,6,3,5}
> >
> > 4,2,6 all occurs twice, in this case retain the order in which they
> > appeared in original array.
> > I was able to give a solution using hashing the elements of the array to
> a
> > new array, and if hash matches, incrementing the count, and then sort the
> > hash values. Later, re scan the array to retain the order in case
> there's a
> > match in frequency of any two element.
> >
> > Looking for better alternatives.
> > Please pour in.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] MS interview question

2013-04-14 Thread rahul sharma
Suppose you are given a string IAMABOY

and a dictionary then divide it into I AM A BOY if it is possible to break
form as many dictionary words from a string giveM able to solve it..but
how if we are given a string like IXAFGMJAHBDSOXDY.

how can we form I AM A BOY..will be done in Opower(2,n)..for every
character we consider it and not and form 2 ways...plz anyone shre the code
for this approach...if the word is not a cotiguous subarray..

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] inplace m*n transpose

2013-04-12 Thread rahul sharma
in this there are permutation cycles which are used to do transpose.can
anybody tell me

nl = (ol x R) mod (N-1)

nl- new location

ol- old location

N-total elements

if i is current element then it will be placed at new location

next = (i*r)%size;

r- no. of rows

please explain how it works logically?i did nt get this


source:-http://www.geeksforgeeks.org/inplace-m-x-n-size-matrix-transpose/

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Find the number of islands/connected components

2013-04-11 Thread rahul sharma
M not getting matrix..is it adjacencyif simple 1 means connected
components then first wehave 3 ones..then in second line 3 ones form 1 more
island..hw in last row 3 islands are formed..these are 3 1 means three
independent nodes...m I ryt?
On Thursday, April 11, 2013, Arpit Sood  wrote:
> islands are five as for each cell we assume all surrounding positions to
be connected... so if coordinates are (x,y) then it is connected to (x+1,
y), (x-1, y), (x+1, y+1), (x-1, y+1), (x+1, y-1), (x-1, y-1), (x, y-1), (x,
y+1
>
>
> On Thu, Apr 11, 2013 at 9:35 AM, rahul sharma 
wrote:
>>
>> I didnt get..plz explain more...thnx
>>
>> On Thursday, April 11, 2013, Don  wrote:
>> > Reformatting to make it easier to see:
>> >
>> > 11000
>> > 01001
>> > 10011
>> > 0
>> > 10101
>> >
>> > In this case an "island" is any set of "1's" which are connected
>> > vertically, horizontally, or diagonally.
>> > So the five islands are
>> >
>> > 11000
>> > 01002
>> > 10022
>> > 0
>> > 30405
>> >
>> > Don
>> >
>> > On Apr 10, 4:34 pm, rahul sharma  wrote:
>> >> {*1*,* 1*, 0, 0, 0},
>> >> {0, *1*, 0, 0, *1*},
>> >> {*1*, 0, 0, *1*, *1*},
>> >> {0, 0, 0, 0, 0},
>> >> {*1*, 0, *1*, 0, *1*}
>> >>
>> >> Can anybody eplain how there are 5 islands in above matrix..thnx in
advance
>> >>
>> >> source:-http://www.geeksforgeeks.org/find-number-of-islands/
>> >
>> > --
>> > You received this message because you are subscribed to the Google
Groups "Algorithm Geeks" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
an email to algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google
Groups "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send
an email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
>
> --
> Regards,
> Arpit Sood
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Find the number of islands/connected components

2013-04-10 Thread rahul sharma
I didnt get..plz explain more...thnx

On Thursday, April 11, 2013, Don  wrote:
> Reformatting to make it easier to see:
>
> 11000
> 01001
> 10011
> 0
> 10101
>
> In this case an "island" is any set of "1's" which are connected
> vertically, horizontally, or diagonally.
> So the five islands are
>
> 11000
> 01002
> 10022
> 0
> 30405
>
> Don
>
> On Apr 10, 4:34 pm, rahul sharma  wrote:
>> {*1*,* 1*, 0, 0, 0},
>> {0, *1*, 0, 0, *1*},
>> {*1*, 0, 0, *1*, *1*},
>> {0, 0, 0, 0, 0},
>> {*1*, 0, *1*, 0, *1*}
>>
>> Can anybody eplain how there are 5 islands in above matrix..thnx in
advance
>>
>> source:-http://www.geeksforgeeks.org/find-number-of-islands/
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Interview question

2013-04-10 Thread rahul sharma
M is number of rows n n is col..outer 2 loops are running n times and inner
is for kadane m tymes n for temp m times total 2m...so isnt it should be
n*n*m?
On Thursday, April 11, 2013, Don  wrote:
> M is a matrix, not a number. M is NxN, so the algorithm is O(N^3) as
> stated in the text.
>
> On Apr 10, 4:19 pm, rahul sharma  wrote:
>> isnt the complexity should be o(m*n*n) instead of (n*n*n) as m can be
>> greater than n..plz comment
>>
>> On Wed, Apr 10, 2013 at 10:11 PM, rahul sharma wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> >http://www.geeksforgeeks.org/dynamic-programming-set-27-max-sum-recta...
>>
>> > wat is complexity of thisn3  or mn2
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Find the number of islands/connected components

2013-04-10 Thread rahul sharma
{*1*,* 1*, 0, 0, 0},
{0, *1*, 0, 0, *1*},
{*1*, 0, 0, *1*, *1*},
{0, 0, 0, 0, 0},
{*1*, 0, *1*, 0, *1*}


Can anybody eplain how there are 5 islands in above matrix..thnx in advance

source:-http://www.geeksforgeeks.org/find-number-of-islands/

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Interview question

2013-04-10 Thread rahul sharma
isnt the complexity should be o(m*n*n) instead of (n*n*n) as m can be
greater than n..plz comment


On Wed, Apr 10, 2013 at 10:11 PM, rahul sharma wrote:

>
> http://www.geeksforgeeks.org/dynamic-programming-set-27-max-sum-rectangle-in-a-2d-matrix/
>
> wat is complexity of thisn3  or mn2
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Interview question

2013-04-10 Thread rahul sharma
http://www.geeksforgeeks.org/dynamic-programming-set-27-max-sum-rectangle-in-a-2d-matrix/

wat is complexity of thisn3  or mn2

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Trie | (Insert and Search)

2013-04-10 Thread rahul sharma
M asking in case of DELETE from trie fxn


On Wed, Apr 10, 2013 at 9:15 PM, rahul sharma wrote:

> http://www.geeksforgeeks.org/trie-insert-and-search/
>
> Can any body tell me what is need of checking pcrawl!=0 int the
> return..cant we check only its value>0 to check whether its a leaf node
>
> return (0 != pCrawl && pCrawl->value);
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Trie | (Insert and Search)

2013-04-10 Thread rahul sharma
http://www.geeksforgeeks.org/trie-insert-and-search/

Can any body tell me what is need of checking pcrawl!=0 int the
return..cant we check only its value>0 to check whether its a leaf node

return (0 != pCrawl && pCrawl->value);

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread rahul sharma
If you have any other solution ..please post that...i thnik recursion is ok
with base case...we need to scan again after first iteration...??


On Wed, Apr 10, 2013 at 12:12 AM, rahul sharma wrote:

> i forgot to add base case..can add wen 2 elemnts are there then there sum
> is stored and we reurn from there...i m in hurry,,,sry for that,,
>
>
> On Wed, Apr 10, 2013 at 12:11 AM, Don  wrote:
>
>> It is O(N^2) because the inner loop takes N steps to execute and that
>> loop will be executed N times.
>>
>> However, I would suggest not using recursion. There is no reason to
>> not do it iteratively. Your recursive solution has no base case so it
>> will recurse until your computer runs out of stack space, at which
>> point it will crash.
>>
>> Don
>>
>> On Apr 9, 2:29 pm, rahul sharma  wrote:
>> >  A = {5, 3, 8, 9, 16}
>> > After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
>> > After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
>> > Given an array, return sum after n iterations
>> >
>> > my sol/
>> > void abc(int arr[],n)
>> > {
>> > for(i=0;i> > arr[i]=arr[i+1]-arr[i];
>> > abc(arr,n-1);
>> >
>> > }
>> >
>> > I wana ask that the complexity is o(n) or o(n)2..as loop is
>> executed n
>> > times..say n is 10...so fxn is called 10 timesi.e  10 n..and
>> ignoring n
>> > it comes out to be...n..but if we implemeted with 2 loops then
>> > complexity is n2 ...and both sol are taking same no of
>> iterations...please
>> > tell whether complexity is n or n2 for above codeif it is n2 then
>> how???
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread rahul sharma
i forgot to add base case..can add wen 2 elemnts are there then there sum
is stored and we reurn from there...i m in hurry,,,sry for that,,


On Wed, Apr 10, 2013 at 12:11 AM, Don  wrote:

> It is O(N^2) because the inner loop takes N steps to execute and that
> loop will be executed N times.
>
> However, I would suggest not using recursion. There is no reason to
> not do it iteratively. Your recursive solution has no base case so it
> will recurse until your computer runs out of stack space, at which
> point it will crash.
>
> Don
>
> On Apr 9, 2:29 pm, rahul sharma  wrote:
> >  A = {5, 3, 8, 9, 16}
> > After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
> > After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
> > Given an array, return sum after n iterations
> >
> > my sol/
> > void abc(int arr[],n)
> > {
> > for(i=0;i > arr[i]=arr[i+1]-arr[i];
> > abc(arr,n-1);
> >
> > }
> >
> > I wana ask that the complexity is o(n) or o(n)2..as loop is executed
> n
> > times..say n is 10...so fxn is called 10 timesi.e  10 n..and
> ignoring n
> > it comes out to be...n..but if we implemeted with 2 loops then
> > complexity is n2 ...and both sol are taking same no of
> iterations...please
> > tell whether complexity is n or n2 for above codeif it is n2 then
> how???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Amazon interview question

2013-04-09 Thread rahul sharma
 A = {5, 3, 8, 9, 16}
After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
Given an array, return sum after n iterations

my sol/
void abc(int arr[],n)
{
for(i=0;ihttps://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Dlete Linked List

2013-04-09 Thread rahul sharma
sory..following is correct code
void deleteList(struct node** head)
{
   /* deref head_ref to get the real head */
 struct node* next;

   while (*head != NULL)
   {
   next = *head->next;
   free(next);
   *head = next;
   }


}


On Tue, Apr 9, 2013 at 9:27 PM, Don  wrote:

> "head" is not even declared, so I doubt that it would compile.
> I believe that you want to free head, not next.
>
>
> On Apr 9, 11:31 am, rahul sharma  wrote:
> >  Is the following code correct for linked list deletion or i need to copy
> > head in some tem. pointer and dlete and theninitialize head to NULLL.Plz
> > comment
> >  void deleteList(struct node** head_ref)
> >  {
> > /* deref head_ref to get the real head */
> >   struct node* next;
> >
> >while (*head != NULL)
> > {
> > next = *head->next;
> > free(next);
> > *head = next;
> > }
> >
> >  }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Median in stream of running integers

2013-03-24 Thread rahul sharma
So we need to implement prelocate down for deletion?

On Sunday, March 24, 2013, atul anand  wrote:
> yeah implementation is wrong.
>
> On 3/24/13, tec  wrote:
>> The heap implementation is wrong to only prelocate up on deletion top.
>> 15
>>   /\
>>   14  13
>>  /  \/  \
>>1211109
>>/\/\/\/\
>>   8  7  6  5  4  3  2  1
>> For example, for the above heap, when deleteTop is called, 1 is moved to
>> top, and heaplify is called on node 9, which does nothing and leave the
>> heap in an invalid state.
>>
>> Comapring l and r child to find maximum/minimum is only needed in
prelocate
>> down, not in prelocate up.
>>
>>
>> 2013/3/24 rahul sharma 
>>
>>> And also in heapify y we r not comapring l and r chid to find maximum?
>>>
>>>
>>> On Sun, Mar 24, 2013 at 6:07 PM, rahul sharma
>>> wrote:
>>>
>>>> I was goin thorugh question on this link
>>>>
http://www.geeksforgeeks.org/median-of-stream-of-integers-running-integers/
>>>> My doubt is y we uses prelocate up in case of deletion also.In deletion
>>>> we use pre locate down.But y here we used pre locate up..plz
xplain.thnx
>>>> in
>>>> advance
>>>>
>>>> // Heapification
>>>>  // Note that, for the current median tracing problem
>>>>  // we need to heapify only towards root, always
>>>>  void heapify(int i)
>>>>  {
>>>>  int p = parent(i);
>>>>
>>>> // comp - differentiate MaxHeap and MinHeap
>>>>  // percolates up
>>>>  if( p >= 0 && comp(A[i], A[p]) )
>>>>  {
>>>>  Exch(A[i], A[p]);
>>>>  heapify(p);
>>>>  }
>>>>  }
>>>>
>>>>  int deleteTop()
>>>>  {
>>>>  int del = -1;
>>>>
>>>> if( heapSize > -1)
>>>>  {
>>>>  del = A[0];
>>>>
>>>> Exch(A[0], A[heapSize]);
>>>>  heapSize--;
>>>>  heapify(parent(heapSize+1));
>>>>  }
>>>>
>>>> return del;
>>>>  }
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
Groups
>>> "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
an
>>> email to algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>> --
>> __
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] [Off topic] Call for Moderators for Algogeeks

2013-03-14 Thread rahul sharma
You mean one who can provide solutions to the pending questions or some
type of management of group like the type of posts and off topic??

On Wed, Mar 13, 2013 at 11:25 PM, shady  wrote:

> Hi,
> Does anyone wants to be moderator ? We want someone who is actively
> participating in discussions and can frequently check the pending tasks for
> moderation.
>
> Shady
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: trie implementation

2013-03-14 Thread rahul sharma
On Thursday, March 14, 2013, rahul sharma  wrote:
> Can anybody provide any link me to understand t9 implementation? I dnt
need code..I need how to implement t9 with trie with explanation..thnx in
advance

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] trie implementation

2013-03-14 Thread rahul sharma
Can anybody provide me to understand t9 implementation? I dnt need code..I
need how to implement t9 with trie with explanation..thnx in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Compiler doubt

2013-01-22 Thread rahul sharma
S->aAbB\bAaB\e


A->S
B->s



Find follow(A) and follow(B)???explanation required??thnx in advance

-- 




[algogeeks] B-Tree

2013-01-01 Thread rahul sharma
IF btree is of order n,then what is min nuber of values at each node
Is it floor(n/2)
a
I read if oreder is 5 then min values in each node is 2...SO is it
floor(n/2)

-- 




[algogeeks] DBMS gate 2012 query

2012-12-27 Thread rahul sharma
HI
please explain the following question no: 2 on below link as i am not able
to copy it.

http://www.geeksforgeeks.org/database-management-system-set-3/

-- 




Re: [algogeeks] Re: adobe apti question

2012-12-16 Thread rahul sharma
I got it from aomewhr .answer given is e...
E option is wrng as per my opinion..
It should be 1&3 or 2&3 instead of 1&2or2&3

am i ryt?

On Mon, Dec 17, 2012 at 12:03 AM, Shubham Sandeep <
s.shubhamsand...@gmail.com> wrote:

> according to me option c holds
> Reason:it is either that F&G or E&H pair occurs but both pairs cannot
> occur as one is an oucome of B while other holds if C occurs. since either
> B or C (but not both) may follow A... so point prooved. but D will always
> be there weather B or C follows after A.
> since "must occur" is asked my answer is option C
>
>
> On Sun, Dec 16, 2012 at 11:39 PM, marti  wrote:
>
>> Yes I feel (e) is the right option.
>>
>>
>> On Sunday, December 16, 2012 11:18:57 PM UTC+5:30, rahul sharma wrote:
>>>
>>> A causes B or C, but not both
>>> F occurs only if B occurs
>>> D occurs if B or C occurs
>>> E occurs only if C occurs
>>> J occurs only if E or F occurs
>>> D causes G,H or both
>>> H occurs if E occurs
>>> G occurs if F occurs
>>>
>>> 6. If A occurs which of the following must occurs
>>>
>>> I. F and G
>>> II. E and H
>>> III. D
>>>
>>> (a) I only
>>> (b) II only
>>> (c) III only
>>> (d) I,II, & III
>>> (e) I & II (or) II & III but not both
>>>
>>> Ans. (e)
>>> E option should be 1&111  or 11&3
>>> am i ryt???
>>> A-> b or c.
>>> if A->Bthen B->f&g   and Delse if A->C   ,then   c->e&h and c->d
>>>
>>> am i ryt
>>>
>>  --
>>
>>
>>
>
>
>
> --
> Regards,
> SHUBHAM SANDEEP
> IT 3rd yr.
> NIT ALD.
>
>  --
>
>
>

-- 




Re: [algogeeks] C o/p adobe

2012-11-16 Thread rahul sharma
ok..thnxi got it.your r ryt n i m ryt too:)..thnx

On Fri, Nov 16, 2012 at 11:54 PM, Neeraj Gangwar wrote:

> Ignore last to last mail. Sorry. Do show expanded content in last mail.
> On 16 Nov 2012 23:49, "Neeraj Gangwar"  wrote:
>
>> Yes, it would be like copying the code in the other file. You have to
>> find a way to do it in Dev-C++.
>> In linux it's simple. Just use *gcc file1.c file2.c *in terminal (as
>> told earlier).
>>
>> If you are still confused, Think it this way
>> If you are compiling only one file in which you have declared variable as
>> intern, where would compiler find its actual definition because you are *not
>> compiling *the second file.
>>
>> *file1.c : file in which variable is defined*
>> *file2.c : file in which variable is declared as extern*
>> *
>> *
>> When you compile both the files together, as compiler sees *extern 
>> *declaration,
>> it will check if you have defined that variable somewhere. It will only
>> check files that are being compiled*. So if you are not compiling *file1.c
>> *it will not check that file. That's why you have to compile both the
>> files together.
>>
>> In simple words, what extern does is that it checks if you have defined
>> that variable somewhere* in the code that is *being compiled. *
>>
>> Try following codes
>> *//start of code*
>> *#include*
>> *main() {*
>>
>> *extern int i;*
>> *printf("i = %d", i);*
>> *return 0;*
>>
>> *}*
>> *//end of code*
>> It will show you an error that variable i has not been defined anywhere
>> in the file.
>> *
>> *
>> *//start of code*
>> *#include*
>> *main() {*
>>
>> *extern int i;*
>> *printf("i = %d", i);*
>> *return 0;*
>>
>> *}*
>> *
>> *
>> *int i = 7;*
>> *// end of code*
>> Try above code, it will run and show you the correct result. Your codes
>> are doing precisely the same thing.
>>
>> *#include "file1.c"* or *#include "file2.c"* was based on the same idea.
>>
>> *scope rules apply.
>>
>> Some lines of *the* book The C Programming Language by Dennis Ritchie:
>> There must be only one definition of an external variable among all the
>> files *that make up the*
>> *source program*; other files may contain extern declarations to access
>> it. (There may also be
>> extern declarations in the file containing the definition.) Array sizes
>> must be specified with
>> the definition, but are optional with an extern declaration.
>>
>>
>> *Neeraj Gangwar*
>> B.Tech. IV Year
>> Electronics and Communication IDD
>> Indian Institute of Technology Roorkee
>> Contact No. : +91 9897073730
>>
>>
>> On Fri, Nov 16, 2012 at 10:52 PM, rahul sharma 
>> wrote:
>>
>>> but with adding it willl copy aalll the codewe we dont need to
>>> copy..if we declare int i in file 1...and include in file 2..then i can use
>>> it in file 2 with its extern declaration...m i ryt?
>>>
>>>
>>> On Fri, Nov 16, 2012 at 2:42 PM, Neeraj Gangwar 
>>> wrote:
>>>
>>>> For Dev-C++, you have to include one file in another.
>>>> So either add *#include "file1.c" *in file2.c and compile file2.c or
>>>> add *#include "file2.c" *in file1.c and compile file1.c.
>>>>
>>>> Hope this helps.
>>>>
>>>>
>>>> *Neeraj Gangwar*
>>>> B.Tech. IV Year
>>>> Electronics and Communication IDD
>>>> Indian Institute of Technology Roorkee
>>>> Contact No. : +91 9897073730
>>>>
>>>>
>>>> On Fri, Nov 16, 2012 at 9:11 AM, Rahul Kumar Dubey 
>>>> wrote:
>>>>
>>>>> @rahulsharma
>>>>>  file1.c
>>>>>
>>>>> #include
>>>>> extern int i;// defintion provided in this file itself
>>>>> extern int j; // definition provided in file2
>>>>> void next()
>>>>> {
>>>>> ++i;
>>>>> other();
>>>>> }
>>>>> int main()
>>>>> {
>>>>> ++i;
>>>>> printf("%d\n",j);
>>>>> printf("%d\n",i);
>>>>>next();
>>>>> }
>>>>> int i=3;
>>>>>
>>>>> // end of file1.c
>>>>>
>>>>> file2.c
>>

Re: [algogeeks] C o/p adobe

2012-11-16 Thread rahul sharma
but with adding it willl copy aalll the codewe we dont need to copy..if
we declare int i in file 1...and include in file 2..then i can use it in
file 2 with its extern declaration...m i ryt?

On Fri, Nov 16, 2012 at 2:42 PM, Neeraj Gangwar wrote:

> For Dev-C++, you have to include one file in another.
> So either add *#include "file1.c" *in file2.c and compile file2.c or add 
> *#include
> "file2.c" *in file1.c and compile file1.c.
>
> Hope this helps.
>
>
> *Neeraj Gangwar*
> B.Tech. IV Year
> Electronics and Communication IDD
> Indian Institute of Technology Roorkee
> Contact No. : +91 9897073730
>
>
> On Fri, Nov 16, 2012 at 9:11 AM, Rahul Kumar Dubey wrote:
>
>> @rahulsharma
>>  file1.c
>>
>> #include
>> extern int i;// defintion provided in this file itself
>> extern int j; // definition provided in file2
>> void next()
>> {
>> ++i;
>> other();
>> }
>> int main()
>> {
>> ++i;
>> printf("%d\n",j);
>> printf("%d\n",i);
>>next();
>> }
>> int i=3;
>>
>> // end of file1.c
>>
>> file2.c
>> extern int i; // declaration of i as extern
>> int j=10; // j defined in file2 here which was declared as extern in file
>> 1
>>
>> void other()
>> {
>> ++i;
>> printf("%d\n",i);
>> }
>> // end of file2.c
>>
>> compile both file together
>> as
>> rahul@rahul:~gcc file1.c file2.c
>> rahul@rahul:~./a.out
>> you will get the required output
>>
>>
>>
>>
>>
>> On Fri, Nov 16, 2012 at 8:27 AM, Neeraj Gangwar 
>> wrote:
>>
>>> That's why you are getting the error. You have to compile both the files
>>> together. Search on google. I don't use dev c++.
>>>
>>> *Neeraj Gangwar*
>>> B.Tech. IV Year
>>> Electronics and Communication IDD
>>> Indian Institute of Technology Roorkee
>>> Contact No. : +91 9897073730
>>>
>>>
>>> On Thu, Nov 15, 2012 at 11:32 PM, rahul sharma 
>>> wrote:
>>>
>>>>  No...individually...dev cpp..how to compile both together???
>>>>
>>>>
>>>> On Thu, Nov 15, 2012 at 9:26 PM, Neeraj Gangwar >>> > wrote:
>>>>
>>>>> Which compiler are you using ? Are you compiling both the files
>>>>> together ?
>>>>>
>>>>> *Neeraj Gangwar*
>>>>> B.Tech. IV Year
>>>>> Electronics and Communication IDD
>>>>> Indian Institute of Technology Roorkee
>>>>> Contact No. : +91 9897073730
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Nov 15, 2012 at 9:10 PM, rahul sharma >>>> > wrote:
>>>>>
>>>>>> but how can i use extern..if i simply declare a variable in file1 as
>>>>>> int j and try to use in file2 with extern then it shows that j nit
>>>>>> defined..how cum file2 knows in which file j is definedfor e.g if i 
>>>>>> use
>>>>>> extern in file it means that this variable/fxn is defined somewhr 
>>>>>> else.then
>>>>>> what are those files in which it searches this variable definition..i m
>>>>>> getting errorplese give me 2 files in which one files defines 
>>>>>> variable
>>>>>> and other uses using extern.its not working for me
>>>>>>
>>>>>> On Thu, Nov 15, 2012 at 12:08 PM, Rahul Kumar Dubey <
>>>>>> rkd7...@gmail.com> wrote:
>>>>>>
>>>>>>> @rahul it will compile perfectly well . note that you have declared
>>>>>>> j in file 1 as extern and used it and have not provided its definition 
>>>>>>> any
>>>>>>> where
>>>>>>> so getting compile error.
>>>>>>> as far as functions are concerned they are external by defaullt as
>>>>>>> specified by @shobhit
>>>>>>>
>>>>>>> i am attaching your corrected code which runs fine ...
>>>>>>> file1.c
>>>>>>>
>>>>>>>
>>>>>>> #include
>>>>>>> extern int i;
>>>>>>> //extern int j; // provide a declaration for this
>>>>>>> void next(void);
>>>>>>>
>>>>>>> int main()
>>

Re: [algogeeks] C o/p adobe

2012-11-15 Thread rahul sharma
 No...individually...dev cpp..how to compile both together???

On Thu, Nov 15, 2012 at 9:26 PM, Neeraj Gangwar wrote:

> Which compiler are you using ? Are you compiling both the files together ?
>
> *Neeraj Gangwar*
> B.Tech. IV Year
> Electronics and Communication IDD
> Indian Institute of Technology Roorkee
> Contact No. : +91 9897073730
>
>
>
> On Thu, Nov 15, 2012 at 9:10 PM, rahul sharma wrote:
>
>> but how can i use extern..if i simply declare a variable in file1 as int
>> j and try to use in file2 with extern then it shows that j nit defined..how
>> cum file2 knows in which file j is definedfor e.g if i use extern in
>> file it means that this variable/fxn is defined somewhr else.then what are
>> those files in which it searches this variable definition..i m getting
>> errorplese give me 2 files in which one files defines variable and
>> other uses using extern.its not working for me
>>
>> On Thu, Nov 15, 2012 at 12:08 PM, Rahul Kumar Dubey wrote:
>>
>>> @rahul it will compile perfectly well . note that you have declared j in
>>> file 1 as extern and used it and have not provided its definition any where
>>> so getting compile error.
>>> as far as functions are concerned they are external by defaullt as
>>> specified by @shobhit
>>>
>>> i am attaching your corrected code which runs fine ...
>>> file1.c
>>>
>>>
>>> #include
>>> extern int i;
>>> //extern int j; // provide a declaration for this
>>> void next(void);
>>>
>>> int main()
>>> {
>>> ++i;
>>> printf("%d\n",i);
>>>
>>> next();
>>> getchar();
>>> }
>>> int i=3;
>>> void next()
>>> {
>>> ++i;
>>> printf("%d\n",i);
>>> //printf("%d",j); // since no defintion provided so getting error
>>> other();
>>> }
>>>
>>> file2.c
>>>
>>>
>>> extern int i;
>>> void other()
>>> {
>>> ++i;
>>> printf("%d\n",i);
>>> }
>>>
>>> if you want to use j u need to provide defintion either in file 1 or
>>> file 2
>>> output:
>>> 4
>>> 5
>>> 6
>>>
>>>
>>>
>>>
>>> On Wed, Oct 24, 2012 at 10:56 PM, rahul sharma 
>>> wrote:
>>>
>>>> can nyone provide me dummy code of how exactly to use extern in c..
>>>> in dev environment
>>>>
>>>> when i declare int i in one fyl
>>>> and try use use with extern int i in another then it doesnt
>>>> compile..plz coment
>>>>
>>>>
>>>> On Wed, Oct 24, 2012 at 9:58 PM, rahul sharma 
>>>> wrote:
>>>>
>>>>> Then why its not running?
>>>>>
>>>>>
>>>>> On Wed, Oct 24, 2012 at 6:50 PM, SHOBHIT GUPTA <
>>>>> shobhitgupta1...@gmail.com> wrote:
>>>>>
>>>>>> http://www.geeksforgeeks.org/archives/840
>>>>>>
>>>>>> By default, the declaration and definition of a C function have
>>>>>> “extern” prepended with them. It means even though we don’t use extern 
>>>>>> with
>>>>>> the declaration/definition of C functions, it is present there. For
>>>>>> example, when we write.
>>>>>>
>>>>>> int foo(int arg1, char arg2);
>>>>>>
>>>>>> There’s an extern present in the beginning which is hidden and the
>>>>>> compiler treats it as below.
>>>>>>
>>>>>> extern int foo(int arg1, char arg2);
>>>>>>
>>>>>>
>>>>>>  On Wed, Oct 24, 2012 at 4:40 PM, rahul sharma <
>>>>>> rahul23111...@gmail.com> wrote:
>>>>>>
>>>>>>>  Pleaase reply with sol as asp
>>>>>>>
>>>>>>> Fille 1:
>>>>>>>  #include
>>>>>>> extern int i;
>>>>>>>
>>>>>>> extern int j;
>>>>>>> void next(void);
>>>>>>> int main()
>>>>>>> {
>>>>>>> ++i;
>>>>>>> printf("%d",i);
>>>>>>> next();
>>>>>>> getchar();
>>>>>>> }
>>>>>>> int i=3;
>>>&g

Re: [algogeeks] C o/p adobe

2012-11-15 Thread rahul sharma
but how can i use extern..if i simply declare a variable in file1 as int j
and try to use in file2 with extern then it shows that j nit defined..how
cum file2 knows in which file j is definedfor e.g if i use extern in
file it means that this variable/fxn is defined somewhr else.then what are
those files in which it searches this variable definition..i m getting
errorplese give me 2 files in which one files defines variable and
other uses using extern.its not working for me

On Thu, Nov 15, 2012 at 12:08 PM, Rahul Kumar Dubey wrote:

> @rahul it will compile perfectly well . note that you have declared j in
> file 1 as extern and used it and have not provided its definition any where
> so getting compile error.
> as far as functions are concerned they are external by defaullt as
> specified by @shobhit
>
> i am attaching your corrected code which runs fine ...
> file1.c
>
>
> #include
> extern int i;
> //extern int j; // provide a declaration for this
> void next(void);
>
> int main()
> {
> ++i;
> printf("%d\n",i);
>
> next();
> getchar();
> }
> int i=3;
> void next()
> {
> ++i;
> printf("%d\n",i);
> //printf("%d",j); // since no defintion provided so getting error
> other();
> }
>
> file2.c
>
>
> extern int i;
> void other()
> {
> ++i;
> printf("%d\n",i);
> }
>
> if you want to use j u need to provide defintion either in file 1 or file 2
> output:
> 4
> 5
> 6
>
>
>
>
> On Wed, Oct 24, 2012 at 10:56 PM, rahul sharma wrote:
>
>> can nyone provide me dummy code of how exactly to use extern in c..
>> in dev environment
>>
>> when i declare int i in one fyl
>> and try use use with extern int i in another then it doesnt compile..plz
>> coment
>>
>>
>> On Wed, Oct 24, 2012 at 9:58 PM, rahul sharma wrote:
>>
>>> Then why its not running?
>>>
>>>
>>> On Wed, Oct 24, 2012 at 6:50 PM, SHOBHIT GUPTA <
>>> shobhitgupta1...@gmail.com> wrote:
>>>
>>>> http://www.geeksforgeeks.org/archives/840
>>>>
>>>> By default, the declaration and definition of a C function have
>>>> “extern” prepended with them. It means even though we don’t use extern with
>>>> the declaration/definition of C functions, it is present there. For
>>>> example, when we write.
>>>>
>>>> int foo(int arg1, char arg2);
>>>>
>>>> There’s an extern present in the beginning which is hidden and the
>>>> compiler treats it as below.
>>>>
>>>> extern int foo(int arg1, char arg2);
>>>>
>>>>
>>>>  On Wed, Oct 24, 2012 at 4:40 PM, rahul sharma >>> > wrote:
>>>>
>>>>>  Pleaase reply with sol as asp
>>>>>
>>>>> Fille 1:
>>>>>  #include
>>>>> extern int i;
>>>>>
>>>>> extern int j;
>>>>> void next(void);
>>>>> int main()
>>>>> {
>>>>> ++i;
>>>>> printf("%d",i);
>>>>> next();
>>>>> getchar();
>>>>> }
>>>>> int i=3;
>>>>> void next()
>>>>> {
>>>>>  ++i;
>>>>>  printf("%d",i);
>>>>>  printf("%d",j);
>>>>> other();
>>>>>  }
>>>>> File 2:
>>>>>  extern int i;
>>>>>
>>>>> void other()
>>>>> {
>>>>>  ++i;
>>>>> printf("%d",i)'
>>>>> }
>>>>>
>>>>> How cum file 1 knows what is other();as we havnet define with
>>>>> extern void other();
>>>>> it should be error
>>>>> but when i include the statemetn extern void other,then also it shows??
>>>>> pls provide me o/p of this questiona nd also tell how use use variable
>>>>> of one file in other as simply writing extern in a is not accesing global 
>>>>> a
>>>>> of other file
>>>>>
>>>>> --
>>>>> 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 

Re: [algogeeks] Add and subtract with out using mathematical operator.......

2012-11-07 Thread rahul sharma
following using exor
http://www.geeksforgeeks.org/archives/18324

following is tricky
http://www.geeksforgeeks.org/archives/22080

On Wed, Nov 7, 2012 at 11:36 AM, Rahul Kumar Patle <
patlerahulku...@gmail.com> wrote:

> you can use bit wise addition.. using xor , and , or and shift op
> erations...
> retrieve bits from both numbers one by one
> do xor store result as a bit in resultant number and consider carry for
> next bit..
>
>
> On Tue, Nov 6, 2012 at 10:43 AM, DHARMENDRA KUMAR VERMA <
> dharmendrakumarverm...@gmail.com> wrote:
>
>> how many ways are there to add or subtract two numbers with out addition
>> or subtraction operator???
>>
>> --
>> 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.
>>
>
>
>
> --
> Thanks and Regards:
> Rahul Kumar Patle
> M.Tech, School of Information Technology
> Indian Institute of Technology, Kharagpur-721302, 
> India
> Mobile No: +91-8798049298, +91-9424738542
> Alternate Email: rahulkumarpa...@hotmail.com
> [image: 
> Linkedin]
> [image: Twitter] 
> 
>
>  --
> 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] Time Complexity Analysis

2012-11-05 Thread rahul sharma
dude n for build tree and n in this for finding maximun??so n*(n/2)=o(n^2)

On Mon, Nov 5, 2012 at 8:54 PM, shady  wrote:

> Here the time complexity of the solution should be O(n * log(n))
> http://www.geeksforgeeks.org/archives/21781
>
> --
> 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] Ternary operators

2012-11-01 Thread rahul sharma
I cant get to you..please explain...what will first statement expanded to
during compilation..??.and why 0 is converted to base..i know exp3 is
convertered to exp to..so int to array..???base array comes in int???and
what is 0??what if we have 1 in case of 0?

On Thu, Nov 1, 2012 at 5:20 PM, Saurabh Kumar  wrote:

> There's nothing to do with the type of "A String".
> The reason for which the first code gives compilation error is: operator
> (<<) has higher precedence than ternary operator (?:) so, without braces
> your are actually messing up the parsing of "cout << << << "stream.
>
> * cout << test ? "A String" : 0 << endl;*
>
> consider removing the last "*<
> * cout << test ? "A String" : 0;* // this compiles and runs fine with my
> compiler(g++ 4.5), but as *cout << test* will take precedence, there is
> no point of putting a ternary operator there, unless you use braces, of
> course.
>
>
> In teh second case however, reason given is valid:
>  i.e. return type of ternary operator is determined by "A String" and the
> expression 0 will be taken as address of a string location. Hence, there is
> no guarantee of output.
>
>
> On 31 October 2012 19:52, rahul sharma  wrote:
>
>> plz read carefully
>>
>>
>> On Wed, Oct 31, 2012 at 10:18 AM, Tamanna Afroze wrote:
>>
>>> sorry for my last post, i didn't look carefully at the code. I think
>>> without bracket the ternary expression is incomplete, that's why; first
>>> code doesn't compile correctly.
>>>
>>>
>>>
>>> On Wed, Oct 31, 2012 at 9:51 AM, Tamanna Afroze wrote:
>>>
>>>> both codes are same. Where is the difference?
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] You are given two 32-bit numbers, N and M, and two bit positions, i and j.

2012-10-31 Thread rahul sharma
You are given two 32-bit numbers, N and M, and two bit positions, i and j.
Write a method to set all bits between i and j in N equal to M (e.g., M
becomes a substring of N located at i and starting at j).
EXAMPLE:
Input: N = 100, M = 10101, i = 2, j = 6
Output: N = 10001010100

Following is code...guys i think that in line no. 5  (1

[algogeeks] Extern in c

2012-10-31 Thread rahul sharma
How actually to use extern

suppose in file 1 i write code..(test_new.c)

#include 

 #include

 int interest_rate =5;
int main()
{
   int test = 0;
   int t=5;
  // cout<
#include"test_new.c"
extern int interest_rate;
void fun()
{
interest_rate=6;
}

it works..
now if i make interest_rate as static in c..it also wokrs in file 2..but it
should not...and if i remove the declaration of interest from file 2 it
also works...all this happening becoz i #included test_new.c(file1) in
file2so i definition comes in a...plz tell how to tell fille 2 to refer
file 1...as by #inlcuded resultsare not as accepted...itz full code coming
in file a...i want that

global variable is accessible in file 2 but for static it shows that itz an
undefined referenceplz provide me code snippet..

-- 
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] BIG O

2012-10-31 Thread rahul sharma
Its nlogn dude

On Wed, Oct 31, 2012 at 8:03 PM, jai gupta  wrote:

> is O(long n!)
> n! is O(n^n) by sterling approximation
> hence it is O(log n^n) = O(nlogn)
>
>
> On Sun, Oct 28, 2012 at 11:14 PM, Pralay Biswas <
> pralaybiswas2...@gmail.com> wrote:
>
>> @ Siddharth :
>> Well, here is how you may understand it:
>> 1) There is an outer loop that runs n times. (k)
>> 2) Then there is an inner loop where j is initially set to current k, but
>> it halves itself in every iteration
>>   -- So for example, if k is 32, and j halves every time, then
>> the inner loop runs for 5 times (32->16->8->4->2 etc)
>>   -- This is a log base 2 order depreciation in for all k
>> 3) So for every k, the inner loop runs for log k times. k itself varies
>> from 1 to n, hence O(nlogn)
>>
>> Hope this helps.
>>
>> #Pralay
>> MS-CS, UC Irvine
>>
>> On Sun, Oct 28, 2012 at 10:38 AM, bharat b 
>> wrote:
>>
>>> while loop : logj base 2 ..
>>> ==> log1 + log2 + ... logn = log(n!) [since logab = loga + logb]
>>> ==> O(log(n^n)) = O(nlogn)
>>>
>>>
>>> On Sun, Oct 28, 2012 at 3:56 AM, Siddharth Malhotra <
>>> codemalho...@gmail.com> wrote:
>>>
>>>> Can somebody explain how it is O(n log n).
>>>> What is the significance of while loop in the above code?
>>>>
>>>> I understand that the for loop implies O(n),does the log n in the O(n
>>>> log n) comes from the while loop?
>>>> What if there where two while loops in the for loop separately?
>>>>
>>>> On Sat, Oct 27, 2012 at 3:26 AM, Pralay Biswas <
>>>> pralaybiswas2...@gmail.com> wrote:
>>>>
>>>>> Yes!
>>>>>
>>>>>
>>>>> On Fri, Oct 26, 2012 at 2:55 PM, rahul sharma >>>> > wrote:
>>>>>
>>>>>> for k=1 to n
>>>>>> {
>>>>>> j=k;
>>>>>> while(j>0)
>>>>>> j=j/2;
>>>>>> }
>>>>>> the complexity is big o is o(nlogn)
>>>>>> am i ryt
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>
> kriateive
>
> --
> 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] Ternary operators

2012-10-31 Thread rahul sharma
plz read carefully

On Wed, Oct 31, 2012 at 10:18 AM, Tamanna Afroze wrote:

> sorry for my last post, i didn't look carefully at the code. I think
> without bracket the ternary expression is incomplete, that's why; first
> code doesn't compile correctly.
>
>
>
> On Wed, Oct 31, 2012 at 9:51 AM, Tamanna Afroze wrote:
>
>> both codes are same. Where is the difference?
>>
>
>  --
> 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: Repeated values

2012-10-30 Thread rahul sharma
i thnik this is the solution...
http://www.geeksforgeeks.org/archives/9755

On Wed, Oct 31, 2012 at 2:20 AM, Don  wrote:

> We can modify the array. The algorithm should work even if we use
> unsigned integers and N is the largest unsigned integer.
>
> Don
>
> On Oct 30, 4:42 pm, rahul sharma  wrote:
> > Can we modify the array???we can make index we visit as negative and then
> > if any one already containing -ve..then its repeating
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Oct 31, 2012 at 1:40 AM, Don  wrote:
> > > Does your algorithm work if N=4 and the array is {1,1,2,2}.
> >
> > > Don
> >
> > > On Oct 30, 2:32 pm, arumuga abinesh  wrote:
> > > > if sum of all elements = n(n-1)/2 , no elements are repeated
> > > > else some numbers are repeated
> >
> > > > On Tue, Oct 30, 2012 at 11:57 PM, Don  wrote:
> > > > > Given an array of N integers in the range 0..N-1, determine if any
> > > > > number is repeated in the array.
> > > > > Solution should execute in O(n) time and use constant space.
> > > > > Don
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Algorithm Geeks" group.
> > > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > algogeeks+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Repeated values

2012-10-30 Thread rahul sharma
Can we modify the array???we can make index we visit as negative and then
if any one already containing -ve..then its repeating

On Wed, Oct 31, 2012 at 1:40 AM, Don  wrote:

> Does your algorithm work if N=4 and the array is {1,1,2,2}.
>
> Don
>
> On Oct 30, 2:32 pm, arumuga abinesh  wrote:
> > if sum of all elements = n(n-1)/2 , no elements are repeated
> > else some numbers are repeated
> >
> >
> >
> >
> >
> >
> >
> > On Tue, Oct 30, 2012 at 11:57 PM, Don  wrote:
> > > Given an array of N integers in the range 0..N-1, determine if any
> > > number is repeated in the array.
> > > Solution should execute in O(n) time and use constant space.
> > > Don
> >
> > > --
> > > 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] C Macro

2012-10-30 Thread rahul sharma
Yeah its working...actually it was written in book...and i did nt
compilemistake of author

On Tue, Oct 30, 2012 at 12:17 PM, Vikram Pradhan wrote:

> @rahul : dude it's working fine ...check your printf() statement you
> are swapping the pointers and printing the original float values of a and x
> it should be printf("%f%f",*p,*q);
>
> or if you want to swap float values not the pointers then it should be
> swap(a,x,float);
> printf("%f%f",a,x);
>
>
> On Mon, Oct 29, 2012 at 11:30 PM, atul anand wrote:
>
>> well they should not , if you see it closely  pointer p and q
>> contain contain address of a and x.
>> and swap() macro will swap value these pointers are holding i.e adress
>> of a and xbut will it reflect address of a and x ???...NO
>> so if you print the address p and q ...before and after the swap then
>> you should see that after swap p will be holding address of x and
>> q will be holding address of a..that it
>>
>> On 10/29/12, rahul sharma  wrote:
>> > I have taken form book...i am writing exact code
>> >
>> > #include
>> > #define swap(a,b,c) c t;t=a,a=b,b=t;
>> >
>> >
>> > int main()
>> > {
>> > float a,x;
>> > a=20.0;
>> > x=30.0;
>> > float *p,*q;
>> > p=&a,q=&x;
>> > swap(p,q,float*);
>> > printf("%f %f",a,x);
>> > getchar();
>> > }
>> >
>> > o/p=20.000 30.000
>> >
>> >
>> > why not swapped???
>> > On Mon, Oct 29, 2012 at 11:01 PM, atul anand
>> > wrote:
>> >
>> >> if you think the your expanded version is incorrect.You are wrong ,
>> >> because int * will hold pointer but you are not allocating address of
>> >> x ..instead you are allocating x value as an address of x to *t.This
>> >> wont work.
>> >> so to make it work you need to save the address of x and y in temp
>> >> pointers i.e
>> >>
>> >>int *p.*q;
>> >> p=&x;
>> >> q=&y;
>> >> int t;
>> >> t=*p;
>> >> *p=*q;
>> >> *q=t;
>> >> now you can convert it into macro.
>> >>
>> >> On 10/29/12, rahul sharma  wrote:
>> >> > @atul...mistakenly  i have put w at place of t in my last post...i
>> wana
>> >> say
>> >> >
>> >> >
>> >> >
>> >> > On Mon, Oct 29, 2012 at 10:07 AM, dCoder 
>> wrote:
>> >> >
>> >> >> Just replace your macro with its definition and you will understand.
>> >> >>
>> >> >> its not doing swapping of pointers...plz explain
>> >> >>
>> >> >
>> >> >
>> >> > @dCode i expanded..but its fine...please tell
>> >> >
>> >> >> #include
>> >> >> #define swap(a,b,c) c t;t=a,a=b,b=t
>> >> >>
>> >> >> int main
>> >> >> int x=10,y=20;
>> >> >> int *p,*q;
>> >> >> swap(x,y,int*);
>> >> >>
>> >> > int * t;
>> >> > t=x;
>> >> > x=y;
>> >> > y=t;
>> >> >
>> >> >
>> >> > There is int* at the end..there is som problem with my
>> >> > keyborad...:(.acc to me axpanded version is above..but not
>> >> swapping
>> >> > two pointerssplz comment
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >> On Sun, Oct 28, 2012 at 9:16 PM, rahul sharma
>> >> >> wrote:
>> >> >>
>> >> >>> its now doing swapping of pointers...plz explain
>> >> >>>
>> >> >>>
>> >> >>> On Sun, Oct 28, 2012 at 8:08 PM, atul anand
>> >> >>> wrote:
>> >> >>>
>> >> >>>> it should swap
>> >> >>>>
>> >> >>>> On 10/28/12, rahul sharma  wrote:
>> >> >>>> > Why the following code is not able to swap two macros???although
>> >> >>>> > it
>> >> >>>> > is
>> >> >>>> > easily swapping 2 variables
>> >> >>>> >
>> >> >>>> > #include
>> >> >>>

Re: [algogeeks] Re: #in macros

2012-10-30 Thread rahul sharma
ossam link...thnx..vikram

On Tue, Oct 30, 2012 at 3:20 PM, Vikram Pradhan wrote:

> Macro arguments are scanned and expanded before the substitution in macro
> body unless they are convert to a string representation (using #) or
> concatenated with other tokens (using ##).
>
> Xstr(oper)  => Xstr(multiply) =>str(multiply)=>"multiply"// in
> Xstr(x) , x is a simple argument so it will expand fully
>
> str(oper)=>"oper"// in str(x) , x is converting to string so it
> will not get expanded
>
> check this link :
> http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html#Argument-Prescan
>
>
>
>
> On Sun, Oct 28, 2012 at 3:28 PM, rahul sharma wrote:
>
>> And when char *opername=str(oper);
>>
>> then o/p is operwhy behaviour is diff. in 2 cases
>>
>> On Sun, Oct 28, 2012 at 2:53 PM, rahul sharma wrote:
>>
>>> #include
>>> #include str(x) #x
>>> #define Xstr(x) str(x)
>>> #define oper multiply
>>>
>>>
>>> int main()
>>> {
>>> char *opername=Xstr(oper);
>>> printf("%s",opername);
>>> }
>>> so firstly Xstr is expanded to str(oper)
>>> then str(oper) is expanded to #oper now i have read that
>>>
>>> If, however, a parameter name is preceded by a # in the replacement
>>> text, the
>>> combination will be expanded into a quoted string with the parameter
>>> replaced by the actual argument...and in this case actual is also oper so
>>> it becomes "oper"...so it should print oper .i thnik i am mistaken
>>> anyhre...correct???
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Vikram Pradhan | B.Tech| Computer Science & Engineering | NIT Jalandhar  |
>  9740186063 |
>
> --
> 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] Pre/Post L and r value

2012-10-30 Thread rahul sharma
@saurabh..thnxplz provide me code snippet for pre increment also..it
will help a lot..i can guess it will do n++ and return itself..plz give
code snippet...

On Mon, Oct 29, 2012 at 10:50 AM, Saurabh Kumar wrote:

> Post increment returns temp object because it has to return the old value
> of object not the new incremented one:
> Simply put, the code for post increment somewhat goes like this:
>
> int operator++ (int &n){
>  int temp = n;
> n = n+1;
> return temp;
> }
>
> that's also the reason you cannot use it as a lvalue in an exprression, as
> you would be assigning nowhere.
>
> On 27 October 2012 20:09, rahul sharma  wrote:
>
>> But y post returns temp. object
>>
>>
>> On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar wrote:
>>
>>> i++: Post increment can't be a lvalue because Post increment internally
>>> returns a temporary object (NOT the location of i) hence you cannot assign
>>> anything to it. The result of i++ can be used only as a rvalue.
>>>  ++i: whereas, in Pre-increment  value gets incremented and the same
>>> location is returned back to you, hence can be used as lvalue in an
>>> expression.(C++ allows this)
>>> Both can be used as rvalues though.
>>>
>>> On 26 October 2012 18:54, rahul sharma  wrote:
>>>
>>>>  why pre inc. is l value and post is r value..please explain
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Complicated declaration C

2012-10-30 Thread rahul sharma
void(*f)(void(*)(int*,void **),int(*)(void**,int*));


f is a fxn pointer to fxn which takes 2 args and teturn nothing

2 arguments are

1. pointer to function which returns nothing and takes 2 args one pointer
to int and pointer to pointer to void
2. pointer to fxn returning int and takes 2 args as pointer to void pointer
and pointer to int..


This is as per me but in book highlighted int above in red as 2 argument is
replaced by int*..so i wana ask whether 2 argument returning int pointer or
int ..Accoring to me its int..please reply asap

Thnx

-- 
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 Function Pointer(Typedef)

2012-10-29 Thread rahul sharma
#include 
#include 


int func(int);
int main(int count,char *argv[])
{
 typedef int (*pFunc) (int);
pFunc=func;
getchar();
}




Y itz not compiling?

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

2012-10-29 Thread rahul sharma
I have taken form book...i am writing exact code

#include
#define swap(a,b,c) c t;t=a,a=b,b=t;


int main()
{
float a,x;
a=20.0;
x=30.0;
float *p,*q;
p=&a,q=&x;
swap(p,q,float*);
printf("%f %f",a,x);
getchar();
}

o/p=20.000 30.000


why not swapped???
On Mon, Oct 29, 2012 at 11:01 PM, atul anand wrote:

> if you think the your expanded version is incorrect.You are wrong ,
> because int * will hold pointer but you are not allocating address of
> x ..instead you are allocating x value as an address of x to *t.This
> wont work.
> so to make it work you need to save the address of x and y in temp
> pointers i.e
>
>int *p.*q;
> p=&x;
> q=&y;
> int t;
> t=*p;
> *p=*q;
>     *q=t;
> now you can convert it into macro.
>
> On 10/29/12, rahul sharma  wrote:
> > @atul...mistakenly  i have put w at place of t in my last post...i wana
> say
> >
> >
> >
> > On Mon, Oct 29, 2012 at 10:07 AM, dCoder  wrote:
> >
> >> Just replace your macro with its definition and you will understand.
> >>
> >> its not doing swapping of pointers...plz explain
> >>
> >
> >
> > @dCode i expanded..but its fine...please tell
> >
> >> #include
> >> #define swap(a,b,c) c t;t=a,a=b,b=t
> >>
> >> int main
> >> int x=10,y=20;
> >> int *p,*q;
> >> swap(x,y,int*);
> >>
> > int * t;
> > t=x;
> > x=y;
> > y=t;
> >
> >
> > There is int* at the end..there is som problem with my
> > keyborad...:(.acc to me axpanded version is above..but not
> swapping
> > two pointerssplz comment
> >
> >
> >
> >
> >> On Sun, Oct 28, 2012 at 9:16 PM, rahul sharma
> >> wrote:
> >>
> >>> its now doing swapping of pointers...plz explain
> >>>
> >>>
> >>> On Sun, Oct 28, 2012 at 8:08 PM, atul anand
> >>> wrote:
> >>>
> >>>> it should swap
> >>>>
> >>>> On 10/28/12, rahul sharma  wrote:
> >>>> > Why the following code is not able to swap two macros???although it
> >>>> > is
> >>>> > easily swapping 2 variables
> >>>> >
> >>>> > #include
> >>>> > #define swap(a,b,c) c t;t=a,a=b,b=t
> >>>> >
> >>>> >
> >>>> > int main
> >>>> >
> >>>> >
> >>>> > int x=10,y=20;
> >>>> > int *p,*q;
> >>>> >
> >>>> > swap(x,y,int);
> >>>> >
> >>>> > --
> >>>> > You received this message because you are subscribed to the Google
> >>>> Groups
> >>>> > "Algorithm Geeks" group.
> >>>> > To post to this group, send email to algogeeks@googlegroups.com.
> >>>> > To unsubscribe from this group, send email to
> >>>> > algogeeks+unsubscr...@googlegroups.com.
> >>>> > For more options, visit this group at
> >>>> > http://groups.google.com/group/algogeeks?hl=en.
> >>>> >
> >>>> >
> >>>>
> >>>> --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "Algorithm Geeks" group.
> >>>> To post to this group, send email to algogeeks@googlegroups.com.
> >>>> To unsubscribe from this group, send email to
> >>>> algogeeks+unsubscr...@googlegroups.com.
> >>>> For more options, visit this group at
> >>>> http://groups.google.com/group/algogeeks?hl=en.
> >>>>
> >>>>
> >>>  --
> >>> You received this message because you are subscribed to the Google
> >>> Groups
> >>> "Algorithm Geeks" group.
> >>> To post to this group, send email to algogeeks@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> algogeeks+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/algogeeks?hl=en.
> >>>
> >>
> >>  --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> 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] C Macro

2012-10-29 Thread rahul sharma
@atul...mistakenly  i have put w at place of t in my last post...i wana say



On Mon, Oct 29, 2012 at 10:07 AM, dCoder  wrote:

> Just replace your macro with its definition and you will understand.
>
> its not doing swapping of pointers...plz explain
>


@dCode i expanded..but its fine...please tell

> #include
> #define swap(a,b,c) c t;t=a,a=b,b=t
>
> int main
> int x=10,y=20;
> int *p,*q;
> swap(x,y,int*);
>
int * t;
t=x;
x=y;
y=t;


There is int* at the end..there is som problem with my
keyborad...:(.acc to me axpanded version is above..but not swapping
two pointerssplz comment




> On Sun, Oct 28, 2012 at 9:16 PM, rahul sharma wrote:
>
>> its now doing swapping of pointers...plz explain
>>
>>
>> On Sun, Oct 28, 2012 at 8:08 PM, atul anand wrote:
>>
>>> it should swap
>>>
>>> On 10/28/12, rahul sharma  wrote:
>>> > Why the following code is not able to swap two macros???although it is
>>> > easily swapping 2 variables
>>> >
>>> > #include
>>> > #define swap(a,b,c) c t;t=a,a=b,b=t
>>> >
>>> >
>>> > int main
>>> >
>>> >
>>> > int x=10,y=20;
>>> > int *p,*q;
>>> >
>>> > swap(x,y,int);
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Algorithm Geeks" group.
>>> > To post to this group, send email to algogeeks@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > algogeeks+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> >
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: LCA in BST

2012-10-28 Thread rahul sharma
how about this:-
int leastCommanAncestor(struct node* root, int n1, int n2)
{
 if(root==NULL)
 return -1;
 if(root->data>n1 && root->data>n2)
 return leastCommanAncestor(root->left,n1,n2);
 else if(root->datadataright,n1,n2);
 return root->data;

}
correct if wrng

On Sun, Oct 28, 2012 at 9:40 PM, rahul sharma wrote:

> According to wiki http://en.wikipedia.org/wiki/Least_common_ancestor
>
> n1 is parent of n2 then n1 is lcabut according to above algo return
> -1..i have taken it from(http://www.geeksforgeeks.org/archives/1029)
>
> plz tell if it is corerctin 2 doubts
>
> 1. if n1is parent of n2
> 2. if n2
> will above algo works???I think No.
>
> So will add the one more condtion for n2 -1 if n2 is child of n1 ???or n1 itself?
>
>
> On Sun, Oct 28, 2012 at 9:25 PM, rahul sharma wrote:
>
>> an one doubt that if we have to find lca of n1 and n2...then if say n1 is
>> parent of n2..in this case we would return n1 or n1->parent.
>>
>>
>> and if n1 is the root and n1 is child then(n1 has no parent)..we will
>> return n1  or -1
>>
>>
>> On Sun, Oct 28, 2012 at 9:18 PM, rahul sharma wrote:
>>
>>> I think th efollowing code lacks one statement i.e   if(root->data>> root->data >n2)
>>> Correct me if wrng
>>> int leastCommanAncestor(struct node* root, int n1, int n2)
>>>  {
>>>
>>>if(root == NULL || root->data == n1 || root->data == n2)
>>>  return -1;
>>>
>>>
>>>   if((root->right != NULL) &&
>>>  (root->right->data == n1 || root->right->data == n2))
>>>  return root->data;
>>>if((root->left != NULL) &&
>>>  (root->left->data == n1 || root->left->data == n2))
>>>  return root->data;
>>>
>>>if(root->data > n1 && root->data < n2)
>>>  return root->data;
>>>if(root->data > n1 && root->data > n2)
>>>  return leastCommanAncestor(root->left, n1, n2);
>>>if(root->data < n1 && root->data < n2)
>>>  return leastCommanAncestor(root->right, n1, n2);
>>>  }
>>>
>>
>>
>

-- 
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: #in macros

2012-10-28 Thread rahul sharma
And when char *opername=str(oper);

then o/p is operwhy behaviour is diff. in 2 cases

On Sun, Oct 28, 2012 at 2:53 PM, rahul sharma wrote:

> #include
> #include str(x) #x
> #define Xstr(x) str(x)
> #define oper multiply
>
>
> int main()
> {
> char *opername=Xstr(oper);
> printf("%s",opername);
> }
> so firstly Xstr is expanded to str(oper)
> then str(oper) is expanded to #oper now i have read that
>
> If, however, a parameter name is preceded by a # in the replacement text,
> the
> combination will be expanded into a quoted string with the parameter
> replaced by the actual argument...and in this case actual is also oper so
> it becomes "oper"...so it should print oper .i thnik i am mistaken
> anyhre...correct???
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] #in macros

2012-10-28 Thread rahul sharma
#include
#include str(x) #x
#define Xstr(x) str(x)
#define oper multiply


int main()
{
char *opername=Xstr(oper);
printf("%s",opername);
}
so firstly Xstr is expanded to str(oper)
then str(oper) is expanded to #oper now i have read that

If, however, a parameter name is preceded by a # in the replacement text,
the
combination will be expanded into a quoted string with the parameter
replaced by the actual argument...and in this case actual is also oper so
it becomes "oper"...so it should print oper .i thnik i am mistaken
anyhre...correct???

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] C Macro

2012-10-28 Thread rahul sharma
Why the following code is not able to swap two macros???although it is
easily swapping 2 variables

#include
#define swap(a,b,c) c t;t=a,a=b,b=t


int main


int x=10,y=20;
int *p,*q;

swap(x,y,int);

-- 
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] Fork in c

2012-10-27 Thread rahul sharma
text 1 remains in buffer...nowwhen child reaches print f.it prints
oldbuffer+newdata...m i ryt???

On Sat, Oct 27, 2012 at 4:07 PM, saurabh singh  wrote:

> printf is line buffered. hence text1 remains in buffer when fork is
> called.this is shared by both the child and the parent when fork is called.
> Leaving the rest for u to conclude
>
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
>
> On Sat, Oct 27, 2012 at 2:25 PM, CHIRANJEEV KUMAR <
> cse.chiranj...@gmail.com> wrote:
>
>> I think the output should be :
>>
>> text1text2
>> text2
>>
>>
>>
>>
>>
>> On Sat, Oct 27, 2012 at 2:22 PM, rahul sharma wrote:
>>
>>> int main()  {
>>> printf("text1");
>>> fork();
>>> printf("text2\n");
>>> return 0;  }
>>>
>>>  the output  is:
>>>
>>> text1text2
>>> text1text2
>>>
>>> Please explain o/p
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Finite state automata accpt string of length 6

2012-10-27 Thread rahul sharma
@payalplz explain how to slect 3 spaces for a.b.c out of 6.
we need to put them in orderso look my aboyve post and plz comment

On Sat, Oct 27, 2012 at 8:14 PM, rahul sharma wrote:

> plz help mei am thinking this the following way..
>
> we need to find no. of permutaions of abcxyz s.t a means we need to form string of 6 length s.t a
> means we have 6 places
> a- can be placed at 4/6 locations
> b- can be palced at 4/6 locations
> c-can be placed at 4/6 locations
>
> can we do like this?
>
>
> On Sat, Oct 27, 2012 at 8:04 PM, rahul sharma wrote:
>
>>  ..i under stand with 6!/(3!*3!) method...
>> plz explain from combination point of viewi didnt get ur last
>> linei understand that
>>
>> we need to find no. of permutaions of abcxyz s.t a> tell how to find thisi understand as someone explained above with
>> VVVHHH method.
>> please explain from thsi view that
>>
>> we need to find no. of permutaions of abcxyz s.t a>
>>
>> On Sat, Oct 27, 2012 at 12:31 PM, Saurabh Kumar wrote:
>>
>>> Since this is a small grid you can count it manually but in general
>>> problem is to count no. of paths from bottom-left corner to top-right
>>> corner (provided all the transition alphabets in the automata are distinct
>>> in the respective dimensions e.g. here,  xyz in one  dimension and abc in
>>> other)
>>>
>>> You can view this problem as writing all permutations of strings of 3R's
>>> and 3U's (for RIGHT movement and UP movement) RRRUUU which will take you to
>>> the top right most corner.
>>> All possible arrangements = (3+3)! / (3! * 3!)
>>> In general: (m+n)! / (m! * n!) for a mxn grid.
>>>
>>>
>>> On 27 October 2012 11:05, rahul sharma  wrote:
>>>
>>>> should i take it how many ways are there to reach from start to  the
>>>> top right destination...x,y,z,a,b,c, are i/p statexyzabc one
>>>> stringabc xyz is another...if m ryt then is dere any formulla to calute
>>>> or we have to do it manuall
>>>>
>>>>
>>>> On Sat, Oct 27, 2012 at 11:02 AM, rahul sharma >>> > wrote:
>>>>
>>>>>
>>>>> can u please elaborate...i am not able to understand the figure..plz
>>>>> explainit would be of great help
>>>>>
>>>>> On Sat, Oct 27, 2012 at 5:57 AM, payal gupta wrote:
>>>>>
>>>>>> should be 6C3 or 20 perhaps.
>>>>>>
>>>>>> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma <
>>>>>> rahul23111...@gmail.com> wrote:
>>>>>>
>>>>>>> Finite state automata accpt string of length 6
>>>>>>>
>>>>>>> what is total number of strings in set..please find the attahcment
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>>> For more options, visit this group at
>>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>
>>>>>
>>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Finite state automata accpt string of length 6

2012-10-27 Thread rahul sharma
plz help mei am thinking this the following way..
we need to find no. of permutaions of abcxyz s.t awrote:

>  ..i under stand with 6!/(3!*3!) method...
> plz explain from combination point of viewi didnt get ur last
> linei understand that
>
> we need to find no. of permutaions of abcxyz s.t a tell how to find thisi understand as someone explained above with
> VVVHHH method.
> please explain from thsi view that
>
> we need to find no. of permutaions of abcxyz s.t a
>
> On Sat, Oct 27, 2012 at 12:31 PM, Saurabh Kumar wrote:
>
>> Since this is a small grid you can count it manually but in general
>> problem is to count no. of paths from bottom-left corner to top-right
>> corner (provided all the transition alphabets in the automata are distinct
>> in the respective dimensions e.g. here,  xyz in one  dimension and abc in
>> other)
>>
>> You can view this problem as writing all permutations of strings of 3R's
>> and 3U's (for RIGHT movement and UP movement) RRRUUU which will take you to
>> the top right most corner.
>> All possible arrangements = (3+3)! / (3! * 3!)
>> In general: (m+n)! / (m! * n!) for a mxn grid.
>>
>>
>> On 27 October 2012 11:05, rahul sharma  wrote:
>>
>>> should i take it how many ways are there to reach from start to  the top
>>> right destination...x,y,z,a,b,c, are i/p statexyzabc one string....abc
>>> xyz is another...if m ryt then is dere any formulla to calute or we have to
>>> do it manuall
>>>
>>>
>>> On Sat, Oct 27, 2012 at 11:02 AM, rahul sharma 
>>> wrote:
>>>
>>>>
>>>> can u please elaborate...i am not able to understand the figure..plz
>>>> explainit would be of great help
>>>>
>>>> On Sat, Oct 27, 2012 at 5:57 AM, payal gupta wrote:
>>>>
>>>>> should be 6C3 or 20 perhaps.
>>>>>
>>>>> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma >>>> > wrote:
>>>>>
>>>>>> Finite state automata accpt string of length 6
>>>>>>
>>>>>> what is total number of strings in set..please find the attahcment
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Sequence Point C with postincremented

2012-10-27 Thread rahul sharma
so it means after sequence point the post increment is done...after && ht
epost increment is incremented and value is reflected...m i ryt?

On Fri, Oct 26, 2012 at 8:43 PM, Saurabh Kumar  wrote:

> You're right , && || all introduce a sequence point. In first case
> evaluation proceeds like this:
> j = (i++, i++);
> >>  *i++* Post increment the i (i is now 11)
> >>  *j = i++* Post increment the i (j is assigned 11 and i is now 12)
>
> In second case, the whole of rvalue for = operator will be evaluated
> first...
> j = a++ && 1;
> >> *a++ *a is Post incremented (a is now 1 but return value is 0)
> >> *0 && 1* = 0 (which gets assigned to j)
> Hence, j = 0, a = 1
>
> On 26 October 2012 18:54, rahul sharma  wrote:
>
>> Guys plz tell that postincremented variable is  incremented after
>> sequence or after ;
>>
>> as we have && || comma and ; as sequence point
>>
>> so say we have
>> int i=10;
>> int j=(i++,i++);
>> firstly i++ goes and as comma comes so ++ post inc. takes place and take
>> to 11 ..now when next time the postincremented is done later after ;  and
>> firstly the value 11 is assigned to j
>>
>> so after this statement we have j=11,i=12
>>
>> but if i write
>> int a=0;
>> int j=a++&&1;
>> so when && comes so postincrement takes place and assign this to j...so
>> at the point we reach && acc. to me a=1..But a remains 0 as this expression
>> goes to false...can anybody tell me y so happens..when does the value in
>> postincremented is incremented...i am sure about comm and ;...but what in
>> case of && and  ||these are also sequence point...y post increment
>> doesnt take place when we reach &&...please explain..
>>
>> --
>> 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] Pre/Post L and r value

2012-10-27 Thread rahul sharma
But y post returns temp. object

On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar  wrote:

> i++: Post increment can't be a lvalue because Post increment internally
> returns a temporary object (NOT the location of i) hence you cannot assign
> anything to it. The result of i++ can be used only as a rvalue.
> ++i: whereas, in Pre-increment  value gets incremented and the same
> location is returned back to you, hence can be used as lvalue in an
> expression.(C++ allows this)
> Both can be used as rvalues though.
>
> On 26 October 2012 18:54, rahul sharma  wrote:
>
>> why pre inc. is l value and post is r value..please explain
>>
>> --
>> 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] Finite state automata accpt string of length 6

2012-10-27 Thread rahul sharma
 ..i under stand with 6!/(3!*3!) method...
plz explain from combination point of viewi didnt get ur last linei
understand that

we need to find no. of permutaions of abcxyz s.t awrote:

> Since this is a small grid you can count it manually but in general
> problem is to count no. of paths from bottom-left corner to top-right
> corner (provided all the transition alphabets in the automata are distinct
> in the respective dimensions e.g. here,  xyz in one  dimension and abc in
> other)
>
> You can view this problem as writing all permutations of strings of 3R's
> and 3U's (for RIGHT movement and UP movement) RRRUUU which will take you to
> the top right most corner.
> All possible arrangements = (3+3)! / (3! * 3!)
> In general: (m+n)! / (m! * n!) for a mxn grid.
>
>
> On 27 October 2012 11:05, rahul sharma  wrote:
>
>> should i take it how many ways are there to reach from start to  the top
>> right destination...x,y,z,a,b,c, are i/p statexyzabc one stringabc
>> xyz is another...if m ryt then is dere any formulla to calute or we have to
>> do it manuall
>>
>>
>> On Sat, Oct 27, 2012 at 11:02 AM, rahul sharma 
>> wrote:
>>
>>>
>>> can u please elaborate...i am not able to understand the figure..plz
>>> explainit would be of great help
>>>
>>> On Sat, Oct 27, 2012 at 5:57 AM, payal gupta wrote:
>>>
>>>> should be 6C3 or 20 perhaps.
>>>>
>>>> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma 
>>>> wrote:
>>>>
>>>>> Finite state automata accpt string of length 6
>>>>>
>>>>> what is total number of strings in set..please find the attahcment
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Finite state automata accpt string of length 6

2012-10-26 Thread rahul sharma
should i take it how many ways are there to reach from start to  the top
right destination...x,y,z,a,b,c, are i/p statexyzabc one stringabc
xyz is another...if m ryt then is dere any formulla to calute or we have to
do it manuall


On Sat, Oct 27, 2012 at 11:02 AM, rahul sharma wrote:

>
> can u please elaborate...i am not able to understand the figure..plz
> explainit would be of great help
>
> On Sat, Oct 27, 2012 at 5:57 AM, payal gupta  wrote:
>
>> should be 6C3 or 20 perhaps.
>>
>> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma wrote:
>>
>>> Finite state automata accpt string of length 6
>>>
>>> what is total number of strings in set..please find the attahcment
>>>
>>> --
>>> 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] Finite state automata accpt string of length 6

2012-10-26 Thread rahul sharma
can u please elaborate...i am not able to understand the figure..plz
explainit would be of great help
On Sat, Oct 27, 2012 at 5:57 AM, payal gupta  wrote:

> should be 6C3 or 20 perhaps.
>
> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma wrote:
>
>> Finite state automata accpt string of length 6
>>
>> what is total number of strings in set..please find the attahcment
>>
>> --
>> 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] BIG O

2012-10-26 Thread rahul sharma
for k=1 to n
{
j=k;
while(j>0)
j=j/2;
}
the complexity is big o is o(nlogn)
am i ryt

-- 
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] Advice needed

2012-10-26 Thread rahul sharma
There is question asked like
O/p of following in C(32 bit OS)
#include 
 #include
using namespace std;


bool IsEqual(char * a)
{
printf("abc");
return true;
}

int main()
{
char str[30];
printf("%d",sizeof(sizeof(IsEqual(str;
getchar();
return 0;
}
I run with .cppi know o/p and all in c++...but c doesn't support
bool.so what should i write in answer as it is asked in written..so wat
should be writen

4 i.e the answer in c++ or should i write that c doesn't support bool

plez comment

-- 
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] Pre/Post L and r value

2012-10-26 Thread rahul sharma
why pre inc. is l value and post is r value..please explain

-- 
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] Sequence Point C with postincremented

2012-10-26 Thread rahul sharma
Guys plz tell that postincremented variable is  incremented after sequence
or after ;

as we have && || comma and ; as sequence point

so say we have
int i=10;
int j=(i++,i++);
firstly i++ goes and as comma comes so ++ post inc. takes place and take to
11 ..now when next time the postincremented is done later after ;  and
firstly the value 11 is assigned to j

so after this statement we have j=11,i=12

but if i write
int a=0;
int j=a++&&1;
so when && comes so postincrement takes place and assign this to j...so at
the point we reach && acc. to me a=1..But a remains 0 as this expression
goes to false...can anybody tell me y so happens..when does the value in
postincremented is incremented...i am sure about comm and ;...but what in
case of && and  ||these are also sequence point...y post increment
doesnt take place when we reach &&...please explain..

-- 
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] .Given the binary form of a number in a string. WAP to find 2's complement in that string itself.[ADOBE]

2012-10-25 Thread rahul sharma
Plz give a program for this...thnx

-- 
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: c code help!!!!

2012-10-25 Thread rahul sharma
Please dont reply to thi post..wrng questionsry for that

On Fri, Oct 26, 2012 at 2:31 AM, rahul sharma wrote:

> address of each byte is printed...each byte is 32 bit long...so 32/4=8 hex
> for each row...but how these are separated with %.2x tin group of
> 2's%.2x means min. 2 width ..if <2..then leading zeros...
> so it should be ("%.2x",start[i]);
> start[i] in 2 but it is more so ignored...print start[i]still how
> these are able to grouped??
>
>
> On Fri, Oct 26, 2012 at 1:53 AM, rahul sharma wrote:
>
>> As per o/p below:
>> 00 00 80 3f
>>  01 00 00 00
>>  44 ff 28 00
>>  01 00 00 00
>>
>> first byte address is first row.
>> second byte address is second row.
>> third byte address third row
>> and so on
>>
>> but how first row containg 3 values...as 1byte=2hexdigits..si only two
>> digits must be there.
>> and u said 44 ff 28 00 is address of i..how???getting a lot confused..plz
>> clearify..thnx in advance
>>
>> On Sun, Oct 21, 2012 at 1:10 AM, Saurabh Kumar wrote:
>>
>>> Sorry, about that.
>>> Read it as:
>>> Yes a hex digit is represented by 4 bits but 1 Byte is being read using
>>> a char pointer* and you're printing the values in those Bytes.
>>>
>>>
>>> On 21 October 2012 01:03, Saurabh Kumar  wrote:
>>>
>>>> Sorry, I don't understand your question. *%.2x *is only a precision
>>>> specifier still.
>>>> (%.2x was used for neat formatting only, because you are printing the
>>>> values only 1 Byte long and a Byte can occupy at max 2digits in hex)
>>>>
>>>> >>>>hex representated by 4 bits.
>>>> Yes hex is represented by 4 bits i.e. 1 Byte and that's what you are
>>>> reading with a char pointer*,  1 Byte each time and printing the values in
>>>> those Bytes.
>>>>
>>>> >>>>total we have to represent 32 bits and 8 bits in eachplz xplain
>>>> Each output represents 32bits only. 1 Byte each (in total 4Bytes)
>>>>
>>>> It's showing you the memory layout. You stored *i = 1; *and when
>>>> probed it using a char pointer. you found following four bytes written:
>>>>  *01 00 00 00*
>>>> It shows that on your machine:
>>>> 1. int is 4bytes long. (4x1Byte)
>>>> 2. First byte stores the least significant value, hence you are working
>>>> on a Little endian machine.
>>>>
>>>> similarly, for pointer:
>>>> char pointer reads 1 Byte at a time. It read 4Bytes in total i.e. 32
>>>> bits. Hence, you are working on a 32 bit machine. (as pointer has
>>>> value: *44 ff 28 00, *address of i)*.*
>>>> *
>>>> *
>>>> *
>>>> *
>>>> PS: This is an algorithm group, please refrain from asking such
>>>> language specific questions.
>>>>
>>>> On 21 October 2012 00:19, rahul sharma  wrote:
>>>>
>>>>> Actually i have taken form   http://www.geeksforgeeks.org/archives/730
>>>>> Please explain me o/p...as hex representated by 4 bitsthen how cum
>>>>> is following o/p
>>>>>  00 00 80 3f
>>>>>  01 00 00 00
>>>>>  44 ff 28 00
>>>>>  01 00 00 00
>>>>>
>>>>> total we have to represent 32 bits and 8 bits in eachplz xplain
>>>>>
>>>>> On Sun, Oct 21, 2012 at 12:05 AM, rahul sharma <
>>>>> rahul23111...@gmail.com> wrote:
>>>>>
>>>>>> void show_bytes(byte_pointer start, int len)
>>>>>> {
>>>>>>  int i;
>>>>>>  for (i = 0; i < len; i++)
>>>>>>printf(" %.2x", start[i]);
>>>>>>  printf("\n");
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> byte_pointr is unsigned char *...typedef unsigned char *
>>>>>> byte_pointer
>>>>>> plz tell me use of %.2x  i knowx is for hexadoes it mean
>>>>>> print 8 bites of address in 4 hexa of 2 bits???i cant get xactly plz 
>>>>>> explain
>>>>>>
>>>>>
>>>>>  --
>>>>> 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: c code help!!!!

2012-10-25 Thread rahul sharma
address of each byte is printed...each byte is 32 bit long...so 32/4=8 hex
for each row...but how these are separated with %.2x tin group of
2's%.2x means min. 2 width ..if <2..then leading zeros...
so it should be ("%.2x",start[i]);
start[i] in 2 but it is more so ignored...print start[i]still how these
are able to grouped??

On Fri, Oct 26, 2012 at 1:53 AM, rahul sharma wrote:

> As per o/p below:
> 00 00 80 3f
>  01 00 00 00
>  44 ff 28 00
>  01 00 00 00
>
> first byte address is first row.
> second byte address is second row.
> third byte address third row
> and so on
>
> but how first row containg 3 values...as 1byte=2hexdigits..si only two
> digits must be there.
> and u said 44 ff 28 00 is address of i..how???getting a lot confused..plz
> clearify..thnx in advance
>
> On Sun, Oct 21, 2012 at 1:10 AM, Saurabh Kumar wrote:
>
>> Sorry, about that.
>> Read it as:
>> Yes a hex digit is represented by 4 bits but 1 Byte is being read using a
>> char pointer* and you're printing the values in those Bytes.
>>
>>
>> On 21 October 2012 01:03, Saurabh Kumar  wrote:
>>
>>> Sorry, I don't understand your question. *%.2x *is only a precision
>>> specifier still.
>>> (%.2x was used for neat formatting only, because you are printing the
>>> values only 1 Byte long and a Byte can occupy at max 2digits in hex)
>>>
>>> >>>>hex representated by 4 bits.
>>> Yes hex is represented by 4 bits i.e. 1 Byte and that's what you are
>>> reading with a char pointer*,  1 Byte each time and printing the values in
>>> those Bytes.
>>>
>>> >>>>total we have to represent 32 bits and 8 bits in eachplz xplain
>>> Each output represents 32bits only. 1 Byte each (in total 4Bytes)
>>>
>>> It's showing you the memory layout. You stored *i = 1; *and when probed
>>> it using a char pointer. you found following four bytes written:  *01
>>> 00 00 00*
>>> It shows that on your machine:
>>> 1. int is 4bytes long. (4x1Byte)
>>> 2. First byte stores the least significant value, hence you are working
>>> on a Little endian machine.
>>>
>>> similarly, for pointer:
>>> char pointer reads 1 Byte at a time. It read 4Bytes in total i.e. 32
>>> bits. Hence, you are working on a 32 bit machine. (as pointer has
>>> value: *44 ff 28 00, *address of i)*.*
>>> *
>>> *
>>> *
>>> *
>>> PS: This is an algorithm group, please refrain from asking such language
>>> specific questions.
>>>
>>> On 21 October 2012 00:19, rahul sharma  wrote:
>>>
>>>> Actually i have taken form   http://www.geeksforgeeks.org/archives/730
>>>> Please explain me o/p...as hex representated by 4 bitsthen how cum
>>>> is following o/p
>>>>  00 00 80 3f
>>>>  01 00 00 00
>>>>  44 ff 28 00
>>>>  01 00 00 00
>>>>
>>>> total we have to represent 32 bits and 8 bits in eachplz xplain
>>>>
>>>> On Sun, Oct 21, 2012 at 12:05 AM, rahul sharma >>> > wrote:
>>>>
>>>>> void show_bytes(byte_pointer start, int len)
>>>>> {
>>>>>  int i;
>>>>>  for (i = 0; i < len; i++)
>>>>>printf(" %.2x", start[i]);
>>>>>  printf("\n");
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> byte_pointr is unsigned char *...typedef unsigned char *
>>>>> byte_pointer
>>>>> plz tell me use of %.2x  i knowx is for hexadoes it mean print
>>>>> 8 bites of address in 4 hexa of 2 bits???i cant get xactly plz explain
>>>>>
>>>>
>>>>  --
>>>> 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: c code help!!!!

2012-10-25 Thread rahul sharma
As per o/p below:
00 00 80 3f
 01 00 00 00
 44 ff 28 00
 01 00 00 00

first byte address is first row.
second byte address is second row.
third byte address third row
and so on

but how first row containg 3 values...as 1byte=2hexdigits..si only two
digits must be there.
and u said 44 ff 28 00 is address of i..how???getting a lot confused..plz
clearify..thnx in advance

On Sun, Oct 21, 2012 at 1:10 AM, Saurabh Kumar  wrote:

> Sorry, about that.
> Read it as:
> Yes a hex digit is represented by 4 bits but 1 Byte is being read using a
> char pointer* and you're printing the values in those Bytes.
>
>
> On 21 October 2012 01:03, Saurabh Kumar  wrote:
>
>> Sorry, I don't understand your question. *%.2x *is only a precision
>> specifier still.
>> (%.2x was used for neat formatting only, because you are printing the
>> values only 1 Byte long and a Byte can occupy at max 2digits in hex)
>>
>> >>>>hex representated by 4 bits.
>> Yes hex is represented by 4 bits i.e. 1 Byte and that's what you are
>> reading with a char pointer*,  1 Byte each time and printing the values in
>> those Bytes.
>>
>> >>>>total we have to represent 32 bits and 8 bits in eachplz xplain
>> Each output represents 32bits only. 1 Byte each (in total 4Bytes)
>>
>> It's showing you the memory layout. You stored *i = 1; *and when probed
>> it using a char pointer. you found following four bytes written:  *01 00
>> 00 00*
>> It shows that on your machine:
>> 1. int is 4bytes long. (4x1Byte)
>> 2. First byte stores the least significant value, hence you are working
>> on a Little endian machine.
>>
>> similarly, for pointer:
>> char pointer reads 1 Byte at a time. It read 4Bytes in total i.e. 32
>> bits. Hence, you are working on a 32 bit machine. (as pointer has value:
>> *44 ff 28 00, *address of i)*.*
>> *
>> *
>> *
>> *
>> PS: This is an algorithm group, please refrain from asking such language
>> specific questions.
>>
>> On 21 October 2012 00:19, rahul sharma  wrote:
>>
>>> Actually i have taken form   http://www.geeksforgeeks.org/archives/730
>>> Please explain me o/p...as hex representated by 4 bitsthen how cum
>>> is following o/p
>>>  00 00 80 3f
>>>  01 00 00 00
>>>  44 ff 28 00
>>>  01 00 00 00
>>>
>>> total we have to represent 32 bits and 8 bits in eachplz xplain
>>>
>>> On Sun, Oct 21, 2012 at 12:05 AM, rahul sharma 
>>> wrote:
>>>
>>>> void show_bytes(byte_pointer start, int len)
>>>> {
>>>>  int i;
>>>>  for (i = 0; i < len; i++)
>>>>printf(" %.2x", start[i]);
>>>>  printf("\n");
>>>> }
>>>>
>>>>
>>>>
>>>> byte_pointr is unsigned char *...typedef unsigned char *
>>>> byte_pointer
>>>> plz tell me use of %.2x  i knowx is for hexadoes it mean print
>>>> 8 bites of address in 4 hexa of 2 bits???i cant get xactly plz explain
>>>>
>>>
>>>  --
>>> 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] Adobe written test question

2012-10-25 Thread rahul sharma
@all.can u provide me working code for use of extern..whenever i try to
use..linker error comes...like any simple codefor use of extern
On Thu, Oct 25, 2012 at 9:49 AM, Nishant Pandey <
nishant.bits.me...@gmail.com> wrote:

> i think arr[10] and int *arr are two different declaration when ,when
> compiler tried to link with the memory of int arr[10] it could nt find it ,
> as u have declraed it to be integer type pointer , and in file 1 it could
> find integer pointer .
>
> On Wed, Oct 24, 2012 at 11:06 PM, rahul sharma wrote:
>
>> int arr[10] // in fyl 1
>>
>> now in fyl 2
>>
>> extern int *arr
>> void foo()
>> {
>> arr[0]=10;
>> }
>> what kind of problem can be there?in what condition and y?
>>
>> plz comment
>>
>> --
>> 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: Does recusrion creates array or its by address??

2012-10-24 Thread rahul sharma
I think it is overwritng old values when child end..parent overwrite old
value with new..m i ryt?

On Thu, Oct 25, 2012 at 3:00 AM, rahul sharma wrote:

> I wana ask that when we pass array by recursion then as we know formal
> parameters are passed by value and array by base address/pointre..so in
> following program path[] arra contain differnt data each recursive call and
> when child function return their data is also deleted i.e when we are at
> parent there is only data till parent.So we are having different values in
> array in recursion tre..So does it passes by value in recursion.If No then
> hw this is implemented??Silly doubt..Please commentthnx in advance...  
> Given
> a binary tree, print out all of its root-to-leaf paths one per line.
> void printPathsRecur(struct node* node, int path[], int pathLen)
>  {
>if (node==NULL) return;
>
>   /* append this node to the path array */
>path[pathLen] = node->data;
>pathLen++;
>
>   /* it's a leaf, so print the path that led to here */
>if (node->left==NULL && node->right==NULL)
>{
>  printArray(path, pathLen);
>}
>else
>{
>/* otherwise try both subtrees */
>  printPathsRecur(node->left, path, pathLen);
>  printPathsRecur(node->right, path, pathLen);
>}
>  }
>

-- 
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] Adobe written test question

2012-10-24 Thread rahul sharma
int arr[10] // in fyl 1

now in fyl 2

extern int *arr
void foo()
{
arr[0]=10;
}
what kind of problem can be there?in what condition and y?

plz comment

-- 
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 o/p adobe

2012-10-24 Thread rahul sharma
can nyone provide me dummy code of how exactly to use extern in c..
in dev environment

when i declare int i in one fyl
and try use use with extern int i in another then it doesnt compile..plz
coment

On Wed, Oct 24, 2012 at 9:58 PM, rahul sharma wrote:

> Then why its not running?
>
>
> On Wed, Oct 24, 2012 at 6:50 PM, SHOBHIT GUPTA  > wrote:
>
>> http://www.geeksforgeeks.org/archives/840
>>
>> By default, the declaration and definition of a C function have “extern”
>> prepended with them. It means even though we don’t use extern with the
>> declaration/definition of C functions, it is present there. For example,
>> when we write.
>>
>> int foo(int arg1, char arg2);
>>
>> There’s an extern present in the beginning which is hidden and the
>> compiler treats it as below.
>>
>> extern int foo(int arg1, char arg2);
>>
>>
>> On Wed, Oct 24, 2012 at 4:40 PM, rahul sharma wrote:
>>
>>> Pleaase reply with sol as asp
>>>
>>> Fille 1:
>>> #include
>>> extern int i;
>>>
>>> extern int j;
>>> void next(void);
>>> int main()
>>> {
>>> ++i;
>>> printf("%d",i);
>>> next();
>>> getchar();
>>> }
>>> int i=3;
>>> void next()
>>> {
>>>  ++i;
>>>  printf("%d",i);
>>>  printf("%d",j);
>>> other();
>>>  }
>>> File 2:
>>> extern int i;
>>>
>>> void other()
>>> {
>>>  ++i;
>>> printf("%d",i)'
>>> }
>>>
>>> How cum file 1 knows what is other();as we havnet define with
>>> extern void other();
>>> it should be error
>>> but when i include the statemetn extern void other,then also it shows??
>>> pls provide me o/p of this questiona nd also tell how use use variable
>>> of one file in other as simply writing extern in a is not accesing global a
>>> of other file
>>>
>>> --
>>> 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] C o/p adobe

2012-10-24 Thread rahul sharma
Then why its not running?

On Wed, Oct 24, 2012 at 6:50 PM, SHOBHIT GUPTA
wrote:

> http://www.geeksforgeeks.org/archives/840
>
> By default, the declaration and definition of a C function have “extern”
> prepended with them. It means even though we don’t use extern with the
> declaration/definition of C functions, it is present there. For example,
> when we write.
>
> int foo(int arg1, char arg2);
>
> There’s an extern present in the beginning which is hidden and the
> compiler treats it as below.
>
> extern int foo(int arg1, char arg2);
>
>
> On Wed, Oct 24, 2012 at 4:40 PM, rahul sharma wrote:
>
>> Pleaase reply with sol as asp
>>
>> Fille 1:
>> #include
>> extern int i;
>>
>> extern int j;
>> void next(void);
>> int main()
>> {
>> ++i;
>> printf("%d",i);
>> next();
>> getchar();
>> }
>> int i=3;
>> void next()
>> {
>>  ++i;
>>  printf("%d",i);
>>  printf("%d",j);
>> other();
>>  }
>> File 2:
>> extern int i;
>>
>> void other()
>> {
>>  ++i;
>> printf("%d",i)'
>> }
>>
>> How cum file 1 knows what is other();as we havnet define with
>> extern void other();
>> it should be error
>> but when i include the statemetn extern void other,then also it shows??
>> pls provide me o/p of this questiona nd also tell how use use variable of
>> one file in other as simply writing extern in a is not accesing global a of
>> other file
>>
>> --
>> 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] second smallest in array

2012-10-24 Thread rahul sharma
for this shall we process all items and parallely calculate first and
second max.
or tournament methos i best for thsi..
if tournament method is best can anybody provide me with code with
tournament method to find second smallest..

-- 
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 o/p adobe

2012-10-24 Thread rahul sharma
Pleaase reply with sol as asp

Fille 1:
#include
extern int i;

extern int j;
void next(void);
int main()
{
++i;
printf("%d",i);
next();
getchar();
}
int i=3;
void next()
{
 ++i;
 printf("%d",i);
 printf("%d",j);
other();
 }
File 2:
extern int i;

void other()
{
 ++i;
printf("%d",i)'
}

How cum file 1 knows what is other();as we havnet define with
extern void other();
it should be error
but when i include the statemetn extern void other,then also it shows??
pls provide me o/p of this questiona nd also tell how use use variable of
one file in other as simply writing extern in a is not accesing global a of
other file

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



  1   2   3   4   >