Re: [algogeeks] Problem with Virtual Function

2010-06-12 Thread Rohit Saraf
M-speed is private and you cannot call it from outside myPlugin. (though i
did not understand what u wanted to say)
Can you write ur prob explicitly?
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 12:20 PM, akshay khatri
wrote:

> I have the following code structure
> in my file myPlugin.h , i have defined this
>
>virtual int speed();
>
> and gave a dummy implementation in myPlugin.cpp
>
> In another file otherPlugin.h I have included this line:
>
>#include 
>private:
>int m_speed;
>
> also class otherPlugin inherits myPlugin (public scope)
> I want to redefine speed in otherPlugin.cpp
> How should I return a value fromspeed() in it ?
>
>  int myPlugin::speed()
>{
>   return m_speed;
>}
> or
>int otherPlugin::speed()
>{
>  return m_speed;
>}
>
> or anything else ?
>
> The error I get is that: m_speed was not declared in this scope.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] Problem with Virtual Function

2010-06-12 Thread akshay khatri
I have the following code structure
in my file myPlugin.h , i have defined this

virtual int speed();

and gave a dummy implementation in myPlugin.cpp

In another file otherPlugin.h I have included this line:

#include 
private:
int m_speed;

also class otherPlugin inherits myPlugin (public scope)
I want to redefine speed in otherPlugin.cpp
How should I return a value fromspeed() in it ?

 int myPlugin::speed()
{
   return m_speed;
}
or
int otherPlugin::speed()
{
  return m_speed;
}

or anything else ?

The error I get is that: m_speed was not declared in this scope.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] union- c

2010-06-12 Thread Rohit Saraf
what is this for...
and which conversion are you talking abt?

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sat, Jun 12, 2010 at 11:20 PM, divya  wrote:

> #include 
> main()
> {
>  union {
>  long l_e;
>  float f_e;
>  } u;
>
>  long l_v;
>  float f_v;
>  l_v = u.l_e = 10;
>  printf("%f ", (float)l_v);
>  printf("%f ", u.f_e);
>  f_v = u.f_e = 3.555;
>  printf("%d ", (long)f_v);
>  printf("%d ", u.l_e);
> }
> hw to do the conversion here..
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread Rohit Saraf
which compiler do you use?

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 10:46 AM, divya jain wrote:

> hmm..the prob is here wid my compiler...!!
> anyways thanks to all
>
>
> On 13 June 2010 10:28, Rohit Saraf  wrote:
>
>> oh.. yes.. my mistake
>> (strings\0).length=8 :P
>>
>> --
>> Rohit Saraf
>> Second Year Undergraduate,
>> Dept. of Computer Science and Engineering
>> IIT Bombay
>> http://www.cse.iitb.ac.in/~rohitfeb14
>>
>>
>> On Sun, Jun 13, 2010 at 10:24 AM, Rahul Kushwaha <
>> rahul.kushw...@gmail.com> wrote:
>>
>>> #include
>>> int main()
>>> {
>>> char str[7]="strings";
>>> printf("%s\n",str);
>>> return 0;
>>> }
>>>
>>>
>>> it is showing error on code block and dev cpp also...
>>> this  is an error no doubt.
>>> also mentioned in denis m ritchie
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from 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 algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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- pointers

2010-06-12 Thread Rohit Saraf
@divya: u r rite.. that * should not be there

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 11:07 AM, divya jain wrote:

> ptr is a pointer naaa...then why ptr-p=*(&(arr+1)-&arr)  ???
> why not &(arr+1)-&arr ??
> i knw m wrong somewhr...plz correct me
>
>
> On 13 June 2010 07:57, Mahesh_JNU  wrote:
>
>> agreed .
>>
>>
>> On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar wrote:
>>
>>> 111
>>> 222
>>> 333
>>> 344
>>> ptr++ ->u do posst increment
>>> hence it goes to 1
>>> ptr-p=*(&(arr+1)-&arr)=1
>>> llrly for other cases
>>> when u do *ptr++ due to operator precedence ptr++ is done and then
>>> dereferenced.
>>> hence u get 222
>>> next *++ptr
>>> the ptr is incremented after dereferencing hence u get 333
>>> next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr)
>>> hence u get 3 but others refer to location hence 44
>>>
>>>
>>> On Sat, Jun 12, 2010 at 9:21 PM, divya  wrote:
>>>
 #include
 int main()
 {
 static int arr[]={0,1,2,3,4};
 int *p[]={arr,arr+1,arr+2,arr+3,arr+4};
 int **ptr=p;
 ptr++;
 printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
 *ptr++;
 printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
 *++ptr;
 printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
 ++*ptr;
 printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
 return 0;
 }
 wat shd b the o/p n why...

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


>>>
>>>
>>> --
>>> yezhu malai vaasa venkataramana Govinda Govinda
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>>   Mahesh Giri
>>  MCA Final Sem
>> JNU, New Delhi
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] output

2010-06-12 Thread Rohit Saraf
I read that. But still it should not be compiled as per the standard.

The latest GNU C/C++ compiler correctly fails to compile this

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 10:44 AM, divya jain wrote:

> sorry for the silly question i got rhe point..
>
> @ rohit
> compiler is doing rite..read mahesh's explanatn
>
> On 13 June 2010 08:27, Rohit Saraf  wrote:
>
>> This is very bad. Change your compiler if it compiles this stuff :)
>>
>> btw.. which compiler is it?
>>
>> Output for me :
>> ro...@rohit-laptop:~/dump$ gcc c.c
>> c.c: In function ‘main’:
>> c.c:14: error: incompatible types when assigning to type ‘char[20]’ from
>> type ‘char *’
>> c.c:15: error: incompatible types when assigning to type ‘char[20]’ from
>> type ‘char *’
>>
>> --
>> Rohit Saraf
>> Second Year Undergraduate,
>> Dept. of Computer Science and Engineering
>> IIT Bombay
>> http://www.cse.iitb.ac.in/~rohitfeb14
>>
>>
>>
>> On Sun, Jun 13, 2010 at 8:13 AM, Mahesh_JNU wrote:
>>
>>> Well
>>>
>>> As we know for copying the string we can can copy it as a simple variable
>>> as in case of address copying.
>>> when u r doing names[3] = names[4] , it means u r trying to copy it
>>> directly
>>> bt in the case of  char *names[] , as it is the array of pointers so u
>>> can copy the address from one pointer to another pointer
>>>
>>> Thanks
>>>
>>>
>>> On Sat, Jun 12, 2010 at 9:12 PM, divya  wrote:
>>>
 #include

 int main()
 { char names[][20]={
 "roshni",
 "manish",
 "sona",
 "baiju",
 "ritu"
 };
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for(i=0;i<=4;i++)
 printf("%s",names[i]);
 printf("\n");
 return 0;
 }

 here i get l value required as error and if i replace char names[][2]
 with char *names[].. then there is no error nd the names[3] n names[4]
 interchange
 pl explain why???

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


>>>
>>>
>>> --
>>>   Mahesh Giri
>>>  MCA Final Sem
>>> JNU, New Delhi
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from 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 algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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: identify the recurring part for a given decimal no

2010-06-12 Thread divya jain
thanks anurag :)

On 12 June 2010 20:07, Anurag Sharma  wrote:

> Since we are given numerator 'n' and denominator 'd' separately already.
> and considering n and d as integers and d!=0 we can safely assume n/d as
> either a terminating fraction or a non terminating but recurring fraction,
> in which case we have to find the recurring digits of the fraction.
>
> Now what I suggested was almost same as Ravi's approach.
> take a Set 'S' keeping tuples (R,Q) where R is the current remainder and Q
> is the factor such that d*Q is subtracted from the number to get R.
> In other words. if at an intermediate step of division we have 'a' as the
> divident left then Q=floor(a/d) and R=a%d
>
> Keep dividing 'n' by 'd' like it is done manually. After every division
> check-
> 1. If the current remainder is not present in 'S' then add current
> remainder 'R' and corresponding quotient 'Q' in the set
> 2. If R is found in the set S, then all the following entries in the set
> until end will constitute the recurring digits.
> taking Ravi's example:-
>
> Example:
>   7) 9 (1.*285714*28S=[]
>7
>--
> 20   S=[(2,2)]
>  14
>  ---
>60S=[(2,2), (6,8)]
> 56
>  ---
>   40 S=[(2,2), (6,8),
> (4,5)]
>   35
>   ---
>  50  S=[(2,2), (6,8),
> (4,5), (5,7)]
>   49
>---
>  10  S=[(2,2), (6,8),
> (4,5), (5,7), (1,1)]
> 7
>  
>  30  S=[(2,2), (6,8),
> (4,5), (5,7), (1,1), (3,4)]
>   28   ^
>      |
>   20 2 is found in S here,
> so recurring digits are "285714"
>14
>
>   
>60
> 56
>  repeats
>
>
> hope its clear
>
>
> Anurag Sharma
>
>
> On Sat, Jun 12, 2010 at 4:02 PM, divya jain wrote:
>
>> @anurag
>>
>> i dint get ur approach..which numerator n denominator u r talking
>> about..plz explain.. thanks in advance
>>
>> On 11 June 2010 08:57, Anurag Sharma  wrote:
>>
>>> Please note that the fractional repeating part is recurring. and so that
>>> 4th temporary variable assignment will be this way->
>>> temp=x*1 - x= 233456.34563456...  - 23.34563456 = 233433.0  (
>>> mark the fractional part is 0 now since the infinitely repeating 3456...
>>> will get cancelled)
>>> In this  case you can say that 4 places are repeating. But yes its
>>> according to the maths and in any programming language whenever you divide
>>> the numerator and denominator you wont get this infinitely recurring decimal
>>> places.
>>>
>>> @divya, also your approach wont work if the recurring fractional digits
>>> start after few places from the decimal like in the case of
>>> 23.123345634563456  (note here after the decimal place 123 is not
>>> repeating while 3456.. after this 123 is repeating.)
>>>
>>> What I suggest in this case is keep dividing the numerator by denominator
>>> and at every step keep inserting the tupple (remainder, quotient) of that
>>> division step in a set. and before inserting in the set check whether it
>>> already exists. If yes then the all the quotients following from that point
>>> (including the point) will be recurring.
>>>
>>> Regards,
>>>
>>> Anurag Sharma
>>>
>>>
>>>
>>> On Thu, Jun 10, 2010 at 8:25 AM, Veer Sharma 
>>> wrote:
>>>
 Seems it wont work...
 x=23.34563456

 temp = x*100 -x = 233.4563456 - 23.34563456 = 210.11071104
 temp = x*100 -x = 2334.563456 - 23.34563456 = 2311.21782144
 temp = x*1000 -x =  23345.63456 - 23.34563456 = 23322.28892544
 temp = x*1 -x =  233456.3456 - 23.34563456 = 233432.6544
 temp = x*10 -x = 2334563.456 - 23.34563456 = 2334540.11036544

 ...

 On Jun 9, 11:24 pm, Anurag Sharma  wrote:
 > multiply the original number x=23.34563456
 >
 > Anurag Sharma
 >
 > On Wed, Jun 9, 2010 at 10:36 PM, Veer Sharma <
 thisisv...@rediffmail.com>wrote:
 >
 >
 >
 > > One question:
 >
 > > No x = 23.34563456
 > > temp = x X 10 = 233.4563456
 > > temp = temp - x = 210.11071104
 > > decimal part zero? No.
 > > Now multiply the no. with 100. Which no? original x (= 23.34563456)
 or
 > > new no. temp (=210.11071104)?
 >
 > > On Jun 9, 8:12 pm, divya jain  wrote:
 > > > multiply the no. with 10 nd store in temp. now subtract no from
 temp.
 > > check
 > > > if the decimal part is zero if y

Re: [algogeeks] c- pointers

2010-06-12 Thread divya jain
ptr is a pointer naaa...then why ptr-p=*(&(arr+1)-&arr)  ???
why not &(arr+1)-&arr ??
i knw m wrong somewhr...plz correct me

On 13 June 2010 07:57, Mahesh_JNU  wrote:

> agreed .
>
>
> On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar wrote:
>
>> 111
>> 222
>> 333
>> 344
>> ptr++ ->u do posst increment
>> hence it goes to 1
>> ptr-p=*(&(arr+1)-&arr)=1
>> llrly for other cases
>> when u do *ptr++ due to operator precedence ptr++ is done and then
>> dereferenced.
>> hence u get 222
>> next *++ptr
>> the ptr is incremented after dereferencing hence u get 333
>> next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr)
>> hence u get 3 but others refer to location hence 44
>>
>>
>> On Sat, Jun 12, 2010 at 9:21 PM, divya  wrote:
>>
>>> #include
>>> int main()
>>> {
>>> static int arr[]={0,1,2,3,4};
>>> int *p[]={arr,arr+1,arr+2,arr+3,arr+4};
>>> int **ptr=p;
>>> ptr++;
>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>>> *ptr++;
>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>>> *++ptr;
>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>>> ++*ptr;
>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>>> return 0;
>>> }
>>> wat shd b the o/p n why...
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>>
>> --
>> yezhu malai vaasa venkataramana Govinda Govinda
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>   Mahesh Giri
>  MCA Final Sem
> JNU, New Delhi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] sorting

2010-06-12 Thread harit agarwal
sort both arrays separetely and then perform merge operation ..it is
O(mlogm+nlog)...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread divya jain
hmm..the prob is here wid my compiler...!!
anyways thanks to all

On 13 June 2010 10:28, Rohit Saraf  wrote:

> oh.. yes.. my mistake
> (strings\0).length=8 :P
>
> --
> Rohit Saraf
> Second Year Undergraduate,
> Dept. of Computer Science and Engineering
> IIT Bombay
> http://www.cse.iitb.ac.in/~rohitfeb14
>
>
> On Sun, Jun 13, 2010 at 10:24 AM, Rahul Kushwaha  > wrote:
>
>> #include
>> int main()
>> {
>> char str[7]="strings";
>> printf("%s\n",str);
>> return 0;
>> }
>>
>>
>> it is showing error on code block and dev cpp also...
>> this  is an error no doubt.
>> also mentioned in denis m ritchie
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] output

2010-06-12 Thread divya jain
sorry for the silly question i got rhe point..

@ rohit
compiler is doing rite..read mahesh's explanatn

On 13 June 2010 08:27, Rohit Saraf  wrote:

> This is very bad. Change your compiler if it compiles this stuff :)
>
> btw.. which compiler is it?
>
> Output for me :
> ro...@rohit-laptop:~/dump$ gcc c.c
> c.c: In function ‘main’:
> c.c:14: error: incompatible types when assigning to type ‘char[20]’ from
> type ‘char *’
> c.c:15: error: incompatible types when assigning to type ‘char[20]’ from
> type ‘char *’
>
> --
> Rohit Saraf
> Second Year Undergraduate,
> Dept. of Computer Science and Engineering
> IIT Bombay
> http://www.cse.iitb.ac.in/~rohitfeb14
>
>
>
> On Sun, Jun 13, 2010 at 8:13 AM, Mahesh_JNU wrote:
>
>> Well
>>
>> As we know for copying the string we can can copy it as a simple variable
>> as in case of address copying.
>> when u r doing names[3] = names[4] , it means u r trying to copy it
>> directly
>> bt in the case of  char *names[] , as it is the array of pointers so u can
>> copy the address from one pointer to another pointer
>>
>> Thanks
>>
>>
>> On Sat, Jun 12, 2010 at 9:12 PM, divya  wrote:
>>
>>> #include
>>>
>>> int main()
>>> { char names[][20]={
>>> "roshni",
>>> "manish",
>>> "sona",
>>> "baiju",
>>> "ritu"
>>> };
>>> int i;
>>> char *t;
>>> t=names[3];
>>> names[3]=names[4];
>>> names[4]=t;
>>> for(i=0;i<=4;i++)
>>> printf("%s",names[i]);
>>> printf("\n");
>>> return 0;
>>> }
>>>
>>> here i get l value required as error and if i replace char names[][2]
>>> with char *names[].. then there is no error nd the names[3] n names[4]
>>> interchange
>>> pl explain why???
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>>
>> --
>>   Mahesh Giri
>>  MCA Final Sem
>> JNU, New Delhi
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread Rohit Saraf
oh.. yes.. my mistake
(strings\0).length=8 :P

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 10:24 AM, Rahul Kushwaha
wrote:

> #include
> int main()
> {
> char str[7]="strings";
> printf("%s\n",str);
> return 0;
> }
>
>
> it is showing error on code block and dev cpp also...
> this  is an error no doubt.
> also mentioned in denis m ritchie
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread Rahul Kushwaha
#include
int main()
{
char str[7]="strings";
printf("%s\n",str);
return 0;
}


it is showing error on code block and dev cpp also...
this  is an error no doubt.
also mentioned in denis m ritchie

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread Rohit Saraf
@Satya: I don't think what you have coded will work.. though i have not read
the whole code.

Don't you think a simple divide and conquer scheme would work...(almost like
the mergesort)

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sat, Jun 12, 2010 at 9:06 PM, Satya  wrote:

> This problem seems to be finding the maxdiff in an array.
>
> int maxdiff ( int A[], int n ) {
> // write your code here
> int max_diff = A[1] - A[0];
>   int min_element = A[0];
>   int i;
>   for(i = 1; i < n; i++)
>   {
> if(A[i] - min_element > max_diff)
>   max_diff = A[i] - min_element;
> if(A[i] < min_element)
>  min_element = A[i];
>   }
>   if(max_diff < 0)
> max_diff  = 0;
>   return max_diff;
> }
>
> .
> Satya
>
>
>
> On Sat, Jun 12, 2010 at 3:18 PM, divya jain wrote:
>
>> i think we need to maintain an array of index as well such that while
>> subtracting smallest element from largest element of sorted array we need to
>> check if index of largest is greater than index of smallest. if no..then
>> this is not the solution..
>>
>>
>> On 12 June 2010 14:20, Modeling Expert wrote:
>>
>>> Let's say array A , 1 till n
>>>
>>> s_index = 1;  e_index = n ;
>>> start  = &A[s_index] ;
>>> end = &A[e_index];
>>> result = 0;  //!  j - i
>>> if ( *end > *start ){
>>>result =  index(end) - index(start)  ( only of its greater than
>>> previous value of result )
>>>break ;
>>> }else{
>>> end-- ;  //! till you reach start
>>> }
>>>
>>> now increment start , and repeat the process but only from A[n] till
>>> A[++result] , going further
>>> down is not required now.
>>>
>>> Average time < o(n^2)
>>>
>>> Worst case : let's say we have descending array of ints, theno(n^2)
>>>
>>> Please suggest improvements
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Jun 12, 12:14 am, amit  wrote:
>>> > given an array A of n elements.
>>> > for indexes j , i such that j>i
>>> > maximize( j - i )
>>> > such that A[j] - A [ i ]> 0 .
>>> >
>>> > Any Algorithm less than O(n^2) would do.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from 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 algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] output

2010-06-12 Thread Rohit Saraf
This is very bad. Change your compiler if it compiles this stuff :)

btw.. which compiler is it?

Output for me :
ro...@rohit-laptop:~/dump$ gcc c.c
c.c: In function ‘main’:
c.c:14: error: incompatible types when assigning to type ‘char[20]’ from
type ‘char *’
c.c:15: error: incompatible types when assigning to type ‘char[20]’ from
type ‘char *’

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 8:13 AM, Mahesh_JNU wrote:

> Well
>
> As we know for copying the string we can can copy it as a simple variable
> as in case of address copying.
> when u r doing names[3] = names[4] , it means u r trying to copy it
> directly
> bt in the case of  char *names[] , as it is the array of pointers so u can
> copy the address from one pointer to another pointer
>
> Thanks
>
>
> On Sat, Jun 12, 2010 at 9:12 PM, divya  wrote:
>
>> #include
>>
>> int main()
>> { char names[][20]={
>> "roshni",
>> "manish",
>> "sona",
>> "baiju",
>> "ritu"
>> };
>> int i;
>> char *t;
>> t=names[3];
>> names[3]=names[4];
>> names[4]=t;
>> for(i=0;i<=4;i++)
>> printf("%s",names[i]);
>> printf("\n");
>> return 0;
>> }
>>
>> here i get l value required as error and if i replace char names[][2]
>> with char *names[].. then there is no error nd the names[3] n names[4]
>> interchange
>> pl explain why???
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
>   Mahesh Giri
>  MCA Final Sem
> JNU, New Delhi
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread Rohit Saraf
@ram : i guess you have used some longer string and not "strings"

btw..  what is Mingw ?
gcc/g++ is not mingw, i guess

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Sun, Jun 13, 2010 at 8:13 AM, ram  wrote:

> D:\code\samplecode\main.cpp|5|error: initializer-string for array of chars
> is too long|
>
>
>
> I get this error on gcc (Mingw) .
>
>
>
> Though the array indexing starts from 0.
>
> The length specified in char str[7] is always straightforward . in this
> case char str[7]  . the length of str is seven not eight ;hence the error
>
> --
>
> ram
>
>
>
> *From:* algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] *On
> Behalf Of *sharad kumar
> *Sent:* 13 June 2010 07:59
> *To:* algogeeks@googlegroups.com
> *Subject:* Re: [algogeeks] c array
>
>
>
> hey array indexing starts from 0 rite??
> then y shld u get overflow in first place..
> s t  r  i n g s \0
> 0 1 2 3 4 5 6 7
>
> On Sat, Jun 12, 2010 at 9:14 PM, divya  wrote:
>
> #include
> int main()
> {
>
> char str[7]="strings";
> printf("%s\n",str);
> return 0;
> }
>
> here i m nt getting overflow error whereas if i write stringss instead
> of strings then there is overflow error.. isnt null stored after s in
> strings nd 1st case shd also give overflow???
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
>
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
>
>
> --
> yezhu malai vaasa venkataramana Govinda Govinda
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread ram
D:\code\samplecode\main.cpp|5|error: initializer-string for array of chars
is too long|

 

I get this error on gcc (Mingw) .

 

Though the array indexing starts from 0. 

The length specified in char str[7] is always straightforward . in this case
char str[7]  . the length of str is seven not eight ;hence the error

--

ram

 

From: algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] On
Behalf Of sharad kumar
Sent: 13 June 2010 07:59
To: algogeeks@googlegroups.com
Subject: Re: [algogeeks] c array

 

hey array indexing starts from 0 rite??
then y shld u get overflow in first place..
s t  r  i n g s \0
0 1 2 3 4 5 6 7



On Sat, Jun 12, 2010 at 9:14 PM, divya  wrote:

#include
int main()
{

char str[7]="strings";
printf("%s\n",str);
return 0;
}

here i m nt getting overflow error whereas if i write stringss instead
of strings then there is overflow error.. isnt null stored after s in
strings nd 1st case shd also give overflow???

--

You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.

To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
 .
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.




-- 
yezhu malai vaasa venkataramana Govinda Govinda

-- 
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] output

2010-06-12 Thread Mahesh_JNU
Well

As we know for copying the string we can can copy it as a simple variable as
in case of address copying.
when u r doing names[3] = names[4] , it means u r trying to copy it directly
bt in the case of  char *names[] , as it is the array of pointers so u can
copy the address from one pointer to another pointer

Thanks

On Sat, Jun 12, 2010 at 9:12 PM, divya  wrote:

> #include
>
> int main()
> { char names[][20]={
> "roshni",
> "manish",
> "sona",
> "baiju",
> "ritu"
> };
> int i;
> char *t;
> t=names[3];
> names[3]=names[4];
> names[4]=t;
> for(i=0;i<=4;i++)
> printf("%s",names[i]);
> printf("\n");
> return 0;
> }
>
> here i get l value required as error and if i replace char names[][2]
> with char *names[].. then there is no error nd the names[3] n names[4]
> interchange
> pl explain why???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
  Mahesh Giri
 MCA Final Sem
JNU, New Delhi

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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- pointers

2010-06-12 Thread Mahesh_JNU
agreed .

On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar wrote:

> 111
> 222
> 333
> 344
> ptr++ ->u do posst increment
> hence it goes to 1
> ptr-p=*(&(arr+1)-&arr)=1
> llrly for other cases
> when u do *ptr++ due to operator precedence ptr++ is done and then
> dereferenced.
> hence u get 222
> next *++ptr
> the ptr is incremented after dereferencing hence u get 333
> next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr)
> hence u get 3 but others refer to location hence 44
>
>
> On Sat, Jun 12, 2010 at 9:21 PM, divya  wrote:
>
>> #include
>> int main()
>> {
>> static int arr[]={0,1,2,3,4};
>> int *p[]={arr,arr+1,arr+2,arr+3,arr+4};
>> int **ptr=p;
>> ptr++;
>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>> *ptr++;
>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>> *++ptr;
>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>> ++*ptr;
>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
>> return 0;
>> }
>> wat shd b the o/p n why...
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> yezhu malai vaasa venkataramana Govinda Govinda
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
  Mahesh Giri
 MCA Final Sem
JNU, New Delhi

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] nibbles

2010-06-12 Thread sharad kumar
#include 

unsigned char swap_nibbles(unsigned char c)
{
unsigned char temp1, temp2;
temp1 = c & 0x0F;
temp2 = c & 0xF0;
temp1=temp1 << 4;
temp2=temp2 >> 4;

return(temp2|temp1); //adding the bits
}

int main(void)
{
char ch=0x34;
printf("\nThe exchanged value is %x",swap_nibbles(ch));

getchar();
return 0;
}


On Sat, Jun 12, 2010 at 9:35 PM, jalaj jaiswal wrote:

>
> write an algorithm to reverse a nibble in one pass...using bitwise
> operators
> --
> With Regards,
> Jalaj Jaiswal
> +919026283397
> B.TECH IT
> IIIT ALLAHABAD
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
yezhu malai vaasa venkataramana Govinda Govinda

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread sharad kumar
hey array indexing starts from 0 rite??
then y shld u get overflow in first place..
s t  r  i n g s \0
0 1 2 3 4 5 6 7


On Sat, Jun 12, 2010 at 9:14 PM, divya  wrote:

> #include
> int main()
> {
> char str[7]="strings";
> printf("%s\n",str);
> return 0;
> }
>
> here i m nt getting overflow error whereas if i write stringss instead
> of strings then there is overflow error.. isnt null stored after s in
> strings nd 1st case shd also give overflow???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
yezhu malai vaasa venkataramana Govinda Govinda

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] sorting

2010-06-12 Thread sharad kumar
is it like this sort 2 unsorted arrays of size m and n such m>n such that
array of size m can hold all n element apart from m element.an inplace
solution is required???
if it is so then copy the elements from n size array elements to m size
array and then perform quick sort ..

On Sat, Jun 12, 2010 at 10:27 PM, sharad  wrote:

> an algorithm to sort two unsorted arrays, the former enough lengthy to
> accomodate all the elements in the latter, in place
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
yezhu malai vaasa venkataramana Govinda Govinda

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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- pointers

2010-06-12 Thread sharad kumar
111
222
333
344
ptr++ ->u do posst increment
hence it goes to 1
ptr-p=*(&(arr+1)-&arr)=1
llrly for other cases
when u do *ptr++ due to operator precedence ptr++ is done and then
dereferenced.
hence u get 222
next *++ptr
the ptr is incremented after dereferencing hence u get 333
next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr)
hence u get 3 but others refer to location hence 44

On Sat, Jun 12, 2010 at 9:21 PM, divya  wrote:

> #include
> int main()
> {
> static int arr[]={0,1,2,3,4};
> int *p[]={arr,arr+1,arr+2,arr+3,arr+4};
> int **ptr=p;
> ptr++;
> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
> *ptr++;
> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
> *++ptr;
> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
> ++*ptr;
> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
> return 0;
> }
> wat shd b the o/p n why...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
yezhu malai vaasa venkataramana Govinda Govinda

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread Modeling Expert
@sourav : if I understood problem correctly , you can't change the
list ( hence you can't sort ).
and list can containt + . - ive ints .
e.g. say list is

 7 9 1 -4 8 0 0 0 3 1 0

Here answer is index(0) - index(-4) = 11

@divya : didn't get what you said , but guess you also thought of
sorting array .

Correct me if I am wrong here.
-Manish

On Jun 12, 2:48 pm, divya jain  wrote:
> i think we need to maintain an array of index as well such that while
> subtracting smallest element from largest element of sorted array we need to
> check if index of largest is greater than index of smallest. if no..then
> this is not the solution..
>
> On 12 June 2010 14:20, Modeling Expert  wrote:
>
> > Let's say array A , 1 till n
>
> > s_index = 1;  e_index = n ;
> > start  = &A[s_index] ;
> > end = &A[e_index];
> > result = 0;                  //!  j - i
> > if ( *end > *start ){
> >    result =  index(end) - index(start)  ( only of its greater than
> > previous value of result )
> >    break ;
> > }else{
> >     end-- ;  //! till you reach start
> > }
>
> > now increment start , and repeat the process but only from A[n] till
> > A[++result] , going further
> > down is not required now.
>
> > Average time < o(n^2)
>
> > Worst case : let's say we have descending array of ints, theno(n^2)
>
> > Please suggest improvements
>
> > On Jun 12, 12:14 am, amit  wrote:
> > > given an array A of n elements.
> > > for indexes j , i such that j>i
> > > maximize( j - i )
> > > such that A[j] - A [ i ]> 0 .
>
> > > Any Algorithm less than O(n^2) would do.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] union- c

2010-06-12 Thread divya
#include 
main()
{
 union {
  long l_e;
  float f_e;
 } u;

 long l_v;
 float f_v;
 l_v = u.l_e = 10;
 printf("%f ", (float)l_v);
 printf("%f ", u.f_e);
 f_v = u.f_e = 3.555;
 printf("%d ", (long)f_v);
 printf("%d ", u.l_e);
}
hw to do the conversion here..

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] sorting

2010-06-12 Thread sharad
an algorithm to sort two unsorted arrays, the former enough lengthy to
accomodate all the elements in the latter, in place

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: identify the recurring part for a given decimal no

2010-06-12 Thread Anurag Sharma
Since we are given numerator 'n' and denominator 'd' separately already. and
considering n and d as integers and d!=0 we can safely assume n/d as either
a terminating fraction or a non terminating but recurring fraction, in which
case we have to find the recurring digits of the fraction.

Now what I suggested was almost same as Ravi's approach.
take a Set 'S' keeping tuples (R,Q) where R is the current remainder and Q
is the factor such that d*Q is subtracted from the number to get R.
In other words. if at an intermediate step of division we have 'a' as the
divident left then Q=floor(a/d) and R=a%d

Keep dividing 'n' by 'd' like it is done manually. After every division
check-
1. If the current remainder is not present in 'S' then add current remainder
'R' and corresponding quotient 'Q' in the set
2. If R is found in the set S, then all the following entries in the set
until end will constitute the recurring digits.
taking Ravi's example:-

Example:
  7) 9 (1.*285714*28S=[]
   7
   --
20   S=[(2,2)]
 14
 ---
   60S=[(2,2), (6,8)]
56
 ---
  40 S=[(2,2), (6,8), (4,5)]
  35
  ---
 50  S=[(2,2), (6,8), (4,5),
(5,7)]
  49
   ---
 10  S=[(2,2), (6,8), (4,5),
(5,7), (1,1)]
7
 
 30  S=[(2,2), (6,8), (4,5),
(5,7), (1,1), (3,4)]
  28   ^
     |
  20 2 is found in S here,
so recurring digits are "285714"
   14

  
   60
56
 repeats


hope its clear


Anurag Sharma


On Sat, Jun 12, 2010 at 4:02 PM, divya jain wrote:

> @anurag
>
> i dint get ur approach..which numerator n denominator u r talking
> about..plz explain.. thanks in advance
>
> On 11 June 2010 08:57, Anurag Sharma  wrote:
>
>> Please note that the fractional repeating part is recurring. and so that
>> 4th temporary variable assignment will be this way->
>> temp=x*1 - x= 233456.34563456...  - 23.34563456 = 233433.0  ( mark
>> the fractional part is 0 now since the infinitely repeating 3456... will get
>> cancelled)
>> In this  case you can say that 4 places are repeating. But yes its
>> according to the maths and in any programming language whenever you divide
>> the numerator and denominator you wont get this infinitely recurring decimal
>> places.
>>
>> @divya, also your approach wont work if the recurring fractional digits
>> start after few places from the decimal like in the case of
>> 23.123345634563456  (note here after the decimal place 123 is not
>> repeating while 3456.. after this 123 is repeating.)
>>
>> What I suggest in this case is keep dividing the numerator by denominator
>> and at every step keep inserting the tupple (remainder, quotient) of that
>> division step in a set. and before inserting in the set check whether it
>> already exists. If yes then the all the quotients following from that point
>> (including the point) will be recurring.
>>
>> Regards,
>>
>> Anurag Sharma
>>
>>
>>
>> On Thu, Jun 10, 2010 at 8:25 AM, Veer Sharma 
>> wrote:
>>
>>> Seems it wont work...
>>> x=23.34563456
>>>
>>> temp = x*100 -x = 233.4563456 - 23.34563456 = 210.11071104
>>> temp = x*100 -x = 2334.563456 - 23.34563456 = 2311.21782144
>>> temp = x*1000 -x =  23345.63456 - 23.34563456 = 23322.28892544
>>> temp = x*1 -x =  233456.3456 - 23.34563456 = 233432.6544
>>> temp = x*10 -x = 2334563.456 - 23.34563456 = 2334540.11036544
>>>
>>> ...
>>>
>>> On Jun 9, 11:24 pm, Anurag Sharma  wrote:
>>> > multiply the original number x=23.34563456
>>> >
>>> > Anurag Sharma
>>> >
>>> > On Wed, Jun 9, 2010 at 10:36 PM, Veer Sharma <
>>> thisisv...@rediffmail.com>wrote:
>>> >
>>> >
>>> >
>>> > > One question:
>>> >
>>> > > No x = 23.34563456
>>> > > temp = x X 10 = 233.4563456
>>> > > temp = temp - x = 210.11071104
>>> > > decimal part zero? No.
>>> > > Now multiply the no. with 100. Which no? original x (= 23.34563456)
>>> or
>>> > > new no. temp (=210.11071104)?
>>> >
>>> > > On Jun 9, 8:12 pm, divya jain  wrote:
>>> > > > multiply the no. with 10 nd store in temp. now subtract no from
>>> temp.
>>> > > check
>>> > > > if the decimal part is zero if yes.  then 1st digit after decimal
>>> is
>>> > > > recurring. if no. multiply the no with 100 and repeat . if this
>>> time
>>> > > decimal
>>> > > > part is zero then 2 digits after decimal r recurring nd so on..
>>> >
>>> > > > On 8 June 2010 21:45, 

[algogeeks] c- pointers

2010-06-12 Thread divya
#include
int main()
{
static int arr[]={0,1,2,3,4};
int *p[]={arr,arr+1,arr+2,arr+3,arr+4};
int **ptr=p;
ptr++;
printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
*ptr++;
printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
*++ptr;
printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
++*ptr;
printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr);
return 0;
}
wat shd b the o/p n why...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] output

2010-06-12 Thread divya
#include

int main()
{ char names[][20]={
"roshni",
"manish",
"sona",
"baiju",
"ritu"
};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for(i=0;i<=4;i++)
printf("%s",names[i]);
printf("\n");
return 0;
}

here i get l value required as error and if i replace char names[][2]
with char *names[].. then there is no error nd the names[3] n names[4]
interchange
pl explain why???

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] nibbles

2010-06-12 Thread jalaj jaiswal
write an algorithm to reverse a nibble in one pass...using bitwise operators
-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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 array

2010-06-12 Thread divya
#include
int main()
{
char str[7]="strings";
printf("%s\n",str);
return 0;
}

here i m nt getting overflow error whereas if i write stringss instead
of strings then there is overflow error.. isnt null stored after s in
strings nd 1st case shd also give overflow???

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread Satya
This problem seems to be finding the maxdiff in an array.

int maxdiff ( int A[], int n ) {
// write your code here
int max_diff = A[1] - A[0];
  int min_element = A[0];
  int i;
  for(i = 1; i < n; i++)
  {
if(A[i] - min_element > max_diff)
  max_diff = A[i] - min_element;
if(A[i] < min_element)
 min_element = A[i];
  }
  if(max_diff < 0)
max_diff  = 0;
  return max_diff;
}

.
Satya


On Sat, Jun 12, 2010 at 3:18 PM, divya jain wrote:

> i think we need to maintain an array of index as well such that while
> subtracting smallest element from largest element of sorted array we need to
> check if index of largest is greater than index of smallest. if no..then
> this is not the solution..
>
>
> On 12 June 2010 14:20, Modeling Expert wrote:
>
>> Let's say array A , 1 till n
>>
>> s_index = 1;  e_index = n ;
>> start  = &A[s_index] ;
>> end = &A[e_index];
>> result = 0;  //!  j - i
>> if ( *end > *start ){
>>result =  index(end) - index(start)  ( only of its greater than
>> previous value of result )
>>break ;
>> }else{
>> end-- ;  //! till you reach start
>> }
>>
>> now increment start , and repeat the process but only from A[n] till
>> A[++result] , going further
>> down is not required now.
>>
>> Average time < o(n^2)
>>
>> Worst case : let's say we have descending array of ints, theno(n^2)
>>
>> Please suggest improvements
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Jun 12, 12:14 am, amit  wrote:
>> > given an array A of n elements.
>> > for indexes j , i such that j>i
>> > maximize( j - i )
>> > such that A[j] - A [ i ]> 0 .
>> >
>> > Any Algorithm less than O(n^2) would do.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread Amir hossein Shahriari
yes we need to maintain an array that shows the real indexes before sorting
and then loop on the elements and find the minimum index that appeared
before a number in the sorted array and subtract it from it's index
and find the maximum difference

On 6/12/10, divya jain  wrote:
> i think we need to maintain an array of index as well such that while
> subtracting smallest element from largest element of sorted array we need to
> check if index of largest is greater than index of smallest. if no..then
> this is not the solution..
>
> On 12 June 2010 14:20, Modeling Expert  wrote:
>
>> Let's say array A , 1 till n
>>
>> s_index = 1;  e_index = n ;
>> start  = &A[s_index] ;
>> end = &A[e_index];
>> result = 0;  //!  j - i
>> if ( *end > *start ){
>>result =  index(end) - index(start)  ( only of its greater than
>> previous value of result )
>>break ;
>> }else{
>> end-- ;  //! till you reach start
>> }
>>
>> now increment start , and repeat the process but only from A[n] till
>> A[++result] , going further
>> down is not required now.
>>
>> Average time < o(n^2)
>>
>> Worst case : let's say we have descending array of ints, theno(n^2)
>>
>> Please suggest improvements
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Jun 12, 12:14 am, amit  wrote:
>> > given an array A of n elements.
>> > for indexes j , i such that j>i
>> > maximize( j - i )
>> > such that A[j] - A [ i ]> 0 .
>> >
>> > Any Algorithm less than O(n^2) would do.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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 output

2010-06-12 Thread Arun prasath
The only gurantee in this is that the outer printf result will come first.

Why ? because comma operator does not act as sequence point.

-Arun prasath N

On Sat, Jun 12, 2010 at 3:44 PM, divya jain wrote:

> thanks to all for explanantions :)
>
>
> On 12 June 2010 15:43, divya jain  wrote:
>
>> one of my frnd askd me this question...
>>
>>
>> On 11 June 2010 21:34, Raj N  wrote:
>>
>>> @kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for
>>> '\n' so its 6 and for the next one 1+1=2
>>>
>>>
>>> On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran 
>>> wrote:
>>>
 Output will be

 1,1
 bcoz printf returns number of characters or integers printed

 On Jun 11, 12:26 am, divya  wrote:
 > #include 
 > main()
 > {
 >  int a = 1;
 >  char b='c';
 >  int i,j;
 >
 >  printf("%d,%d",printf("%d\n",a),printf("%c\n",b));
 >
 > wat shd b the o/p of this..plzz explain y?

 --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from 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 algoge...@googlegroups.com.
>>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] level order traversal

2010-06-12 Thread Jitendra Kushwaha
@Terence : Consider your algo for the tree
 1
 /\
2 3
 /\  / \
   4 56  7
 /   /
8  9
According to your algo , first we print 8 4 2 1  ( while(! is_empty(vstack))
) . But 9 should come before 1.
i.e  8 4 2 9 1 5 6 3 7
am I correct???


-- 
Regards
Jitendra Kushwaha
MNNIT, Allahabad

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



Re: [algogeeks] Array Increment Problem

2010-06-12 Thread Jitendra Kushwaha
This is direct question of segment tree. read the topcoder's tutorial for
segment tree


-- 
Regards
Jitendra Kushwaha
MNNIT, Allahabad

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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 output

2010-06-12 Thread divya jain
thanks to all for explanantions :)

On 12 June 2010 15:43, divya jain  wrote:

> one of my frnd askd me this question...
>
>
> On 11 June 2010 21:34, Raj N  wrote:
>
>> @kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for
>> '\n' so its 6 and for the next one 1+1=2
>>
>>
>> On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran 
>> wrote:
>>
>>> Output will be
>>>
>>> 1,1
>>> bcoz printf returns number of characters or integers printed
>>>
>>> On Jun 11, 12:26 am, divya  wrote:
>>> > #include 
>>> > main()
>>> > {
>>> >  int a = 1;
>>> >  char b='c';
>>> >  int i,j;
>>> >
>>> >  printf("%d,%d",printf("%d\n",a),printf("%c\n",b));
>>> >
>>> > wat shd b the o/p of this..plzz explain y?
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from 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 algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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: identify the recurring part for a given decimal no

2010-06-12 Thread divya jain
@anurag

i dint get ur approach..which numerator n denominator u r talking about..plz
explain.. thanks in advance

On 11 June 2010 08:57, Anurag Sharma  wrote:

> Please note that the fractional repeating part is recurring. and so that
> 4th temporary variable assignment will be this way->
> temp=x*1 - x= 233456.34563456...  - 23.34563456 = 233433.0  ( mark
> the fractional part is 0 now since the infinitely repeating 3456... will get
> cancelled)
> In this  case you can say that 4 places are repeating. But yes its
> according to the maths and in any programming language whenever you divide
> the numerator and denominator you wont get this infinitely recurring decimal
> places.
>
> @divya, also your approach wont work if the recurring fractional digits
> start after few places from the decimal like in the case of
> 23.123345634563456  (note here after the decimal place 123 is not
> repeating while 3456.. after this 123 is repeating.)
>
> What I suggest in this case is keep dividing the numerator by denominator
> and at every step keep inserting the tupple (remainder, quotient) of that
> division step in a set. and before inserting in the set check whether it
> already exists. If yes then the all the quotients following from that point
> (including the point) will be recurring.
>
> Regards,
>
> Anurag Sharma
>
>
>
> On Thu, Jun 10, 2010 at 8:25 AM, Veer Sharma wrote:
>
>> Seems it wont work...
>> x=23.34563456
>>
>> temp = x*100 -x = 233.4563456 - 23.34563456 = 210.11071104
>> temp = x*100 -x = 2334.563456 - 23.34563456 = 2311.21782144
>> temp = x*1000 -x =  23345.63456 - 23.34563456 = 23322.28892544
>> temp = x*1 -x =  233456.3456 - 23.34563456 = 233432.6544
>> temp = x*10 -x = 2334563.456 - 23.34563456 = 2334540.11036544
>>
>> ...
>>
>> On Jun 9, 11:24 pm, Anurag Sharma  wrote:
>> > multiply the original number x=23.34563456
>> >
>> > Anurag Sharma
>> >
>> > On Wed, Jun 9, 2010 at 10:36 PM, Veer Sharma > >wrote:
>> >
>> >
>> >
>> > > One question:
>> >
>> > > No x = 23.34563456
>> > > temp = x X 10 = 233.4563456
>> > > temp = temp - x = 210.11071104
>> > > decimal part zero? No.
>> > > Now multiply the no. with 100. Which no? original x (= 23.34563456) or
>> > > new no. temp (=210.11071104)?
>> >
>> > > On Jun 9, 8:12 pm, divya jain  wrote:
>> > > > multiply the no. with 10 nd store in temp. now subtract no from
>> temp.
>> > > check
>> > > > if the decimal part is zero if yes.  then 1st digit after decimal is
>> > > > recurring. if no. multiply the no with 100 and repeat . if this time
>> > > decimal
>> > > > part is zero then 2 digits after decimal r recurring nd so on..
>> >
>> > > > On 8 June 2010 21:45, Veer Sharma 
>> wrote:
>> >
>> > > > > You have a Numerator and Denominator. After division you might get
>> a
>> > > > > recurring decimal points float as the answer.
>> >
>> > > > > Problem is: You need to identify the recurring part for a given
>> > > > > decimal no?
>> > > > > For example 23.34563456 ...
>> > > > > return 3456
>> >
>> > > > > --
>> > > > > You received this message because you are subscribed to the Google
>> > > Groups
>> > > > > "Algorithm Geeks" group.
>> > > > > To post to this group, send email to algoge...@googlegroups.com.
>> > > > > To unsubscribe from this group, send email to
>> > > > > algogeeks+unsubscr...@googlegroups.com
>> 
>> > > 
>> > > > > .
>> > > > > For more options, visit this group at
>> > > > >http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text -
>> >
>> > > > - Show quoted text -
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "Algorithm Geeks" group.
>> > > To post to this group, send email to algoge...@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > algogeeks+unsubscr...@googlegroups.com
>> 
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
>> >
>> > - Show quoted text -
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more o

Re: [algogeeks] Re: c output

2010-06-12 Thread divya jain
one of my frnd askd me this question...

On 11 June 2010 21:34, Raj N  wrote:

> @kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for
> '\n' so its 6 and for the next one 1+1=2
>
>
> On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran wrote:
>
>> Output will be
>>
>> 1,1
>> bcoz printf returns number of characters or integers printed
>>
>> On Jun 11, 12:26 am, divya  wrote:
>> > #include 
>> > main()
>> > {
>> >  int a = 1;
>> >  char b='c';
>> >  int i,j;
>> >
>> >  printf("%d,%d",printf("%d\n",a),printf("%c\n",b));
>> >
>> > wat shd b the o/p of this..plzz explain y?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: sum to x

2010-06-12 Thread Chakravarthi Muppalla
@Expert,
u r right, it will take nlogn time.
But I didn't get this part of the code:
else {
  if ( && map[num] == false){
 map[ S - num ] = true ;
  } else {

}

can u please provide us a little explanation?


On Sat, Jun 12, 2010 at 2:34 PM, Modeling Expert <
cs.modelingexp...@gmail.com> wrote:

> As problem says N is very large, I think sorting is not the right
> thing as that would be minimum (n log n) time
> how about this
> Let's say sum is S
> we take an map map and start reading integerts num
> if ( num > S ) discard
> else {
>   if ( && map[num] == false){
>  map[ S - num ] = true ;
>   } else {
>
> }
>
>
> On Jun 12, 11:40 am, Chakravarthi Muppalla 
> wrote:
> > I would use an array.
> >
> > a[] = 1 3 7 8 9 78 67 23
> > a[] = 1 3 7 8 9 23 67 78 //sort the array
> > reqSum = 30;
> > for i :a.length-1; i>=0; i--
> >  t = reqSum - a[i];
> >  if(t is negative) continue;
> >   find(t);//in the rest of the array;(binary search)
> >   if(t found in the array) return index of t, current value of i;
> >  I guess it works.(we may have to use a hash map to speed it up in the
> long
> > run).
> >
> > On Sat, Jun 12, 2010 at 10:29 AM, Rohit Saraf
> > wrote:
> >
> >
> >
> > > I guess it can be done in efficiently using a simple divide and conquer
> > > scheme almost imitating mergesort.
> > > Can you think of it now? :D
> >
> > > --
> > > Rohit Saraf
> > > Second Year Undergraduate,
> > > Dept. of Computer Science and Engineering
> > > IIT Bombay
> > >http://www.cse.iitb.ac.in/~rohitfeb14
> >
> > > On Fri, Jun 11, 2010 at 10:07 PM, sharad kumar <
> sharad20073...@gmail.com>wrote:
> >
> > >> all possible pairs
> >
> > >> --
> > >> You received this message because you are subscribed to the Google
> Groups
> > >> "Algorithm Geeks" group.
> > >> To post to this group, send email to algoge...@googlegroups.com.
> > >> To unsubscribe from 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 algoge...@googlegroups.com.
> > > To unsubscribe from 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,
> > Chakravarthi.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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,
Chakravarthi.

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



[algogeeks] Re: sum to x

2010-06-12 Thread Modeling Expert
My previous post went unfinished :((
anyway this is summary of algo . (as N is very large , sorting could
be costly so this method doesn't do that )

algo ::
have a map

1. For given number , if its less than Sum S , make map[S-number] =
true  only if map[number] does not exist
2. for Next  number , if map[number] is true , we got a pair
( number , map[number]) else do 1

For exampe S = 100 , if we get 20 , let's make map[80] = true ;
next if we get 80 , we will first check map[80] and if its true , we
get a pair.

If there are repetations , we can take map of  where second
argument is count of first element ,
say of 20 comes 4 times we will store map[20] = 4




On Jun 12, 11:40 am, Chakravarthi Muppalla 
wrote:
> I would use an array.
>
> a[] = 1 3 7 8 9 78 67 23
> a[] = 1 3 7 8 9 23 67 78 //sort the array
> reqSum = 30;
> for i :a.length-1; i>=0; i--
>      t = reqSum - a[i];
>      if(t is negative) continue;
>       find(t);//in the rest of the array;(binary search)
>       if(t found in the array) return index of t, current value of i;
>  I guess it works.(we may have to use a hash map to speed it up in the long
> run).
>
> On Sat, Jun 12, 2010 at 10:29 AM, Rohit Saraf
> wrote:
>
>
>
> > I guess it can be done in efficiently using a simple divide and conquer
> > scheme almost imitating mergesort.
> > Can you think of it now? :D
>
> > --
> > Rohit Saraf
> > Second Year Undergraduate,
> > Dept. of Computer Science and Engineering
> > IIT Bombay
> >http://www.cse.iitb.ac.in/~rohitfeb14
>
> > On Fri, Jun 11, 2010 at 10:07 PM, sharad kumar 
> > wrote:
>
> >> all possible pairs
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algoge...@googlegroups.com.
> >> To unsubscribe from 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 algoge...@googlegroups.com.
> > To unsubscribe from 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,
> Chakravarthi.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread divya jain
i think we need to maintain an array of index as well such that while
subtracting smallest element from largest element of sorted array we need to
check if index of largest is greater than index of smallest. if no..then
this is not the solution..

On 12 June 2010 14:20, Modeling Expert  wrote:

> Let's say array A , 1 till n
>
> s_index = 1;  e_index = n ;
> start  = &A[s_index] ;
> end = &A[e_index];
> result = 0;  //!  j - i
> if ( *end > *start ){
>result =  index(end) - index(start)  ( only of its greater than
> previous value of result )
>break ;
> }else{
> end-- ;  //! till you reach start
> }
>
> now increment start , and repeat the process but only from A[n] till
> A[++result] , going further
> down is not required now.
>
> Average time < o(n^2)
>
> Worst case : let's say we have descending array of ints, theno(n^2)
>
> Please suggest improvements
>
>
>
>
>
>
>
>
>
>
> On Jun 12, 12:14 am, amit  wrote:
> > given an array A of n elements.
> > for indexes j , i such that j>i
> > maximize( j - i )
> > such that A[j] - A [ i ]> 0 .
> >
> > Any Algorithm less than O(n^2) would do.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread Modeling Expert
Let's say array A , 1 till n

s_index = 1;  e_index = n ;
start  = &A[s_index] ;
end = &A[e_index];
result = 0;  //!  j - i
if ( *end > *start ){
result =  index(end) - index(start)  ( only of its greater than
previous value of result )
break ;
}else{
 end-- ;  //! till you reach start
}

now increment start , and repeat the process but only from A[n] till
A[++result] , going further
down is not required now.

Average time < o(n^2)

Worst case : let's say we have descending array of ints, theno(n^2)

Please suggest improvements










On Jun 12, 12:14 am, amit  wrote:
> given an array A of n elements.
> for indexes j , i such that j>i
> maximize( j - i )
> such that A[j] - A [ i ]> 0 .
>
> Any Algorithm less than O(n^2) would do.

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



[algogeeks] Re: sum to x

2010-06-12 Thread Modeling Expert
As problem says N is very large, I think sorting is not the right
thing as that would be minimum (n log n) time
how about this
Let's say sum is S
we take an map map and start reading integerts num
if ( num > S ) discard
else {
   if ( && map[num] == false){
  map[ S - num ] = true ;
   } else {

}


On Jun 12, 11:40 am, Chakravarthi Muppalla 
wrote:
> I would use an array.
>
> a[] = 1 3 7 8 9 78 67 23
> a[] = 1 3 7 8 9 23 67 78 //sort the array
> reqSum = 30;
> for i :a.length-1; i>=0; i--
>      t = reqSum - a[i];
>      if(t is negative) continue;
>       find(t);//in the rest of the array;(binary search)
>       if(t found in the array) return index of t, current value of i;
>  I guess it works.(we may have to use a hash map to speed it up in the long
> run).
>
> On Sat, Jun 12, 2010 at 10:29 AM, Rohit Saraf
> wrote:
>
>
>
> > I guess it can be done in efficiently using a simple divide and conquer
> > scheme almost imitating mergesort.
> > Can you think of it now? :D
>
> > --
> > Rohit Saraf
> > Second Year Undergraduate,
> > Dept. of Computer Science and Engineering
> > IIT Bombay
> >http://www.cse.iitb.ac.in/~rohitfeb14
>
> > On Fri, Jun 11, 2010 at 10:07 PM, sharad kumar 
> > wrote:
>
> >> all possible pairs
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algoge...@googlegroups.com.
> >> To unsubscribe from 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 algoge...@googlegroups.com.
> > To unsubscribe from 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,
> Chakravarthi.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: sleep

2010-06-12 Thread souravsain
@sharad
process A has gone to sleep asking kernel to wake it only if resource
which it needs is available. So this process is sleeping.

I think it is not possible for a process to interrupt another process.
Lets understand it by these examples.

Two processes can communicate, bit not interrupt. Communication is
different from interrupts. If process A says "Are u there?" to process
B, process B may say "Yes" or process B may not reply. It is process
A's responcibility to handle all cases like got reply from B, did not
get reply from B, wait indefinetly or return saying error.

For interrupts lets understand it this way. Process A says I want to
write this value to a file. Kernel may decide to write this to the
actual file in the disk. This means disk device driver (this will be
some routine in kernal code) will called by kernal to write the value
to the file. For this time, process A may be put to sleep by kernel
(but not necessarily. If process A is the only process running and it
has more thread then some other thread of A may execute now). If put
to sleep, Kernel will run another process B which may be, say a music
audio for example. When the disk device driver routine will have
completed the writing to file, it will give its retrun valur (remember
its a routine / function for kernal) to kernal. The kernal will then
"interrupt" the sleeping process A as "your job is done". But this it
can not do at any time. It has to find a proper instance during the
running of process B which the kernel can do so. Because to do so, the
kernal has do do a context switch.

There are more issues to this. For example if kernel is executing some
system call, called by B, it may not immediately do the context
switch. In system calls the kernal may be manipulating some of its
internal data structures like in call to malloc etc. So it will do the
context switch only acter this data structure manipulation is over.

On Jun 11, 3:28 pm, sharad kumar  wrote:
> @souravsain
> means that process has slept and asked kernel to wake it only if its
> resource which it need,it got so at that time can any process interrupt it
> or not

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] Mirroring Binary Tree Pattern Problem

2010-06-12 Thread harit agarwal
just send the inorder and preorder traversal of binary tree to other process
and recontruct it.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] stack

2010-06-12 Thread Raj N
@jalaj: These were few solutions discussed b4

1. For 3 stacks a efficient algo is not easy to think in a single array ,
yet we can optimise according the usage. For example lets say out of 3 stack
we know the growth of 2nd stack more closely and we know its variations
boundary of 2nd stack more clearly than others two. In such case make stack
2 static giving it its particular location. For the rest two apply same as
implementation of two stack

|   stack2  |>1st 3rd<---|
__



for n stacks make n/2 such intervals.
If n is odd, one interval will be for a single stack.

2. for three stacks u can use indices 0 3 6 etc for stack1. 1 4 7 for stack
2 and 2 5 8 etc for stack 3.
now if any of the stack overflows but there is still space in array as other
stacks have few element then now u can grow ur stack in reverse direction as
shown below :

indices of array :   0  1  2  3  4  5  6  7  8  9  10  11 12

contents  1   2  3  1 1  1  1
/  \
  \
  top2top3
 top1
here 1 represents element of stack1 2 for stack 2 and so on.
now if  u want to insert more element in stack 1 it will overflow while 2
and 3 have space so wat u can do now is grow stack 1 in reverse direction.
ie now place elements for stack 1 in index 11 and so now top1 will point to
11 and so on. u can indicate this behaviour of stack1 by using some tag.





On Fri, Jun 11, 2010 at 10:19 PM, jalaj jaiswal
wrote:

> @raj n
> for 2 stacks its fine can you please tell for 3 stacks ...i'll generalize
> it
>
>
> On Fri, Jun 11, 2010 at 9:32 PM, Anurag Sharma wrote:
>
>> Is it without having the need to shift elements at all?
>>
>> Anurag Sharma
>>
>>
>> On Fri, Jun 11, 2010 at 3:41 PM, jalaj jaiswal > > wrote:
>>
>>> Give an algorithm to implement n stacks in an array... take care of the
>>> empty space too i.e no overflow shld occur if there is eny empty space left
>>> .
>>>
>>>
>>>
>>>
>>> --
>>> With Regards,
>>> Jalaj Jaiswal
>>> +919026283397
>>> B.TECH IT
>>> IIIT ALLAHABAD
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from 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 algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> With Regards,
> Jalaj Jaiswal
> +919026283397
> B.TECH IT
> IIIT ALLAHABAD
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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: Common elements in 2 circular linked lists

2010-06-12 Thread Raj N
@Balarukesh: Yeah even I was thinking about it..

On Sat, Jun 12, 2010 at 12:18 AM, BALARUKESH wrote:

> I hope u can do better... try this..
> use a hash table and try inserting all elements of 1st list and then
> insert the elements of second list. if u find an element already
> existing when u insert from second list then add it to a new list. the
> new list has the common elements...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from 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 algoge...@googlegroups.com.
To unsubscribe from 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] level order traversal

2010-06-12 Thread Terence

vertical_traversal(v)
{
  stack_init(vstack);
  stack_init(tstack);

  while(v)
  stack_push(vstack, v);
  if(v.right)
  stack_push(tstack, v.right);
  v = v.left;

  while(! is_empty(vstack))
  visit(stack_pop(vstack));
  while(! is_empty(tstack))
  vertical_traversal(stack_pop(tstack));
}


On 2010-6-9 16:56, sharad wrote:

can any one tell me how to code for vertical level traversal of a
binary tree?


   1
 /\
2  3
  /   \/  \
 45  67


print

4   2156   37

   


--
You received this message because you are subscribed to the Google Groups "Algorithm 
Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] OS doubt

2010-06-12 Thread amit
OS doubt:

I have read many times that say a 24 KB process enters the Main Memory
selected by the Long Term Scheduler.
But I don't understand what it exactly means.
As far as I know Process consists of ( Code + Data(Static) +
Stack(Local Data) + Heap)

So doubt1: Is this 24 KB the size of this whole process or just the
size of the code segment.

doubt2: Now lets say this process starts getting executed by the
CPU ,Suppose the main() contains
main(){
int x;
int y;
x=10;
...
}
So x,y will be allocated the memory in the Stack.
But when x=10 is encountered , how will the CPU know the 
address of
x. In short how is x accessed??


doubt 3: If x and y are just address of a memory location in the
stack , can their logical address be determined by the compiler or it
will be generated by the CPU??

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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] sum to x

2010-06-12 Thread Chakravarthi Muppalla
I would use an array.

a[] = 1 3 7 8 9 78 67 23
a[] = 1 3 7 8 9 23 67 78 //sort the array
reqSum = 30;
for i :a.length-1; i>=0; i--
 t = reqSum - a[i];
 if(t is negative) continue;
  find(t);//in the rest of the array;(binary search)
  if(t found in the array) return index of t, current value of i;
 I guess it works.(we may have to use a hash map to speed it up in the long
run).




On Sat, Jun 12, 2010 at 10:29 AM, Rohit Saraf
wrote:

> I guess it can be done in efficiently using a simple divide and conquer
> scheme almost imitating mergesort.
> Can you think of it now? :D
>
> --
> Rohit Saraf
> Second Year Undergraduate,
> Dept. of Computer Science and Engineering
> IIT Bombay
> http://www.cse.iitb.ac.in/~rohitfeb14
>
>
>
> On Fri, Jun 11, 2010 at 10:07 PM, sharad kumar 
> wrote:
>
>> all possible pairs
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from 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 algoge...@googlegroups.com.
> To unsubscribe from 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,
Chakravarthi.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from 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: Array Problem

2010-06-12 Thread souravsain
Problme is not clear.
Quesrtions:
1. Is the array all of positive numbers
if yes then sort the array in ascending order. Now for every j, j>i
and i,j <=n, A[j]>A[i] and so A[j]-A[i] > 0. Now if we want max(j-i)
such that A[j]-A[i]>0, it has to be j=n, the last element of A and
i=1, the first element of A
Time Complexity = O(nlogn) for sorting.

2. Is array consisting of +ve and -ve numbers?
Again sort in ascending order(nlogn). We know A[j] is max of all
elements. If A[j] <= 0, then no solution exists. Else if A[j] +ve then
again j=n, the last element of A and i=0 the first element is answer.

Sourav Sain


On Jun 12, 12:14 am, amit  wrote:
> given an array A of n elements.
> for indexes j , i such that j>i
> maximize( j - i )
> such that A[j] - A [ i ]> 0 .
>
> Any Algorithm less than O(n^2) would do.

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