Re: [algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread ankit sambyal
Following is the working code :Time complexity : O(n^2)  Space
complexity : O(1)


void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
/*num is the number which is searched in the array arr[]. index is the index
in the array arr[] by which the searched number is to be replaced*/
int searchAndReplace(int arr[],int size,int num,int index)
{
int i=index+1;
while(ihttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] direct i

2011-07-26 Thread salvador_cerinza
Let say stack S.
1.insert elements in S of A[] from right to left.
2.int val = S.top();
3.S.pop();
4.now check val with S.top() until u find any element smaller than val.
5.Note down the element pop it from stack
6.if step 4 is true , the push val in stack S and all elements which were
popped in the order they were popped except the last matched candidate
element.

Yeah..dis algo is not very efficient..

On Wed, Jul 27, 2011 at 12:20 PM, Pankaj  wrote:

> Can you please elaborate a little about your stack based solution. I was
> thinking of using queue but was unable to make a perfect algo.
>
>
> On Wed, Jul 27, 2011 at 12:18 PM, salvador_cerinza <
> vishwakarma.ii...@gmail.com> wrote:
>
>> i m  suggesting stack  not just for best case only .
>>
>>
>> On Wed, Jul 27, 2011 at 12:16 PM, Pankaj wrote:
>>
>>> Even in array best case can be O(n). Why use stack?
>>> On Wed, Jul 27, 2011 at 12:14 PM, salvador_cerinza <
>>> vishwakarma.ii...@gmail.com> wrote:
>>>
 Best case : O(n)
 Worst case : O(n^2)
 can be done using stack.

 Thinking of better solution. .


 On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal >>> > wrote:

> O(n^2) algo is trivial. Can anybody think of a better approach ???
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

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

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



Re: [algogeeks] direct i

2011-07-26 Thread Pankaj
Can you please elaborate a little about your stack based solution. I was
thinking of using queue but was unable to make a perfect algo.

On Wed, Jul 27, 2011 at 12:18 PM, salvador_cerinza <
vishwakarma.ii...@gmail.com> wrote:

> i m  suggesting stack  not just for best case only .
>
>
> On Wed, Jul 27, 2011 at 12:16 PM, Pankaj wrote:
>
>> Even in array best case can be O(n). Why use stack?
>> On Wed, Jul 27, 2011 at 12:14 PM, salvador_cerinza <
>> vishwakarma.ii...@gmail.com> wrote:
>>
>>> Best case : O(n)
>>> Worst case : O(n^2)
>>> can be done using stack.
>>>
>>> Thinking of better solution. .
>>>
>>>
>>> On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal 
>>> wrote:
>>>
 O(n^2) algo is trivial. Can anybody think of a better approach ???

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

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

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



Re: [algogeeks] direct i

2011-07-26 Thread salvador_cerinza
i m  suggesting stack  not just for best case only .

On Wed, Jul 27, 2011 at 12:16 PM, Pankaj  wrote:

> Even in array best case can be O(n). Why use stack?
> On Wed, Jul 27, 2011 at 12:14 PM, salvador_cerinza <
> vishwakarma.ii...@gmail.com> wrote:
>
>> Best case : O(n)
>> Worst case : O(n^2)
>> can be done using stack.
>>
>> Thinking of better solution. .
>>
>>
>> On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal 
>> wrote:
>>
>>> O(n^2) algo is trivial. Can anybody think of a better approach ???
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] direct i

2011-07-26 Thread Pankaj
Even in array best case can be O(n). Why use stack?
On Wed, Jul 27, 2011 at 12:14 PM, salvador_cerinza <
vishwakarma.ii...@gmail.com> wrote:

> Best case : O(n)
> Worst case : O(n^2)
> can be done using stack.
>
> Thinking of better solution. .
>
>
> On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal wrote:
>
>> O(n^2) algo is trivial. Can anybody think of a better approach ???
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] direct i

2011-07-26 Thread salvador_cerinza
Best case : O(n)
Worst case : O(n^2)
can be done using stack.

Thinking of better solution. .

On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal wrote:

> O(n^2) algo is trivial. Can anybody think of a better approach ???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: MS interview:

2011-07-26 Thread geek forgeek
anyone??

On Tue, Jul 26, 2011 at 11:36 PM, geek forgeek wrote:

> Function to display the directory structure in a user friendly way taking
> root dir as arg
> for a general OS. You may assume and state some basic APIs available in
> that OS
>

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

2011-07-26 Thread sunny agrawal
As we start every time from the beginning, so 1 will never be deleted
hence in last it will remain there

I faced the same Question in MS Written where question was..Given a
number find if the number is Lucky or not?

that can be easily found because every time we remove the numbers at
even indexes(assuming indexes start at 1) now if at any time if index
goes even number is not lucky and if it is odd after the operation new
index will be (i+1)/2
Overall Complexity O(lgn)

On Wed, Jul 27, 2011 at 9:46 AM, bharath  wrote:
> This is the extended Josephus problem. More details and solution
> formulation here:
> http://www.cs.man.ac.uk/~shamsbaa/Josephus.pdf
>
>
> On Jul 26, 11:04 pm, Nikhil Gupta  wrote:
>> Please suggest a good algo for this :
>>
>> You have numbers 1 to n (consider them arranged in a circular order)
>> Then starting from the first number, all alternate numbers are deleted. Once
>> the entire range is traversed with this procedure, the same is performed
>> from the beginning again (as they are circularly arranged).
>> This action is done until only one number is left. So given a range of
>> numbers, you have to use an algo to tell which number will be left in the
>> end.
>>
>> Example :
>>
>> 1 2 3 4 5 6 7 8 9 10 11 12 ...
>> 1 3 5 7 9 11 13 15 17 19 .
>> 1 5 9 13 17 21 25 .
>>
>> and so on.
>>
>> --
>> Nikhil Gupta
>> Senior Co-ordinator, Publicity
>> CSI, NSIT Students' Branch
>> NSIT, New Delhi, India
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to 
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.
>
>



-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

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

2011-07-26 Thread geek forgeek
Function to display the directory structure in a user friendly way taking
root dir as arg
for a general OS. You may assume and state some basic APIs available in that
OS

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

2011-07-26 Thread sunny agrawal
@shiva viknesh
this is a different Question...

@saurabh
how is nlgn possible, total no of possible substrings are n^2


this is the O(n^2) solutionOn Wed, Jul 27, 2011 at 8:09 AM, saurabh singh

for(int l = 0; l < len; l++){
                for(int i = 0; i < len-l; i++){
                        int j = i+l;
                        char temp = s[j+1];
                        s[j+1] = 0;
                        printf("%s\n", s+i);
                        s[j+1] = temp;
                }
        }

 wrote:
>
> using suffix tree this can be done in o(nlogn) though will take extra space.
>
> On Wed, Jul 27, 2011 at 12:47 AM, siva viknesh  wrote:
>>
>> http://geeksforgeeks.org/?p=767
>>
>> On Jul 26, 11:49 pm, Pratz mary  wrote:
>> > how?
>> >
>> > On 26 July 2011 23:18, ankit sambyal  wrote:
>> >
>> > > @vivin : Suffix trees are memory intensive..
>> >
>> > > This problem can be solved just by running 2 nested loops in O(1)
>> > > space and O(n^2) time
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google Groups
>> > > "Algorithm Geeks" group.
>> > > To post to this group, send email to algogeeks@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > algogeeks+unsubscr...@googlegroups.com.
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > --
>> > regards Pratima :)
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> 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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to 
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.



--
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

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

2011-07-26 Thread Rajeev Kumar
Hey ankit, i gave java code also...didn't u check it in the link...anyway i
am explaining here.

*Note : Position count starts from 0. *
*ex: {1,2,3,4} ...position of '1' is zero*
*
*
*In the below approach,we are checking element position in the modified
list(after deletion operation in the previous iteration).*

given array is : ar[]= {1,3,2,4,5,4,2}.
construct a list with array elements and sort it.Now list contains
:1,2,2,3,4,4,5

Now traverse through array elements from i=0 to n-1(start to end)
store result in result[] array.

list is *1*-2-2-3-4-4-5
for i=0, a[0]=1,search for a[0] position in the list(right
occurrence).a[0]=1 position in list is '0'
add '0' to result.===>result[0]=0;
remove the element a[0] from the list.now list contains 2-2-*3*-4-4-5

for i=1,a[1]=3,search for a[1] position in the list(right occurence).a[1]=3
position in list is '2'
  add '2' to result>result[1]=2
remove the element a[1] from the list.now list contains 2-*2*-4-4-5


for i=2,a[2]=2,search for a[2] position in the list(right occurence).a[2]=2
position in list is '1'
  add '1' to result>result[2]=1
remove the element a[2] from the list.now list contains 2-4-*4*-5


for i=3,a[3]=4,search for a[3] position in the list(right occurence).a[3]=4
position in list is '2'
  add '2' to result>result[3]=2
remove the element a[3] from the list.now list contains 2-4-5


for i=4,a[4]=5,search for a[4] position in the list(right occurence).a[4]=5
position in list is '2'
  add '2' to result>result[4]=2
remove the element a[4] from the list.now list contains 2-*4*


for i=5,a[5]=4,search for a[5] position in the list(right occurence).a[5]=4
position in list is '1'
  add '1' to result>result[5]=1
remove the element a[5] from the list.now list contains 2


for i=6,a[6]=2,search for a[6] position in the list(right occurence).a[6]=2
position in list is '0'
  add '0' to result>result[6]=0
remove the element a[6] from the list.now list is empty.


resultant array contains :
from all conditions :
add '0' to result.===>result[0]=0;
add '2' to result>result[1]=2
add '1' to result>result[2]=1
add '1' to result>result[3]=2
add '2' to result>result[4]=2
add '1' to result>result[5]=1
add '0' to result>result[6]=0

expected result   {0,2,1,2,2,1,0}
actual result ==>{0,2,1,2,2,1,0}


I hope u r clear now.Please let me know if you still have
doubts...

U can execute the java code given in link :
http://rajeevprasanna.blogspot.com/2011/07/count-number-of-min-elements-on-right.html

I will be more happy if you give me failed cases...



On Wed, Jul 27, 2011 at 11:25 AM, ankit sambyal wrote:

> @rajeev :try the example given in the question. And explain ur algo with
> that example
>



-- 
Thank You
Rajeev Kumar

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

2011-07-26 Thread Anand Saha
I don't think so. Try it on {2, 5, 1, 7} and {5, 7, 1, 2}

-- 


On Wed, Jul 27, 2011 at 10:33 AM, Sonal Maheshwari wrote:

> i think the following shud work:
>
> i=j=0;
> while(i< n && j {
>   if ( a[i] < b[j] )
>   {
>   pos= find(b, a[i]); ///find the position of a[i] in
> array b
>   swap ( b[j], b[pos] ); //swapping the two numbers
>   }
>   else if ( a[i] > b[j] )
>   {
>   pos= find(a, b[j]); ///find the position of b[j] in
> array a
>   swap ( a[i], a[pos] ); //swapping the two numbers
>   }
>   i++;
>   j++;
> }
>
> Correct me if m wrong...
>
> On Jul 27, 8:46 am, siva viknesh  wrote:
> > Given two arrays
> > a[] = {1,3,2,4}
> > b[] = {4,2,3,1}
> > both will have the same numbers but in different combination.
> > We have to sort them . The condition is that you cannot compare only
> > elements within the same array.You can compare element of one array
> > with
> > another only.
> >
> > On Jul 27, 8:45 am, sivaviknesh s  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > -- Forwarded message --
> > > From: Padmaja Sridharan 
> > > Date: Wed, Jul 27, 2011 at 5:15 AM
> > > Subject: SORTING ARRAYS
> > > To: mitcse08i...@googlegroups.com
> >
> > > Given two arrays
> > > a[] = {1,3,2,4}
> > > b[] = {4,2,3,1}
> > > both will have the same numbers but in different combination.
> > > We have to sort them . The condition is that you cannot compare only
> > > elements within the same array.You can compare element of one array
> with
> > > another only.
> >
> > > ~With Regards
> > > Padmaja
> >
> > > --
> > > Regards,
> > > $iva
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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

2011-07-26 Thread ankit sambyal
O(n^2) algo is trivial. Can anybody think of a better approach ???

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

2011-07-26 Thread Sonal Maheshwari
i think the following shud work:

i=j=0;
while(i< n && j b[j] )
   {
   pos= find(a, b[j]); ///find the position of b[j] in
array a
   swap ( a[i], a[pos] ); //swapping the two numbers
   }
   i++;
   j++;
}

Correct me if m wrong...

On Jul 27, 8:46 am, siva viknesh  wrote:
> Given two arrays
> a[] = {1,3,2,4}
> b[] = {4,2,3,1}
> both will have the same numbers but in different combination.
> We have to sort them . The condition is that you cannot compare only
> elements within the same array.You can compare element of one array
> with
> another only.
>
> On Jul 27, 8:45 am, sivaviknesh s  wrote:
>
>
>
>
>
>
>
> > -- Forwarded message --
> > From: Padmaja Sridharan 
> > Date: Wed, Jul 27, 2011 at 5:15 AM
> > Subject: SORTING ARRAYS
> > To: mitcse08i...@googlegroups.com
>
> > Given two arrays
> > a[] = {1,3,2,4}
> > b[] = {4,2,3,1}
> > both will have the same numbers but in different combination.
> > We have to sort them . The condition is that you cannot compare only
> > elements within the same array.You can compare element of one array with
> > another only.
>
> > ~With Regards
> > Padmaja
>
> > --
> > Regards,
> > $iva

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



Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread Rajeev Kumar
@ankit : can u give me a case where it fails...

On Wed, Jul 27, 2011 at 8:33 AM, ankit sambyal wrote:

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



-- 
Thank You
Rajeev Kumar

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

2011-07-26 Thread subramania jeeva
This problem is termed as nut and bolts problem..:) We've to use a
modification of quick sort..:)







Cheers
  ~ Jeeva ~


On Wed, Jul 27, 2011 at 9:16 AM, siva viknesh wrote:

> Given two arrays
> a[] = {1,3,2,4}
> b[] = {4,2,3,1}
> both will have the same numbers but in different combination.
> We have to sort them . The condition is that you cannot compare only
> elements within the same array.You can compare element of one array
> with
> another only.
>
> On Jul 27, 8:45 am, sivaviknesh s  wrote:
> > -- Forwarded message --
> > From: Padmaja Sridharan 
> > Date: Wed, Jul 27, 2011 at 5:15 AM
> > Subject: SORTING ARRAYS
> > To: mitcse08i...@googlegroups.com
> >
> > Given two arrays
> > a[] = {1,3,2,4}
> > b[] = {4,2,3,1}
> > both will have the same numbers but in different combination.
> > We have to sort them . The condition is that you cannot compare only
> > elements within the same array.You can compare element of one array with
> > another only.
> >
> > ~With Regards
> > Padmaja
> >
> > --
> > Regards,
> > $iva
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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

2011-07-26 Thread siva viknesh
Given an array of integers, for each index i, you have to swap the
value at i with the first value smaller than A[ i ] that comes after
index i


for example array A = {3,7,4,9,10,2,1}

The Output array should be : 2 4 3 7 9 1 10

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



Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread Rajeev Kumar
@ankit : can u give me a case where it fails...

On Wed, Jul 27, 2011 at 8:33 AM, ankit sambyal wrote:

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



-- 
Thank You
Rajeev Kumar

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

2011-07-26 Thread Puneet Gautam
Let k=no. of rows

If k=odd
mirror the matrix about the ((k/2)+1) th row..

else start from k/2 and (k/2 +1 )th row, swap the two rows.. then
k/2-1 and k/2 +2 and swap and soon...

OR

maintain array as a pointer table.. keep on changing the base address
to which a[i points to..

Let *a[]={{1,1,0},{2,3,4},{4,57,8},{1,2,5}};

Take pointer a[0] and swap it with the a[3] address.. lly for a[2]and a[1]...
This should run in O(n) time ,n=no of rows of matrix
I think i made it clear...

This might not be the best solution... i wud love to see better
solutions from anyone..!

Thanks..

On 7/27/11, Deoki Nandan  wrote:
> rotate a 2D matrix by angle 180
>
>
> --
> **With Regards
> Deoki Nandan Vishwakarma
>
> *
> *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] Re: Redundant parentheses

2011-07-26 Thread bharath
I think I figured out a solution. Please correct me if I missed anything. 

*Example:*
Input: ((A+B)*C)
Expected output: (A+B)*C

*Assumptions:*
- Peek (queue) just tells the element in front end of queue without deleting 
it.
- precedence( ) is a function which looks a precedence table of operators

*Pseudo code below:*
1) Convert infix expression to postfix

AB+C*

2) Insert only operators in queue 'Q'

(front)+  *(rear)

3) Parse postfix expression
4) If operand, push to stack 'S'
5) If operator

5.1) y=Delete(Q)

5.2) If precedence(y) > precedence(peek(Q)), then Push (S, "Pop(S) y 
Pop(S)") 

5.3) If precedence(y) < precedence(peek(Q)), then Push (S, "( Pop(S) y 
Pop(S) )")

6) Final result on top of 'S'



 

 
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/RGom9z_GybEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Lucky numbers

2011-07-26 Thread bharath
This is the extended Josephus problem. More details and solution
formulation here:
http://www.cs.man.ac.uk/~shamsbaa/Josephus.pdf


On Jul 26, 11:04 pm, Nikhil Gupta  wrote:
> Please suggest a good algo for this :
>
> You have numbers 1 to n (consider them arranged in a circular order)
> Then starting from the first number, all alternate numbers are deleted. Once
> the entire range is traversed with this procedure, the same is performed
> from the beginning again (as they are circularly arranged).
> This action is done until only one number is left. So given a range of
> numbers, you have to use an algo to tell which number will be left in the
> end.
>
> Example :
>
> 1 2 3 4 5 6 7 8 9 10 11 12 ...
> 1 3 5 7 9 11 13 15 17 19 .
> 1 5 9 13 17 21 25 .
>
> and so on.
>
> --
> Nikhil Gupta
> Senior Co-ordinator, Publicity
> CSI, NSIT Students' Branch
> NSIT, New Delhi, India

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



[algogeeks] rotate a matrix NVIDIA question

2011-07-26 Thread Deoki Nandan
rotate a 2D matrix by angle 180


-- 
**With Regards
Deoki Nandan Vishwakarma

*
*

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

2011-07-26 Thread Nikhil Gupta
Please suggest a good algo for this :

You have numbers 1 to n (consider them arranged in a circular order)
Then starting from the first number, all alternate numbers are deleted. Once
the entire range is traversed with this procedure, the same is performed
from the beginning again (as they are circularly arranged).
This action is done until only one number is left. So given a range of
numbers, you have to use an algo to tell which number will be left in the
end.

Example :

1 2 3 4 5 6 7 8 9 10 11 12 ...
1 3 5 7 9 11 13 15 17 19 .
1 5 9 13 17 21 25 .

and so on.

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

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



Re: [algogeeks] AMAZON Q

2011-07-26 Thread Anand Saha
Construct a BST using ar[], where each node contains the ar index
information as well (in addition to the value).
Now iterating through ar. For each element, traverse the BST by value,
counting only those nodes where the value AND index# are greater then self.
Once done traversal, update ar_low.

-- 



On Tue, Jul 26, 2011 at 7:18 PM, Piyush Sinha wrote:

> You have an array like ar[]= {1,3,2,4,5,4,2}. You need to create
> another array ar_low[] such that ar_low[i] = number of elements lower
> than or equal to ar[i] in ar[i+1:n-1].
> So the output of above should be {0,2,1,2,2,1,0}
>
> Time complexity : O(nlogn)
> use of extra space allowed.
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-7483122727*
> *  "NEVER SAY
> NEVER"
> *
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread siva viknesh
Given two arrays
a[] = {1,3,2,4}
b[] = {4,2,3,1}
both will have the same numbers but in different combination.
We have to sort them . The condition is that you cannot compare only
elements within the same array.You can compare element of one array
with
another only.

On Jul 27, 8:45 am, sivaviknesh s  wrote:
> -- Forwarded message --
> From: Padmaja Sridharan 
> Date: Wed, Jul 27, 2011 at 5:15 AM
> Subject: SORTING ARRAYS
> To: mitcse08i...@googlegroups.com
>
> Given two arrays
> a[] = {1,3,2,4}
> b[] = {4,2,3,1}
> both will have the same numbers but in different combination.
> We have to sort them . The condition is that you cannot compare only
> elements within the same array.You can compare element of one array with
> another only.
>
> ~With Regards
> Padmaja
>
> --
> Regards,
> $iva

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



[algogeeks] Fwd: SORTING ARRAYS

2011-07-26 Thread sivaviknesh s
-- Forwarded message --
From: Padmaja Sridharan 
Date: Wed, Jul 27, 2011 at 5:15 AM
Subject: SORTING ARRAYS
To: mitcse08i...@googlegroups.com



Given two arrays
a[] = {1,3,2,4}
b[] = {4,2,3,1}
both will have the same numbers but in different combination.
We have to sort them . The condition is that you cannot compare only
elements within the same array.You can compare element of one array with
another only.



~With Regards
Padmaja



-- 
Regards,
$iva

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



[algogeeks] Re: AMAZON Q

2011-07-26 Thread bharath
Oops, my bad. I missed that lowest in a[i+1...n] part.

On Jul 26, 10:17 pm, ankit sambyal  wrote:
> @bharath :I think array C is not the resultant array. Take an example and
> explain

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



Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@bharath :I think array C is not the resultant array. Take an example and
explain

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



Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@rajeev:ur algo does not give the correct answer.

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

2011-07-26 Thread bharath
We can use "count sort" to solve this. Assuming each element is the
array is in range 1-k (k=O(n)).

for (i=0 to n)
  C[A[i]]=C[A[i]]+1
for (i=1 to k)
  C[i]=C[i]+C[i-1]

Array 'C' will have the resultant array.

On Jul 26, 9:20 pm, Rajeev Kumar  wrote:
> *
> Algorithm :
> 1)Conside original array a[]
> 2)Construct a sorted list with the array elements(O(nlogn))
> 3)Traverse across all elements of the original array 'a' and find it's
> position(right occurence) in the sorted list using binary search.
>   -position in the sorted list returns the number of elements in the less
> than the current element on right side.
>   -after remove the current element from the sorted list.
> PS: list is preferred datastructure because there are so many insertion and
> deletion operations.
>
> check this link 
> :http://rajeevprasanna.blogspot.com/2011/07/count-number-of-min-elemen...
> *
> On Tue, Jul 26, 2011 at 11:08 AM, ankit sambyal wrote:
>
> > @vivin : Your algo seems to be  wrong. Plz take an example and
> > explain. I may hv misunderstood u ..
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Thank You
> Rajeev Kumar

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

2011-07-26 Thread bharath
Well, the answer should still be in infix except without 'redundant' 
parantheses. So, just converting it to prefix/postfix will not do.  If we 
were to scan the array and remove parentheses, you might end up deleting 
relevant ones. Eg: ((A+B)*C) should output (A+B)*C. So, the key point here 
is to remove superfluous parentheses.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/GjgpYW3LKS8J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Amazon Question

2011-07-26 Thread saurabh singh
using suffix tree this can be done in o(nlogn) though will take extra space.

On Wed, Jul 27, 2011 at 12:47 AM, siva viknesh wrote:

> http://geeksforgeeks.org/?p=767
>
> On Jul 26, 11:49 pm, Pratz mary  wrote:
> > how?
> >
> > On 26 July 2011 23:18, ankit sambyal  wrote:
> >
> > > @vivin : Suffix trees are memory intensive..
> >
> > > This problem can be solved just by running 2 nested loops in O(1)
> > > space and O(n^2) time
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --
> > regards Pratima :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Saurabh Singh
B.Tech (Computer Science)
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 algogeeks@googlegroups.com.
To unsubscribe from 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: AMAZON Q

2011-07-26 Thread Rajeev Kumar
*
Algorithm :
1)Conside original array a[]
2)Construct a sorted list with the array elements(O(nlogn))
3)Traverse across all elements of the original array 'a' and find it's
position(right occurence) in the sorted list using binary search.
  -position in the sorted list returns the number of elements in the less
than the current element on right side.
  -after remove the current element from the sorted list.
PS: list is preferred datastructure because there are so many insertion and
deletion operations.

check this link :
http://rajeevprasanna.blogspot.com/2011/07/count-number-of-min-elements-on-right.html
*
On Tue, Jul 26, 2011 at 11:08 AM, ankit sambyal wrote:

> @vivin : Your algo seems to be  wrong. Plz take an example and
> explain. I may hv misunderstood u ..
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Thank You
Rajeev Kumar

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

2011-07-26 Thread Poised~
To get rid of all parenthesis, we use prefix or postfix notation.
But if you simply want to remove the parenthesis, why not simply scan and 
remove the parenthesis by shifts OR by storing the non-parenthesis elements 
in another output array as we scan the elements?

If I am wrong in getting the question, please do correct me.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/hqUFSejTdzEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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]

2011-07-26 Thread Poised~
Kavitha,

>From a sorted array you need to find two elements whose sum is equal to the 
value given by user.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/Twvbe8Cp7tYJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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]

2011-07-26 Thread Poised~
Niks,

This is the efficient solution for a sorted array.
This algo doesn't use any other storage and is completed in one scan of 
array only.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/MV0B5rk9lJoJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Nagarro Coding Round Ques......

2011-07-26 Thread SkRiPt KiDdIe
I dint get wat are you speaking of.each alphabet is mapped onto
ascii_val-'a' ie ascii of a=97. now check for odd and even occurence is
performed. Work it on paper u'll get it.

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



Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include
#include
#include
#include

using namespace std;

#define ll long long int
#define INF 0x7fff

ll mask(ll x,string str,ll dist)
{
ll re=INF,y=0,len;

len=str.size();

for(int i=0;ire )continue;

else if((int)str[(i+dist)%len]>str;//60 len strings
len=str.size();
x=(1LL

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include
#include
#include
#include

using namespace std;

#define ll long long int
#define INF 0x7fff

ll mask(ll x,string str,ll dist)
{
ll re=INF,y=0,len;

len=str.size();

for(int i=0;ire )continue;

else if((int)str[(i+dist)%len]>str;//60 len strings
len=str.size();
x=(1LL

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include
#include
#include
#include

using namespace std;

#define ll long long int
#define INF 0x7fff

ll mask(ll x,string str,ll dist)
{
ll re=INF,y=0,len;

len=str.size();

for(int i=0;ire )continue;

else if((int)str[(i+dist)%len]>str;//60 len strings
len=str.size();
x=(1LL

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include
#include
#include
#include

using namespace std;

#define ll long long int
#define INF 0x7fff

int mask(ll x,string str,ll dist)
{
ll re=INF,y=0,len;

len=str.size();

for(int i=0;ire )continue;

else if((int)str[(i+dist)%len]>str;//60 len strings
len=str.size();
x=(1LL

Re: [algogeeks] Re: Nagarro Coding Round Ques......

2011-07-26 Thread Pratz mary
hey the above case wont work for a few casesfor instance wen the seventh
letter of the alphabet is involved...

On 26 July 2011 15:32, sachet  wrote:

> please explainthe code
> #include
> using namespace std;
> int main()
> {
> int x=0;
> string str;
> cin>>str;//only lowercase
> for(int i=0;i if(str.size()&1)
> {  if(!(x&(x-1)))cout<<"Palindrome\n";
>else cout<<"Not palindrome\n";
> }
>
> else
> {if(!x)cout<<"Palindrome\n";
>else cout<<"Not palindrome\n";
> }
> }
> i could not understand the algo
>
>
> On Jul 26, 11:07 am, Anika Jain  wrote:
> > int palin(char *p)
> > {
> > int x=0;
> > while(*p)
> > {
> > x^=1<<(*p-'a');
> > p++;
> > }
> > int i=0,count=0;
> > while(i<26)
> > {
> > count+=(1<>i;
> > i++;
> > }
> > if(count>1)
> > return 0;
> > else
> > return 1;
> >
> >
> >
> >
> >
> >
> >
> > }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
regards Pratima :)

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

2011-07-26 Thread Piyush Sinha
http://www.cprogramming.com/tutorial/size_of_class_object.html

On 7/27/11, TUSHAR  wrote:
> 1.
> #include
> using namespace std;
> class abc
> {
> int x;
> static int y;
> };
> main()
> {
> abc a;
> cout< cout< }
>
> why o/p is 4 4 ???
>
>
> 2.
> class abc
> { };
> main()
> {
>   abc ob;
>   cout< }
>
> why o/p is 1 ?
> some say o/p may vary from os to os .why ?? and what may be other
> o/p s ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-7483122727*
*  "NEVER SAY
NEVER"
*

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

2011-07-26 Thread Anurag Narain
@Someshwar: precedence of && > ||

http://www.difranco.net/cop2220/op-prec.htm

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

2011-07-26 Thread bharath
Ah! a good friend just pointed out that step (2) is not quite simple.
A postfix expression bases precedence by the operator position due to
lack of parentheses. I am not sure about the code to convert from
postfix to infix. It *has* to insert parentheses generously to add to
the precedence information lost. So, it will eventually again return
back (A+(B*C)).
So, my approach will not work. Any solutions then?

On Jul 26, 3:26 pm, bharath  wrote:
> Given an expression (A+(B*C)), remove redundant parentheses. Output in
> this case should be A+B*C.
> My initial solution:
> (1) Convert expression from infix to postfix (or prefix) [This way,
> all parentheses are removed]
> (2) Now, convert postfix (or prefix) expression back to infix.
>
> Is there a better way of doing this?

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

2011-07-26 Thread sivaviknesh s
we can do like creating an adjacency matrix..populate all values i.e.
cost to reach each node...finally find the nodes that has min value...any
other gud solutions??

On Wed, Jul 27, 2011 at 2:16 AM, sivaviknesh s wrote:

> the question is clear..you draw the sample test case and work out ..
> you will understand
>
> 1
>  /  /   \
> 4  2   3
> /\
>5 6
>
> here from node 2 the maximum cost to reach any node 'i' is 2 and
> minimum is 1
>
> ...so M(2) = max(1,2)=2..the same is the case for node 1 also
>
> ...if you consider node 4 , to reach 6 , cost is 3similar is
> applicable for other nodes
>
> therefore centre = min(M(1..6)) = 1 and 2.
> ...hope u got me!!
>
> On Wed, Jul 27, 2011 at 2:08 AM, siva viknesh wrote:
>
>>
>>
>>
>> -- Forwarded message --
>> From: jayapriya surendran 
>> Date: Sep 29 2010, 9:41 pm
>> Subject: Directi question-centre of the tree
>> To: Algorithm Geeks
>>
>>
>> In graph theory, atreeis defined as a graph on N nodes,and (N-1)
>> un-directed edges such that there are no cycles in the graph.Each node
>> has a single unique path to every other node.
>> Let D(u,v) be the number of edges in the unique path from node 'u' to
>> node 'v' (or from node 'v' to 'u' since the edges are
>> un-directed).D(u,u) is 0 for all nodes 'u'.
>> M(u)=MAX(D(u,i):for all nodes i)
>> Thecenterof atreeis the node (or nodes) 'u',for which M(u) is
>> minimum among all the nodes in the graph.
>> You'll be given a graph which has N nodes (1<=N<=20).The nodes are
>> labeled 1,2,3,..N.You will be provided with N-1 edges in the form of
>> "a b" pairs where 1<=a,b<=N.No edge will be repeated.You can assume
>> that the edges are specified such that the graph is a validtreeas
>> defined above.
>> Output the node labels of thecenter(or centers) of thetree.
>> Sample Input:
>> 6(value of N)
>> 1 3 (edges)
>> 1 4
>> 1 2
>> 2 5
>> 2 6
>>
>> Sample Output
>> 1
>> 2
>> Expected:O(N) complexity algo
>> can anyone plz help me out with O(N) algo?
>>
>
>
>
> --
> Regards,
> $iva
>
>


-- 
Regards,
$iva

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



[algogeeks] Re: Directi question-centre of the tree

2011-07-26 Thread sivaviknesh s
the question is clear..you draw the sample test case and work out ..
you will understand

1
 /  /   \
4  2   3
/\
   5 6

here from node 2 the maximum cost to reach any node 'i' is 2 and
minimum is 1

...so M(2) = max(1,2)=2..the same is the case for node 1 also

...if you consider node 4 , to reach 6 , cost is 3similar is
applicable for other nodes

therefore centre = min(M(1..6)) = 1 and 2.
...hope u got me!!

On Wed, Jul 27, 2011 at 2:08 AM, siva viknesh wrote:

>
>
>
> -- Forwarded message --
> From: jayapriya surendran 
> Date: Sep 29 2010, 9:41 pm
> Subject: Directi question-centre of the tree
> To: Algorithm Geeks
>
>
> In graph theory, atreeis defined as a graph on N nodes,and (N-1)
> un-directed edges such that there are no cycles in the graph.Each node
> has a single unique path to every other node.
> Let D(u,v) be the number of edges in the unique path from node 'u' to
> node 'v' (or from node 'v' to 'u' since the edges are
> un-directed).D(u,u) is 0 for all nodes 'u'.
> M(u)=MAX(D(u,i):for all nodes i)
> Thecenterof atreeis the node (or nodes) 'u',for which M(u) is
> minimum among all the nodes in the graph.
> You'll be given a graph which has N nodes (1<=N<=20).The nodes are
> labeled 1,2,3,..N.You will be provided with N-1 edges in the form of
> "a b" pairs where 1<=a,b<=N.No edge will be repeated.You can assume
> that the edges are specified such that the graph is a validtreeas
> defined above.
> Output the node labels of thecenter(or centers) of thetree.
> Sample Input:
> 6(value of N)
> 1 3 (edges)
> 1 4
> 1 2
> 2 5
> 2 6
>
> Sample Output
> 1
> 2
> Expected:O(N) complexity algo
> can anyone plz help me out with O(N) algo?
>



-- 
Regards,
$iva

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



[algogeeks] Fwd: Directi question-centre of the tree

2011-07-26 Thread siva viknesh



-- Forwarded message --
From: jayapriya surendran 
Date: Sep 29 2010, 9:41 pm
Subject: Directi question-centre of the tree
To: Algorithm Geeks


In graph theory, atreeis defined as a graph on N nodes,and (N-1)
un-directed edges such that there are no cycles in the graph.Each node
has a single unique path to every other node.
Let D(u,v) be the number of edges in the unique path from node 'u' to
node 'v' (or from node 'v' to 'u' since the edges are
un-directed).D(u,u) is 0 for all nodes 'u'.
M(u)=MAX(D(u,i):for all nodes i)
Thecenterof atreeis the node (or nodes) 'u',for which M(u) is
minimum among all the nodes in the graph.
You'll be given a graph which has N nodes (1<=N<=20).The nodes are
labeled 1,2,3,..N.You will be provided with N-1 edges in the form of
"a b" pairs where 1<=a,b<=N.No edge will be repeated.You can assume
that the edges are specified such that the graph is a validtreeas
defined above.
Output the node labels of thecenter(or centers) of thetree.
Sample Input:
6(value of N)
1 3 (edges)
1 4
1 2
2 5
2 6

Sample Output
1
2
Expected:O(N) complexity algo
can anyone plz help me out with O(N) algo?

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



Re: [algogeeks] preprocessor directives

2011-07-26 Thread Naveen Agrawal
I think "k" value will depend on compiler as we have changed "i" value in
the
 expression "k = ++i*++i" and used it again in the same expression.

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

2011-07-26 Thread bharath
Given an expression (A+(B*C)), remove redundant parentheses. Output in
this case should be A+B*C.
My initial solution:
(1) Convert expression from infix to postfix (or prefix) [This way,
all parentheses are removed]
(2) Now, convert postfix (or prefix) expression back to infix.

Is there a better way of doing this?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: write an scanf that reads only a to z charchter.............

2011-07-26 Thread Tushar Kanta Rath
thanks to all . :)

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

2011-07-26 Thread TUSHAR
1.
#include
using namespace std;
class abc
{
int x;
static int y;
};
main()
{
abc a;
cout

Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
thanx bro

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

2011-07-26 Thread ankit sambyal
@coder :Got my mistake. There is a slight change in the checkmin function.
Actually I was returning the modified value of i and j. Following is the
correct code :

#include
using namespace std;


int checkmin(char arr[],int size,int i,int j)
{
  int k=0,*m=i,n=j*;

 while(arr[i]==arr[j] && khttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: write an scanf that reads only a to z charchter.............

2011-07-26 Thread rajeev bharshetty
@Nithish Yup you are right :)

On Wed, Jul 27, 2011 at 12:54 AM, Nitish Garg wrote:

> scanf("%[^a-z]",z); will only accept characters other than a-z.
> The solution must be scanf("%[a-z]", z); to read only the characters a-z.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/Jr52J0qE63IJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards
Rajeev N B 

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

2011-07-26 Thread aditi garg
can u plz explain dis code?

On Wed, Jul 27, 2011 at 12:37 AM, coder coder
wrote:

> the answer should be 6 correct me if i am getting the  question wrong
>
>
> #include
> using namespace std;
>
>
> int checkmin(char arr[],int size,int i,int j)
> {
>int k=0;
>
>   while(arr[i]==arr[j] && k{
>i=(i+1)%size;
>j=(j+1)%size;
>k++;
>}
>if(k==size)
>
>return i;   //Strings at i and j are both
> same. You can return either index
>else if(arr[i] less than string starting at index j
>return i;
>else//String starting at index j is
> less than string starting at index i
>return j;
> }
>
>
> int getFirstIndexInLex(char arr[],int size)
> {
>int minindex=0,i;
>for(i=1;i{
>if(arr[i] < arr[minindex])
>minindex=i;
>else if(arr[i]==arr[minindex])
>minindex=checkmin(arr,size,minindex,i);
>}
>return minindex;
> }
>
>
>
> int main()
> {
> cout< system("pause");
>
> }
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



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

9718388816

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



[algogeeks] Re: write an scanf that reads only a to z charchter.............

2011-07-26 Thread Nitish Garg
scanf("%[^a-z]",z); will only accept characters other than a-z.
The solution must be scanf("%[a-z]", z); to read only the characters a-z.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/Jr52J0qE63IJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Amazon Question

2011-07-26 Thread siva viknesh
http://geeksforgeeks.org/?p=767

On Jul 26, 11:49 pm, Pratz mary  wrote:
> how?
>
> On 26 July 2011 23:18, ankit sambyal  wrote:
>
> > @vivin : Suffix trees are memory intensive..
>
> > This problem can be solved just by running 2 nested loops in O(1)
> > space and O(n^2) time
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> regards Pratima :)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: write an scanf that reads only a to z charchter.............

2011-07-26 Thread rShetty
scanf("%[^a-z]",z);

On Jul 27, 12:13 am, TUSHAR  wrote:
> write an scanf that reads only a to z charchter.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] write an scanf that reads only a to z charchter.............

2011-07-26 Thread rajeev bharshetty
scanf("%[^a-z]",i);

On Wed, Jul 27, 2011 at 12:43 AM, TUSHAR  wrote:

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


-- 
Regards
Rajeev N B 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] write an scanf that reads only a to z charchter.............

2011-07-26 Thread TUSHAR
write an scanf that reads only a to z charchter.

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

2011-07-26 Thread coder coder
the answer should be 6 correct me if i am getting the  question wrong


#include
using namespace std;

int checkmin(char arr[],int size,int i,int j)
{
   int k=0;
  while(arr[i]==arr[j] && khttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder : No, my solution gives the correct answer. Check it out again !!

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

2011-07-26 Thread coder coder
@ankit still your solution is not giving the correct result for this test
case

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

2011-07-26 Thread ankit sambyal
@coder: my mistake. There is a typo in my code.
the condition is :
while(arr[i]==arr[j] && khttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
ankit your solution gives answer 11 for test case ABCDEAABCCDA ie
AABCDEAABCCD
Isn't solution is AABCCDAABCDE ie 6

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

2011-07-26 Thread ankit sambyal
There is a mistake in my code:
In the function
int checkmin(char arr[],int size,int i,int j)
after the while loop in the line
if(k==0)

It shud be :
if(k==size) instead of  if(k==0)

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



Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
@ankit

your answer is wrong for the test case ABCDEAABCCDA

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

2011-07-26 Thread coder coder
yes

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

2011-07-26 Thread Pratz mary
how?


On 26 July 2011 23:18, ankit sambyal  wrote:

> @vivin : Suffix trees are memory intensive..
>
> This problem can be solved just by running 2 nested loops in O(1)
> space and O(n^2) time
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
regards Pratima :)

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

2011-07-26 Thread syl
im having problem with learning suffix array
i have few doubts
can kmp be an alternative to suffix array in every case
i tried to read SA from wiki but they didnt explain   much...
could anyone help me in this...i want to learn how to implement it and
where to use it.

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



Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
int getFirstIndexInLex(char arr[],int size)
{
int minindex=0,i;
for(i=1;ihttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: please help

2011-07-26 Thread Pratz mary
would it make a difference if it wasnt a circular array?


On 26 July 2011 23:52, coder coder  wrote:

> in the circular array ABCDEABCCDE
> The answer is 6 because the circular string starting from the element
> A in the 6th position comes first in the dictionary formed from all
> the possible strings of the circular array.
>
> for "ABCDEAABCCDA"  is 6
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
regards Pratima :)

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

2011-07-26 Thread Ankur Khurana
i believe you are asking for rank in lexicographic rotation

On Tue, Jul 26, 2011 at 11:52 PM, coder coder
wrote:

> in the circular array ABCDEABCCDE
> The answer is 6 because the circular string starting from the element
> A in the 6th position comes first in the dictionary formed from all
> the possible strings of the circular array.
>
> for "ABCDEAABCCDA"  is 6
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.

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

2011-07-26 Thread coder coder
in the circular array ABCDEABCCDE
The answer is 6 because the circular string starting from the element
A in the 6th position comes first in the dictionary formed from all
the possible strings of the circular array.

for "ABCDEAABCCDA"  is 6

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

2011-07-26 Thread sukhmeet singh
provide a sample i/p output..!!

On Tue, Jul 26, 2011 at 11:43 PM, coder coder
wrote:

> Write a program to find the index in an circular array such that the
> string that is formed starting from that index is first in
> lexicographic order.
>
> on all the sites the code part is misunderstood for the test case
> "ABCDEAABCCDA"
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] please help

2011-07-26 Thread coder coder
Write a program to find the index in an circular array such that the
string that is formed starting from that index is first in
lexicographic order.

on all the sites the code part is misunderstood for the test case
"ABCDEAABCCDA"

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

2011-07-26 Thread ankit sambyal
@vivin : Your algo seems to be  wrong. Plz take an example and
explain. I may hv misunderstood u ..

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

2011-07-26 Thread siva viknesh
ideone.com is also great

On Jul 26, 10:03 pm, Ram CEG  wrote:
> ya it would ignore \ alone..
>
> On Tue, Jul 26, 2011 at 10:27 PM, aditi garg wrote:
>
>
>
>
>
>
>
> > ya thats wat my doubt was...if its not a recognised escape sequence thn how
> > is it interpreted??
> > Would the compiler jst ignore ''\''?
>
> > On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG  wrote:
>
> >> op:abc.. \c is not an escape sequence
>
> >> On Tue, Jul 26, 2011 at 10:17 PM, aditi garg 
> >> wrote:
>
> >>> what will be the output fr this??
> >>> printf("ab\c");
>
> >>> On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul 
> >>> wrote:
>
>  Dipankar, Thanks!!!
>
>  On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro 
>  wrote:
>
> > Swetha,
>
> > '\' in C is used to denote a escape sequence in C strings (and also in
> > many other languages).
> > e.g '\n' is for New Line '\n' is counted as one character.
> > Now '\ooo' is for an ASCII in octal representation.
> > here is the list of all escape sequences:
> >http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx
>
> > So for your string : "\12345s\n"
> > here '\123' is an ASCII in octal, hence one character.
> > rest you know about the characters: so length = '\123'(1) + 3 + '\n'(1)
> > = 5.
>
> > I suggest you try with other combinations with '\' and print the
> > output. They will definitely show some weird stuffs :)
>
> > Hope that helps.
> >   On 25 July 2011 22:53, swetha rahul  wrote:
>
> >>   char *s="\12345s\n";
> >> printf("\n %d",strlen(s));
>
> >> The output is 5...?? But how.??
>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
>
> > ___
>
> > Please do not print this e-mail until urgent requirement. Go Green!!
> > Save Papers <=> Save Trees
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
>  --
>  You received this message because you are subscribed to the Google
>  Groups "Algorithm Geeks" group.
>  To post to this group, send email to algogeeks@googlegroups.com.
>  To unsubscribe from this group, send email to
>  algogeeks+unsubscr...@googlegroups.com.
>  For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
> >>> --
> >>> Aditi Garg
> >>> Undergraduate Student
> >>> Electronics & Communication Divison
> >>> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> >>> Sector 3, Dwarka
> >>> New Delhi
>
> >>> 9718388816
>
> >>>   --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Algorithm Geeks" group.
> >>> To post to this group, send email to algogeeks@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> algogeeks+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/algogeeks?hl=en.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > Aditi Garg
> > Undergraduate Student
> > Electronics & Communication Divison
> > NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> > Sector 3, Dwarka
> > New Delhi
>
> > 9718388816
>
> >   --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

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

2011-07-26 Thread siva viknesh
@both...fantastic explanation...thanks :)

On Jul 26, 10:34 pm, rajeev bharshetty  wrote:
> So if the input is gujarat it scans gujarat to find the first character in
> gujarat which is also present in india . So the character in gujarat is a so
> it will stop on encountering a and prints the string scanned till then.
>
> If the input is india , it matches at first location so it prints the
> contents of str which is junk.
>
> Now consider rajeev it will print r because of a at second position. and for
> siva it will print s try it out.
>
> Hope you understood the concept.
>
>
>
>
>
>
>
>
>
> On Tue, Jul 26, 2011 at 10:54 PM, kc Liyan  wrote:
> > if U given input as gujarat the scanf will accept inputs as
> > char's.but there s an ^ which means ex-or operation should be
> > performed regular check of existance of any char of {india}...
> > untill it get's the existance then it will stop the input
> > getting..finally it prints as guj
>
> > On 7/26/11, siva viknesh  wrote:
> > > main()
> > > {
>
> > > char str[80];
> > > strcpy(str,"junk");
> > > scanf("%[^india]",str);
> > > printf("%s",str);
>
> > > }
>
> > > ...input is gujarat.output is guj.plz explain how?
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Regards
> Rajeev N B 

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

2011-07-26 Thread vivin
The binary search trees can be used ...arrange the given elements in
binary search tree ...search for each element in the tree count
the number of nodes along its left successors until the leaf node is
reached ...!! thats the ans !!


On Jul 26, 6:53 pm, Someshwar Chandrasekaran 
wrote:
> On Tue, Jul 26, 2011 at 7:18 PM, Piyush Sinha  
> wrote:
> > You have an array like ar[]= {1,3,2,4,5,4,2}. You need to create
> > another array ar_low[] such that ar_low[i] = number of elements lower
> > than or equal to ar[i] in ar[i+1:n-1].
> > So the output of above should be {0,2,1,2,2,1,0}
>
> > Time complexity : O(nlogn)
> > use of extra space allowed.
>
> A straight forward question
> for i in 0 to n-1:
>   temp = 0;
>   for j in i+1 to n-1:
>     if arr[j]<= arr[i]:
>         temp++;
>   ar_low[i] = temp
>
> But the trick is to find a better algorithm with better complexity
>
> Regards,
> B.C.Someshwar
>
> --
> 'Talk sense to a fool and he calls you foolish.' - Euripides
>
> My Blog:  somsekaran.wordpress.com

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



Re: [algogeeks] Re: Amazon Question

2011-07-26 Thread ankit sambyal
@vivin : Suffix trees are memory intensive..

This problem can be solved just by running 2 nested loops in O(1)
space and O(n^2) time

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



[algogeeks] Re: Amazon Question

2011-07-26 Thread vivin
suffix tree can be used print all the nodes...u ll get every
substring ..!!


On Jul 26, 8:51 pm, Ankur Garg  wrote:
> Hey Guys
>
> Can we use KMP Algorithm here to generate permutations...May be a bit
> modification is req
>
> On Tue, Jul 26, 2011 at 9:07 PM, keyan karthi 
> wrote:
>
>
>
>
>
>
>
> > oops .. permutation  pardon me guys !!!
>
> > On 7/26/11, keyan karthi  wrote:
> > > @kavitha: u can use back tracking to print all the substring for a
> > > string .. pseudo code should look some thing like this:
>
> > > void next_perm(string st,int pos)
> > > {
> > >    if(pos==length)
> > >    {
> > >      cout< > >     return;
> > >    }
> > >    for(int i=pos;i > >   {
> > >     swap(st,i,pos);
> > >     next_perm(st,i+1);
> > >     swap(st,i,pos);
> > >   }
> > > }
>
> > > On 7/26/11, ankit sambyal  wrote:
> > >> @Swetha :Number of possible sub strings of a string of length n is of
> > >> the order of n^2.
> > >> So, there can,t be a better solution than O(n^2)
>
> > >> --
> > >> You received this message because you are subscribed to the Google
> > Groups
> > >> "Algorithm Geeks" group.
> > >> To post to this group, send email to algogeeks@googlegroups.com.
> > >> To unsubscribe from this group, send email to
> > >> algogeeks+unsubscr...@googlegroups.com.
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

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



[algogeeks] IPC Material

2011-07-26 Thread Swathi
Does anyone has good material on InterProcessCommunications? Please share.

Thanks in advance.

-Swathi

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

2011-07-26 Thread rajeev bharshetty
@Ankur The link does has a very good explanation. Nice solution :)

On Tue, Jul 26, 2011 at 10:47 PM, Kunal Patil  wrote:

> @Ankur Garg: Nice explanation at the link given by u...
>
>
> On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg  wrote:
>
>> Check this
>>
>> http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
>>
>>
>> On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote:
>>
>>> Here is the working code..
>>>
>>> #include 
>>> #include 
>>> int a[] = {1,2,3,4,5};
>>> #define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
>>> void print_comb(int len)
>>> {
>>>int tlen = len;
>>>int i, j, k;
>>> int al = ARRLEN(a);
>>>for (i = 0; i < al; i++) {
>>>for (j=i+len-1; j>>for (k = i; k < i+len-1; k++) {
>>>printf("%d ", a[k]);
>>>}
>>>printf("%d\n", a[j]);
>>> }
>>>}
>>> }
>>>
>>> int main(int argc, char *argv[])
>>> {
>>>int len = atoi(argv[1]);
>>> print_comb(len);
>>>return 0;
>>> }
>>>
>>>
>>>
>>> On Tue, Jul 26, 2011 at 5:18 PM, praneethn 
>>> wrote:
>>> >
>>> > check this link:
>>> >
>>> > *http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*
>>> >
>>> > On Tue, Jul 26, 2011 at 11:59 AM, sumit 
>>> wrote:
>>> >>
>>> >> Given an array of size n, print all the possible subset of array of
>>> >> size k.
>>> >> eg:-
>>> >> input:
>>> >> a[]={1,2,3,4}, k = 2
>>> >> output:
>>> >> 1,2
>>> >> 1,3
>>> >> 1,4
>>> >> 2,3
>>> >> 2,4
>>> >> 3,4
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google
>>> Groups
>>> >> "Algorithm Geeks" group.
>>> >> To post to this group, send email to algogeeks@googlegroups.com.
>>> >> To unsubscribe from this group, send email to
>>> >> algogeeks+unsubscr...@googlegroups.com.
>>> >> For more options, visit this group at
>>> >> http://groups.google.com/group/algogeeks?hl=en.
>>> >>
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Algorithm Geeks" group.
>>> > To post to this group, send email to algogeeks@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > algogeeks+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards
Rajeev N B 

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

2011-07-26 Thread rajeev bharshetty
So if the input is gujarat it scans gujarat to find the first character in
gujarat which is also present in india . So the character in gujarat is a so
it will stop on encountering a and prints the string scanned till then.

If the input is india , it matches at first location so it prints the
contents of str which is junk.

Now consider rajeev it will print r because of a at second position. and for
siva it will print s try it out.

Hope you understood the concept.

On Tue, Jul 26, 2011 at 10:54 PM, kc Liyan  wrote:

> if U given input as gujarat the scanf will accept inputs as
> char's.but there s an ^ which means ex-or operation should be
> performed regular check of existance of any char of {india}...
> untill it get's the existance then it will stop the input
> getting..finally it prints as guj
>
> On 7/26/11, siva viknesh  wrote:
> > main()
> > {
> >
> > char str[80];
> > strcpy(str,"junk");
> > scanf("%[^india]",str);
> > printf("%s",str);
> >
> >
> > }
> >
> > ...input is gujarat.output is guj.plz explain how?
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Regards
Rajeev N B 

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

2011-07-26 Thread kc Liyan
if U given input as gujarat the scanf will accept inputs as
char's.but there s an ^ which means ex-or operation should be
performed regular check of existance of any char of {india}...
untill it get's the existance then it will stop the input
getting..finally it prints as guj

On 7/26/11, siva viknesh  wrote:
> main()
> {
>
> char str[80];
> strcpy(str,"junk");
> scanf("%[^india]",str);
> printf("%s",str);
>
>
> }
>
> ...input is gujarat.output is guj.plz explain how?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] GATE C-Question

2011-07-26 Thread sasi kumar
hi
> void XYZ(int a[],int b[], int c[])
> {
> int i,j,k;
> i=j=k=0;
> while((i {
> if (a[i]  c[k++]=a[i++];
>  else
>  c[k++]=b[j++];
>0
> }

   In this case either i value or j value is incremented at a time
in an iteration . So its impossible that both the conditions (i< n)
and (j
> Which of the following condition(s) hold(s) after the termination of
> the while loop?
>
> i)j
> ii)ihttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Facebook Interview question at NIT Warangal

2011-07-26 Thread Kunal Patil
@Ankur Garg: Nice explanation at the link given by u...

On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg  wrote:

> Check this
>
> http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
>
>
> On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote:
>
>> Here is the working code..
>>
>> #include 
>> #include 
>> int a[] = {1,2,3,4,5};
>> #define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
>> void print_comb(int len)
>> {
>>int tlen = len;
>>int i, j, k;
>> int al = ARRLEN(a);
>>for (i = 0; i < al; i++) {
>>for (j=i+len-1; j>for (k = i; k < i+len-1; k++) {
>>printf("%d ", a[k]);
>>}
>>printf("%d\n", a[j]);
>> }
>>}
>> }
>>
>> int main(int argc, char *argv[])
>> {
>>int len = atoi(argv[1]);
>> print_comb(len);
>>return 0;
>> }
>>
>>
>>
>> On Tue, Jul 26, 2011 at 5:18 PM, praneethn  wrote:
>> >
>> > check this link:
>> >
>> > *http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*
>> >
>> > On Tue, Jul 26, 2011 at 11:59 AM, sumit 
>> wrote:
>> >>
>> >> Given an array of size n, print all the possible subset of array of
>> >> size k.
>> >> eg:-
>> >> input:
>> >> a[]={1,2,3,4}, k = 2
>> >> output:
>> >> 1,2
>> >> 1,3
>> >> 1,4
>> >> 2,3
>> >> 2,4
>> >> 3,4
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Algorithm Geeks" group.
>> >> To post to this group, send email to algogeeks@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS c output ques

2011-07-26 Thread siva viknesh
main()
{

char str[80];
strcpy(str,"junk");
scanf("%[^india]",str);
printf("%s",str);


}

...input is gujarat.output is guj.plz explain how?

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

2011-07-26 Thread Ankur Garg
Check this

http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html


On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote:

> Here is the working code..
>
> #include 
> #include 
> int a[] = {1,2,3,4,5};
> #define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
> void print_comb(int len)
> {
>int tlen = len;
>int i, j, k;
> int al = ARRLEN(a);
>for (i = 0; i < al; i++) {
>for (j=i+len-1; jfor (k = i; k < i+len-1; k++) {
>printf("%d ", a[k]);
>}
>printf("%d\n", a[j]);
> }
>}
> }
>
> int main(int argc, char *argv[])
> {
>int len = atoi(argv[1]);
> print_comb(len);
>return 0;
> }
>
>
>
> On Tue, Jul 26, 2011 at 5:18 PM, praneethn  wrote:
> >
> > check this link:
> >
> > *http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*
> >
> > On Tue, Jul 26, 2011 at 11:59 AM, sumit  wrote:
> >>
> >> Given an array of size n, print all the possible subset of array of
> >> size k.
> >> eg:-
> >> input:
> >> a[]={1,2,3,4}, k = 2
> >> output:
> >> 1,2
> >> 1,3
> >> 1,4
> >> 2,3
> >> 2,4
> >> 3,4
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] C Output

2011-07-26 Thread Ram CEG
ya it would ignore \ alone..

On Tue, Jul 26, 2011 at 10:27 PM, aditi garg wrote:

> ya thats wat my doubt was...if its not a recognised escape sequence thn how
> is it interpreted??
> Would the compiler jst ignore ''\''?
>
>
> On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG  wrote:
>
>> op:abc.. \c is not an escape sequence
>>
>>
>> On Tue, Jul 26, 2011 at 10:17 PM, aditi garg 
>> wrote:
>>
>>> what will be the output fr this??
>>> printf("ab\c");
>>>
>>>
>>> On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul 
>>> wrote:
>>>
 Dipankar, Thanks!!!


 On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote:

>
> Swetha,
>
> '\' in C is used to denote a escape sequence in C strings (and also in
> many other languages).
> e.g '\n' is for New Line '\n' is counted as one character.
> Now '\ooo' is for an ASCII in octal representation.
> here is the list of all escape sequences:
> http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx
>
> So for your string : "\12345s\n"
> here '\123' is an ASCII in octal, hence one character.
> rest you know about the characters: so length = '\123'(1) + 3 + '\n'(1)
> = 5.
>
> I suggest you try with other combinations with '\' and print the
> output. They will definitely show some weird stuffs :)
>
> Hope that helps.
>   On 25 July 2011 22:53, swetha rahul  wrote:
>
>>   char *s="\12345s\n";
>> printf("\n %d",strlen(s));
>>
>> The output is 5...?? But how.??
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>
> ___
>
> Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

>>>
>>>
>>>
>>> --
>>> Aditi Garg
>>> Undergraduate Student
>>> Electronics & Communication Divison
>>> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
>>> Sector 3, Dwarka
>>> New Delhi
>>>
>>> 9718388816
>>>
>>>   --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Aditi Garg
> Undergraduate Student
> Electronics & Communication Divison
> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> Sector 3, Dwarka
> New Delhi
>
> 9718388816
>
>   --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

2011-07-26 Thread Vivek Srivastava
Yes compiler always ignores the first '\' and if it finds a recognizable
character after this escape sequence . it will interpret it. Otherwise it
just dumps it according to predefined semantics of machine code
generation.But I would suggest everyone in this group to try out
http://www.codepad.org
Where you can easily test the code in any language of your choice.
It must be using gcc compiler.
Thanks

On Tue, Jul 26, 2011 at 10:27 PM, aditi garg wrote:

> ya thats wat my doubt was...if its not a recognised escape sequence thn how
> is it interpreted??
> Would the compiler jst ignore ''\''?
>
>
> On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG  wrote:
>
>> op:abc.. \c is not an escape sequence
>>
>>
>> On Tue, Jul 26, 2011 at 10:17 PM, aditi garg 
>> wrote:
>>
>>> what will be the output fr this??
>>> printf("ab\c");
>>>
>>>
>>> On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul 
>>> wrote:
>>>
 Dipankar, Thanks!!!


 On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote:

>
> Swetha,
>
> '\' in C is used to denote a escape sequence in C strings (and also in
> many other languages).
> e.g '\n' is for New Line '\n' is counted as one character.
> Now '\ooo' is for an ASCII in octal representation.
> here is the list of all escape sequences:
> http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx
>
> So for your string : "\12345s\n"
> here '\123' is an ASCII in octal, hence one character.
> rest you know about the characters: so length = '\123'(1) + 3 + '\n'(1)
> = 5.
>
> I suggest you try with other combinations with '\' and print the
> output. They will definitely show some weird stuffs :)
>
> Hope that helps.
>   On 25 July 2011 22:53, swetha rahul  wrote:
>
>>   char *s="\12345s\n";
>> printf("\n %d",strlen(s));
>>
>> The output is 5...?? But how.??
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>
> ___
>
> Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

>>>
>>>
>>>
>>> --
>>> Aditi Garg
>>> Undergraduate Student
>>> Electronics & Communication Divison
>>> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
>>> Sector 3, Dwarka
>>> New Delhi
>>>
>>> 9718388816
>>>
>>>   --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Aditi Garg
> Undergraduate Student
> Electronics & Communication Divison
> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> Sector 3, Dwarka
> New Delhi
>
> 9718388816
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

Re: [algogeeks] C Output

2011-07-26 Thread aditi garg
ya thats wat my doubt was...if its not a recognised escape sequence thn how
is it interpreted??
Would the compiler jst ignore ''\''?

On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG  wrote:

> op:abc.. \c is not an escape sequence
>
>
> On Tue, Jul 26, 2011 at 10:17 PM, aditi garg wrote:
>
>> what will be the output fr this??
>> printf("ab\c");
>>
>>
>> On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul wrote:
>>
>>> Dipankar, Thanks!!!
>>>
>>>
>>> On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote:
>>>

 Swetha,

 '\' in C is used to denote a escape sequence in C strings (and also in
 many other languages).
 e.g '\n' is for New Line '\n' is counted as one character.
 Now '\ooo' is for an ASCII in octal representation.
 here is the list of all escape sequences:
 http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx

 So for your string : "\12345s\n"
 here '\123' is an ASCII in octal, hence one character.
 rest you know about the characters: so length = '\123'(1) + 3 + '\n'(1)
 = 5.

 I suggest you try with other combinations with '\' and print the output.
 They will definitely show some weird stuffs :)

 Hope that helps.
   On 25 July 2011 22:53, swetha rahul  wrote:

>   char *s="\12345s\n";
> printf("\n %d",strlen(s));
>
> The output is 5...?? But how.??
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



 --

 ___

 Please do not print this e-mail until urgent requirement. Go Green!!
 Save Papers <=> Save Trees

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

>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Aditi Garg
>> Undergraduate Student
>> Electronics & Communication Divison
>> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
>> Sector 3, Dwarka
>> New Delhi
>>
>> 9718388816
>>
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



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

9718388816

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



Re: [algogeeks] C Output

2011-07-26 Thread Ram CEG
op:abc.. \c is not an escape sequence

On Tue, Jul 26, 2011 at 10:17 PM, aditi garg wrote:

> what will be the output fr this??
> printf("ab\c");
>
>
> On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul wrote:
>
>> Dipankar, Thanks!!!
>>
>>
>> On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote:
>>
>>>
>>> Swetha,
>>>
>>> '\' in C is used to denote a escape sequence in C strings (and also in
>>> many other languages).
>>> e.g '\n' is for New Line '\n' is counted as one character.
>>> Now '\ooo' is for an ASCII in octal representation.
>>> here is the list of all escape sequences:
>>> http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx
>>>
>>> So for your string : "\12345s\n"
>>> here '\123' is an ASCII in octal, hence one character.
>>> rest you know about the characters: so length = '\123'(1) + 3 + '\n'(1) =
>>> 5.
>>>
>>> I suggest you try with other combinations with '\' and print the output.
>>> They will definitely show some weird stuffs :)
>>>
>>> Hope that helps.
>>>   On 25 July 2011 22:53, swetha rahul  wrote:
>>>
   char *s="\12345s\n";
 printf("\n %d",strlen(s));

 The output is 5...?? But how.??

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

>>>
>>>
>>>
>>> --
>>>
>>> ___
>>>
>>> Please do not print this e-mail until urgent requirement. Go Green!!
>>> Save Papers <=> Save Trees
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Aditi Garg
> Undergraduate Student
> Electronics & Communication Divison
> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> Sector 3, Dwarka
> New Delhi
>
> 9718388816
>
>   --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

2011-07-26 Thread aditi garg
what will be the output fr this??
printf("ab\c");

On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul wrote:

> Dipankar, Thanks!!!
>
>
> On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote:
>
>>
>> Swetha,
>>
>> '\' in C is used to denote a escape sequence in C strings (and also in
>> many other languages).
>> e.g '\n' is for New Line '\n' is counted as one character.
>> Now '\ooo' is for an ASCII in octal representation.
>> here is the list of all escape sequences:
>> http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx
>>
>> So for your string : "\12345s\n"
>> here '\123' is an ASCII in octal, hence one character.
>> rest you know about the characters: so length = '\123'(1) + 3 + '\n'(1) =
>> 5.
>>
>> I suggest you try with other combinations with '\' and print the output.
>> They will definitely show some weird stuffs :)
>>
>> Hope that helps.
>>  On 25 July 2011 22:53, swetha rahul  wrote:
>>
>>>  char *s="\12345s\n";
>>> printf("\n %d",strlen(s));
>>>
>>> The output is 5...?? But how.??
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>>
>> ___
>>
>> Please do not print this e-mail until urgent requirement. Go Green!!
>> Save Papers <=> Save Trees
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



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

9718388816

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



Re: [algogeeks] self referential struct. Contd.

2011-07-26 Thread Nikhil Gupta
Padding is not a topic of self referential structure.

Padding means that extra spaces of memory are used by the compiler to
allocate memory. This is done to have the memory address as a multiple of
the size of the variable. This speeds up the processing of these variables
by the compiler.

On Tue, Jul 26, 2011 at 8:09 PM, Puneet Gautam wrote:

> what is meant by padding in self_referenced structure?
> Is it always necessary?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


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

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



Re: [algogeeks]

2011-07-26 Thread saurabh singh
@kavitha Yeah I was just giving examples.The idea is to push everything into
a buffer and then parse according to ur needs.From my experiences and
experiments the list in ascending order of time taken is
1,fread_unlocked
2.fread
3getchar_unlocked
4.getchar
5.gets

(3,4 & 5  may show variable behaviour).

On Tue, Jul 26, 2011 at 7:58 PM, rajeev bharshetty wrote:

> test or text ??
>
>
> On Tue, Jul 26, 2011 at 7:52 PM, kavitha nk  wrote:
>
>> @saurabh::gets too could be used
>>
>>
>> //BE COOL//   kavi
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards
> Rajeev N B 
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Saurabh Singh
B.Tech (Computer Science)
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 algogeeks@googlegroups.com.
To unsubscribe from 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] Closest as Possible

2011-07-26 Thread saurabh singh
Is answer 0 ??

On Tue, Jul 26, 2011 at 7:41 PM, rajeev bharshetty wrote:

> Sum of any number of elements on the two partitions should be as close as
> possible.
>
>
> On Tue, Jul 26, 2011 at 6:49 PM, Puneet Gautam wrote:
>
>> @rshetty: do u mean the sum of any no of elements separately in the
>> two partitions be equal to each other..? is that what u mean..?
>>
>> On 7/26/11, rShetty  wrote:
>> > Problem statement goes as :
>> >
>> > Consider square root of integers form 1 to 100. Now partition the
>> > square roots of integers as being from 1 to 50 and 51 to 100.
>> > Now find the sum in the two partitions which is as close as possible
>> > or minimum?
>> > Give the algorithm ?? and das structures to be used??
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Regards
> Rajeev N B 
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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 & Regards,
Saurabh

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

2011-07-26 Thread kavitha nk
sry sry o/p ll be 0 1 0in the 2nd printf the value ll be evaluated
from rite to left...
so in the 1st printf i's vlue ll be 0 and in the 2nd printf stmt rite
expression is evaluated first and then i value ll be modified in it..
and with hte help of it left one is evaluated...crct me if i'm
wrong..

On 7/26/11, kavitha nk  wrote:
> ans ll nt be 0 0 2 va???
>
> On 7/25/11, Puneet Gautam  wrote:
>> @aditi: the "%2" in each of these printf statements is redundant coz
>> it is "1%2"...and "%" has higher precedence over left or right
>> shifts..thats y output of say :
>>
>> #include
>> main()
>> {
>> int i=1;
>> printf("\n%d%d ",i<<=2,i<<=1%2);
>> return 0;
>> }
>>
>> is 8 8
>>
>> 1 gets left shifted twice in i<<=2, becomes 4
>> then i<<1%2 concludes to i<<1 as 1%2 is 1 only..
>> i<<1 ,makes i=8 and hence
>>
>> 8 8 is printed.
>>
>> On 7/25/11, Puneet Gautam  wrote:
>>> @rajeev: hey...does printf evaluate an expression right to left
>>> without considering any priority of operators..?
>>> Pls reply asap..
>>>
>>>
>>>
>>> On 7/25/11, Puneet Gautam  wrote:
 @aditi: y dont u try it out urself considering the priorities of
 different operators used here...!!
 that would help...

 On 7/25/11, aditi garg  wrote:
> Can u plz elaborate...im not able to understand...
>
> On Mon, Jul 25, 2011 at 11:04 PM, rajeev bharshetty
> wrote:
>
>> @sameer I think that is right
>>
>>
>> On Mon, Jul 25, 2011 at 11:02 PM, sameer.mut...@gmail.com <
>> sameer.mut...@gmail.com> wrote:
>>
>>> its because of side effect where value of i is getting changed twice
>>> in
>>> a
>>> single line.
>>> correct me if i am wrong :)
>>>
>>> *Muthuraj R.
>>> 4TH Year BE.**
>>> Information Science Dept*
>>> *PESIT, Bengaluru .
>>> *
>>>
>>>
>>>
>>>
>>> On Mon, Jul 25, 2011 at 11:01 PM, geek forgeek
>>> wrote:
>>>
 y not the output is 3 2  coz on right to left evaluation  of printf
 i
 shud be left shifted by 1 bit wgich shud make it 2 ??


 On Mon, Jul 25, 2011 at 10:28 AM, sameer.mut...@gmail.com <
 sameer.mut...@gmail.com> wrote:

> yeah output
>  0
> 1 1
> *is dis because of side effect? *
> * *
> *
> *
> *Muthuraj R.
> 4TH Year BE.**
> Information Science Dept*
> *PESIT, Bengaluru .
> *
>
>
>
>
>
> On Mon, Jul 25, 2011 at 10:49 PM, Deoki Nandan
> wrote:
>
>> run on gcc compiler it would be
>> 0
>> 1 1
>>
>>
>> On Mon, Jul 25, 2011 at 10:35 PM, geek forgeek
>> wrote:
>>
>>> 1.
>>> #include
>>> main()
>>> {
>>> int i=1;
>>>  printf("\n%d",i^=1%2);
>>>  printf("\n%d %d",i^=1%2,i<<=1%2);
>>> return 0;
>>> }
>>>
>>> output 3 3
>>> hey shudnt the output be 3 2
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the
>>> Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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
>> Deoki Nandan Vishwakarma
>>
>> *
>> *
>>
>>  --
>> You received this message because you are subscribed to the
>> Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

  --
 You received this message because you are subscribed to the Google
 Groups
 "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
>>

  1   2   3   >