Re: [algogeeks] Re: TopCoder Bad Neighbour

2010-12-22 Thread Manmeet Singh
class BadNeighbors {
public:
int maxDonations(vector );
};
int dp[51][2][2];
int l;
vector v;
int solve(int id, int taken, int first) {
if(id==l)
return 0;
int &d = dp[id][taken][first];
if(~d) return d;
d = 0;
if(id!=l-1) {
if(taken==0) {
d >?= v[id] + solve(id+1, 1, (id==0) | first);
d >?= solve(id+1, 0, first);
}
else {
d >?= solve(id+1, 0, first);
}
}
else {
if(first==1) {
d >?= solve(id+1, 1, first);
}
else {
if(taken==0) {
d >?= v[id] + solve(id+1, 1, first);
d >?= solve(id+1, 0, first);
}
else {
d >?= solve(id+1, 0, first);
}
}
}
return d;
}
int BadNeighbors::maxDonations(vector  v) {
:: v = v;
l = v.size();
memset(dp, -1, sizeof dp);
return solve(0, 0, 0);
}


On Wed, Dec 22, 2010 at 9:00 PM, mohit ranjan wrote:

> Ok, I got the recurrence relation at
>
> http://www.topcoder.com/tc?module=Static&d1=match_editorials&d2=tccc04_online_rd_4
>
>
> Mohit
>
>
>
> On Wed, Dec 22, 2010 at 8:33 PM, mohit ranjan wrote:
>
>> Hi All,
>>
>> Can anybody help me with some hint for
>> http://www.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009
>>
>>
>> Mohit
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread jai gupta
make  another array(B) from (A) with all elements negated
now find one element from B and one from A  whose sum is x or -x. This can
ofcourse be done in O(n).

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



[algogeeks] Call for Papers & Sessions: The 2011 International Conference on Software Engineering Research and Practice (SERP'11), USA, July 18-21, 2011

2010-12-22 Thread A. M. G. Solo
   CALL  FOR  PAPERS
 and
  Call For Workshop/Session Proposals
 
   SERP'11
 The 2011 International Conference on Software
   Engineering Research and Practice
 
   Date and Location: July 18-21, 2011, USA
 
   http://www.world-academy-of-science.org/
   Location: See the above web site for venue/city
 
You are invited to submit a full paper for consideration. All
accepted papers will be published in the SERP conference
proceedings (in printed book form; later, the proceedings will
also be accessible online). Those interested in proposing
workshops/sessions, should refer to the relevant sections that
appear below.
 
 
SCOPE: Topics of interest include, but are not limited to, the following:
 
O  Software architectures
O  Software design and design patterns
O  Architectural analysis, verifications and validation methods
O  Quality oriented software architecture (design and Support)
O  Software reliability, safety critical systems and security methods
O  Software reuse and component engineering
O  UML/MDA and AADL
O  Object oriented technology (design and analysis)
O  Software metrics
O  Reverse and architectural recovery methods
O  Domain specific software engineering
O  Aerospace software and system engineering
O  Software engineering methodologies
O  Survivable systems
O  Engineering of safety/mission critical systems
O  Software testing, evaluation and analysis technologies
O  Workflow - Computer Supported Cooperative Work (CSCW)
O  Project management issues
O  Distributed and parallel systems
O  Legal issues and standards
O  Automated software design
O  Real-time embedded software engineering
O  Automated software design and synthesis
O  Software security engineering
O  Theoretic approaches (formal methods, graph, ...)
O  Software, domain modeling and meta-modeling
O  Model driven engineering
O  Software maintenance
O  Reflection and metadata methodologies
O  AI approaches to software engineering
O  Component based software engineering
O  Software engineering standards and guidelines
O  Reports on intelligent CASE tools and eclipse plugins issues
O  Multimedia in software engineering
O  Usability engineering
O  Novel software tools and environments
O  Pervasive software engineering
O  Requirement engineering and processes
O  Critical and embedded software design
O  Service oriented software architecture
O  Software cost estimation
O  Web engineering and web-based applications
O  Human computer interaction and usability engineering
O  Model based software engineering
O  Aspect oriented software engineering
O  Agent oriented software engineering
O  Programming languages and compilers
O  Education and law
O  Case studies and emerging technologies
 
 
USEFUL WEB LINKS:
To see the DBLP list of accepted papers of SERP 2009, go to:
http://www.informatik.uni-trier.de/~ley/db/conf/serp/serp2009.html
The DBLP list of accepted papers of SERP 2010 will soon appear at:
http://www.informatik.uni-trier.de/~ley/db/conf/serp/serp2010.html
SERP 2011 URL:
http://www.world-academy-of-science.org/
 
 
IMPORTANT DATES:
 
March 10, 2011:    Submission of papers (about 5 to 7 pages)
April 03, 2011:    Notification of acceptance (+/- two days)
April 24, 2011:    Final papers + Copyright/Consent + Registration
July 18-21, 2011:  The 2011 International Conference on Software
   Engineering Research and Practice (SERP'11)
 
 
ACADEMIC CO-SPONSORS:
 
Currently being prepared - The Academic sponsors of the last offering
of SERP (2010) included research labs and centers affiliated
with (a partial list): University of California, Berkeley; University
of Southern California; University of Texas at Austin; Harvard
University, Cambridge, Massachusetts; Georgia Institute of Technology,
Georgia; Emory University, Georgia; University of Minnesota;
University of Iowa; University of North Dakota; NDSU-CIIT Green
Computing & Comm. Lab.; University of Siegen, Germany; UMIT, Austria;
SECLAB (University of Naples Federico II + University of Naples
Parthenope + Second University of Naples, Italy); National Institute
for Health Research; World Academy of Biomedical Sciences and
Technologies; Russian Academy of Sciences, Russia; International
Society of Intelligent Biological Medicine (ISIBM); The International
Council on Medical and Care Compunetics; Eastern Virginia Medical
School & the American College of Surgeons, USA.
 
 
SUBMISSION OF PAPERS:
 
Prospective authors are invited to submit their papers by uploading
them to the evaluation web site at:  http://world-comp.org
Submissions must be uploaded by March 10, 2011 and they must be
in either MS doc (but not docx) or pdf formats (about 5 to 7
pages - single space, font size of 10 to 12). All reasonable
typesetting formats are acceptable (later, the authors of accepted
papers will be asked to follow a particular typesetting format to
prepare their final pap

Re: [algogeeks] Re: difference x

2010-12-22 Thread Divya Jain
its okk

On 22 December 2010 22:28, Ankur Khurana  wrote:

> saurabh , asking for a better sol. is not a crime. rest everybody is
> intelligent.
>
> On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar 
> wrote:
> > @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which
> > r very basic.As u solved the looping prob in other thread I think u r
> > intelligent enough to solve this prob(difference x) easily and also
> > some other probs posted by u(not all).Some problems posted by u are
> > really very tricky and I loved them.I jst requested u while posting if
> > u review the ques carefully it will be helpful.I dint want to hurt
> > u.If u r I m sorry.Bt still I will request u to post carefully.Lets
> > finish this.And sorry once again.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> > For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Re: TopCoder Bad Neighbour

2010-12-22 Thread Amit Jaspal
Hi all,

I was trying this question and I got the jist of it I guess but still its
not getting accepted

Can anybody tell me what am I doing wrong??


int BadNeighbors::maxDonations(vector  d) {

int s=d.size();

if(s==1){
return d[0];
}

int i,j,k,ans1=0,ans2=0;
int dp1[10],dp2[10];
dp1[0]=d[0];
dp1[1]=d[1];

// Breaking the circular list into 2 linear lists.


// Processing the first list.
for(i=2;iwrote:

> Ok, I got the recurrence relation at
>
> http://www.topcoder.com/tc?module=Static&d1=match_editorials&d2=tccc04_online_rd_4
>
>
> Mohit
>
>
>
> On Wed, Dec 22, 2010 at 8:33 PM, mohit ranjan wrote:
>
>> Hi All,
>>
>> Can anybody help me with some hint for
>> http://www.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009
>>
>>
>> Mohit
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Amit Jaspal
Btech IT IIIT- Allahabad

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread Divya Jain
@ saurabh
and i wanna ur solution to this prob
i know O(nlogn) post ur O(n) solution,.
i hv some idea bt i wanna knw ur ans b4 mine

On 22 December 2010 22:32, Divya Jain  wrote:

> its okk
>
>
> On 22 December 2010 22:28, Ankur Khurana  wrote:
>
>> saurabh , asking for a better sol. is not a crime. rest everybody is
>> intelligent.
>>
>> On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar 
>> wrote:
>> > @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which
>> > r very basic.As u solved the looping prob in other thread I think u r
>> > intelligent enough to solve this prob(difference x) easily and also
>> > some other probs posted by u(not all).Some problems posted by u are
>> > really very tricky and I loved them.I jst requested u while posting if
>> > u review the ques carefully it will be helpful.I dint want to hurt
>> > u.If u r I m sorry.Bt still I will request u to post carefully.Lets
>> > finish this.And sorry once again.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> > To post to this group, send email to algoge...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> > For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>

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



[algogeeks] Re: Amazon Interview Question about Linked Lists

2010-12-22 Thread siva viknesh
oh thank u :)

On Dec 22, 11:20 am, bittu  wrote:
> Xcellent Shiva..keep goin on..\
>
> Best Regards
> Shashank Mani Narayan
> BIT Mesra

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



[algogeeks] Re: difference x

2010-12-22 Thread Minotauraus
Also a general FYI, please, please, please search before you post.
Seeing the same Qs again and again for regulars isn't very interesting
either.


On Dec 22, 11:29 am, bhupendra dubey  wrote:
> @juver:thanx  for making me work... please notice this
> this also uses the sorted property of the array
>
>  i=0,j=1;
> while((i!=n-1) or  j!=n)
> {
> /*compare difference of a[j] and a[i]*/
> if( (a[j]-[a[i]])>x )
> i++;
> else if( (a[j]-a[i]) j++;
> else
> {
> /*SOLUTION*/
> return;
>
> }
> }
>
> regards
>
> complexity:O(n)
>
> On Thu, Dec 23, 2010 at 12:29 AM, juver++  wrote:
> > Your solution needs extra space and it has only *expected* O(n) time.
> > There is O(n) inplace solution
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> bhupendra dubey

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread yq Zhang
@bhupendra
Nice solution!

Yq

On Wed, Dec 22, 2010 at 11:29 AM, bhupendra dubey
wrote:

> @juver:thanx  for making me work... please notice this
> this also uses the sorted property of the array
>
>  i=0,j=1;
> while((i!=n-1) or  j!=n)
> {
> /*compare difference of a[j] and a[i]*/
> if( (a[j]-[a[i]])>x )
> i++;
> else if( (a[j]-a[i]) j++;
> else
> {
> /*SOLUTION*/
> return;
> }
> }
>
> regards
>
> complexity:O(n)
>
> On Thu, Dec 23, 2010 at 12:29 AM, juver++  wrote:
>
>> Your solution needs extra space and it has only *expected* O(n) time.
>> There is O(n) inplace solution
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> bhupendra dubey
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] how to delete a substring from a given string.???

2010-12-22 Thread Ajay Kumar
i dont noe the logic..help!!!

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



Re: [algogeeks] Re: 1s and 0s

2010-12-22 Thread juver++
Problem mentioned by @investmentsupergro...@googlegroups.com is not 
connected with the original problem.

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



Re: [algogeeks] Re: 1s and 0s

2010-12-22 Thread Carl Barton
This is simply a decision problem is it not?
the above sorting would require n log n for comparison sorting where as a
decision could be simply done in linear time and space.
Please correct me if i'm wrong


On 22 December 2010 19:17, Anand  wrote:

>
> http://anandtechblog.blogspot.com/2010/12/sort-array-containing-1s-and-0s.html
>
>
> On Wed, Dec 22, 2010 at 6:47 AM, Carl Barton 
> wrote:
>
>> Could be modelled as a deterministic finite statemachine to be checked in
>> linear time.
>>
>>
>>
>> On 22 December 2010 07:47, snehal jain  wrote:
>>
>>> @above
>>> nice approach :)
>>>
>>>
>>> On Wed, Dec 22, 2010 at 1:06 PM, juver++  wrote:
>>>
 Use bits manipulation tricks.
 1. There is a way to remove a group of consecutive 1's from the right: A
 = n & (n + 1). Then check if A==0 then OK.
 2. Second approach: B=n+1, check if B & (B-1) (this checks if B is a
 power of 2, so it contains only 1 set bit) is zero then OK.

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

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

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread bhupendra dubey
@juver:thanx  for making me work... please notice this
this also uses the sorted property of the array

 i=0,j=1;
while((i!=n-1) or  j!=n)
{
/*compare difference of a[j] and a[i]*/
if( (a[j]-[a[i]])>x )
i++;
else if( (a[j]-a[i]) wrote:

> Your solution needs extra space and it has only *expected* O(n) time.
> There is O(n) inplace solution
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
bhupendra dubey

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



Re: [algogeeks] Re: array partition

2010-12-22 Thread Anand
http://anandtechblog.blogspot.com/2010/07/partition-of-array.html

On Wed, Dec 22, 2010 at 7:14 AM, rajessge...@yahoo.com <
rajessge...@yahoo.com> wrote:

> sort the array and from the last elements of the array, put element
> i(last) in set A and i-1 in set B,
> now for the i-2 th element put this element in the set whichever has
> lesser sum of elements in both sets and continue this till the least
> element
>
>
> On Dec 22, 7:09 am, Devil Wang  wrote:
> > *Hi,*
> > *
> > *
> > *I wonder that if the element of the array contains negative integer?
> > *
> >
> > On Wed, Dec 22, 2010 at 1:25 AM, snehal jain 
> wrote:
> > > There is an array, how will you partition that into two parts so that
> > > the sum of both the sub set is minimum
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algoge...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com
> 
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --
> >
> > **
> > *
> >
> > Best Regards,
> >
> > Devil Wang
> >
> > *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Re: 1s and 0s

2010-12-22 Thread Anand
http://anandtechblog.blogspot.com/2010/12/sort-array-containing-1s-and-0s.html

On Wed, Dec 22, 2010 at 6:47 AM, Carl Barton wrote:

> Could be modelled as a deterministic finite statemachine to be checked in
> linear time.
>
>
>
> On 22 December 2010 07:47, snehal jain  wrote:
>
>> @above
>> nice approach :)
>>
>>
>> On Wed, Dec 22, 2010 at 1:06 PM, juver++  wrote:
>>
>>> Use bits manipulation tricks.
>>> 1. There is a way to remove a group of consecutive 1's from the right: A
>>> = n & (n + 1). Then check if A==0 then OK.
>>> 2. Second approach: B=n+1, check if B & (B-1) (this checks if B is a
>>> power of 2, so it contains only 1 set bit) is zero then OK.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: sort

2010-12-22 Thread Dave
Assuming that you mean that you have an array of size 1000 that you
can use as temporary storage, use it as a bit array. Based on the size
of the input numbers, the word size is at least 15 bits, so you have
at least 15,000 bits to use. If the word size is such that you have at
least 20,000 bits, then read through the data one item at a time,
setting the corresponding bit in the bit array. After completing the
input, scan the bit array in order and output the numbers. If you have
less than 20,000 bits, then read through the data twice, first marking
the bits for items between 0 and 14,999. After outputting those
numbers, read the input again, setting bit i-15,000 for every number
between 15,000 and 19,999.

Dave

On Dec 21, 11:56 pm, snehal jain  wrote:
> Given an array having 16000 unique integers, each lying within the
> range 1<2, how do u sort it. U can load only 1000 numbers at a
> time in memory

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread juver++
Your solution needs extra space and it has only *expected* O(n) time. There 
is O(n) inplace solution

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



[algogeeks] Re: median

2010-12-22 Thread Dave
Have you googled "parallel median algorithm"?

Dave

On Dec 22, 12:04 am, snehal jain  wrote:
> You have n machines contains n integer. How will you find the median
> of n^2 element. Only 2n number can be loaded in the memory

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread bhupendra dubey
send the data set to the hash table
now search for a[i]+x in the table if found for 'k' den a[k] and a[k]+x is
the required pair

complexity:
o(n)(for mapping)+O(n)(for search a[i]+x)=O(n)

@Snehal can i see your solution please.

On Thu, Dec 23, 2010 at 12:11 AM, Aviral Gupta  wrote:

> use hash map.O(n)
> or you can use use the binary search for each element
> O(nlogn) 
>
> Regards
> Aviral
> http://coders-stop.blogspot.com
>
> On Dec 22, 3:05 pm, snehal jain  wrote:
> > How will you find the pair from an sorted array whose difference is x
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
bhupendra dubey

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



[algogeeks] Re: difference x

2010-12-22 Thread Aviral Gupta
use hash map.O(n)
or you can use use the binary search for each element
O(nlogn) 

Regards
Aviral
http://coders-stop.blogspot.com

On Dec 22, 3:05 pm, snehal jain  wrote:
> How will you find the pair from an sorted array whose difference is x

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread rajat ahuja
saurabh .. i would like to know your solution
can u please tell me ,, i want to know

On Wed, Dec 22, 2010 at 11:50 PM, juver++  wrote:

> Please don't use abbreviated words in your posts. Speak in pure English.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread juver++
Please don't use abbreviated words in your posts. Speak in pure English.

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



[algogeeks] matrix row column

2010-12-22 Thread MAC
you have a matrix containing integers (no range provided). The matrix is
randomly populated with integers. We need to devise an algorithm where by we
find a row number which matches exactly with a column within the matrix. We
need to return the row number and the column number for the match. The order
of of the matching elements is the same. For example, If, i'th row matches
with j'th column, and i'th row contains the elements - [1,4,5,6,3]. Then jth
column would also contain the elements - [1,4,5,6,3]. Given an n x n matrix
.


-- 
thanks
--mac

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



Re: [algogeeks] Valid subsets

2010-12-22 Thread bhupendra dubey
iam sorry but the problem statment is not clear to me.
how am i supposed to use exclusion rules
some more examples please.

On Wed, Dec 22, 2010 at 8:34 PM, Prims  wrote:

> given a set of distinct integers {a1, a2, a3, a4, a5, ...}
> and a set of exclusion rules: R = {{a1, a3}, {a2, a4, a10}, ...}
> can you print out all the valid subsets?
> Example:
> what is a valid subset? {a1, a4}
> what is an invalid subset? {a1, a2, a4}
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
bhupendra dubey

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread snehal jain
@ saurabh
its fine..
nd can u plz tell ur soln to this prob.. i hv figured out an O(n) solution..
bt b4 dat i wanna knw ur solution..


On Wed, Dec 22, 2010 at 10:31 PM, rajat ahuja wrote:

> nyone like to post solution of ths problem,
>
> On Wed, Dec 22, 2010 at 10:28 PM, Ankur Khurana 
> wrote:
>
>> saurabh , asking for a better sol. is not a crime. rest everybody is
>> intelligent.
>>
>> On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar 
>> wrote:
>> > @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which
>> > r very basic.As u solved the looping prob in other thread I think u r
>> > intelligent enough to solve this prob(difference x) easily and also
>> > some other probs posted by u(not all).Some problems posted by u are
>> > really very tricky and I loved them.I jst requested u while posting if
>> > u review the ques carefully it will be helpful.I dint want to hurt
>> > u.If u r I m sorry.Bt still I will request u to post carefully.Lets
>> > finish this.And sorry once again.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> > To post to this group, send email to algoge...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> > For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Find The Looping Node

2010-12-22 Thread rahul
@sneha...

WOW we should hang out...:-)

On Wed, Dec 22, 2010 at 9:56 PM, snehal jain  wrote:

> @ above
>
> well this a ver old and easy problem.. but unlike u, criticizing others wen
> u knw the solution i wud rather post my solution..
>
> int removeCycle(list head)
> {
>
>   struct listnode * slow, *fast,*slow;
>   slow=fast=head;
>  do
>{
>if(!fast || ! fast->next) rteurn -1;
>slow=slow->next;
> fast=fast->next->next;
> } while(slow!=fast);
>
> slow1=head;
>  while( slow1!=slow)
> {
> prev=slow;
> slow=slow->next;
> slow1=slow1->next;
>
> }
>
> prev->next=null;
> return 1;
> }
>
>
> well this is the code for solving ur prob.. but i hv nt attached y this
> works.. i hope u ll work out on this.. rather than having spoon feeding..
> still if u cant work out, u can ask it.. i would love to answer and explain
> to a genius (/ or the person who considers himself genius and the one who
> considers others doubts as homework problem and his own doubts as a big
> tricky problem although it is too old and common problem :P).
>
>
>
> On Wed, Dec 22, 2010 at 9:11 PM, Saurabh Koar wrote:
>
>> Finding whether a loop exists or not in a linked list, is a very
>> familiar problem.But I want an algorithm that will find the node that
>> is causing the loop.
>> Well,I have an approach.Start from the head.Copy its data into an
>> array.Mark node's data as infinity.Move to the next node.When u find
>> node->next->data=infinity u will say that the current node is causing
>> the loop.Then restore the data of the linked list from the array.But I
>> think more optimized algorithm is possible.Reply if you know more
>> optimized way.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread rajat ahuja
nyone like to post solution of ths problem,

On Wed, Dec 22, 2010 at 10:28 PM, Ankur Khurana wrote:

> saurabh , asking for a better sol. is not a crime. rest everybody is
> intelligent.
>
> On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar 
> wrote:
> > @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which
> > r very basic.As u solved the looping prob in other thread I think u r
> > intelligent enough to solve this prob(difference x) easily and also
> > some other probs posted by u(not all).Some problems posted by u are
> > really very tricky and I loved them.I jst requested u while posting if
> > u review the ques carefully it will be helpful.I dint want to hurt
> > u.If u r I m sorry.Bt still I will request u to post carefully.Lets
> > finish this.And sorry once again.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> > For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread Ankur Khurana
saurabh , asking for a better sol. is not a crime. rest everybody is
intelligent.

On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar  wrote:
> @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which
> r very basic.As u solved the looping prob in other thread I think u r
> intelligent enough to solve this prob(difference x) easily and also
> some other probs posted by u(not all).Some problems posted by u are
> really very tricky and I loved them.I jst requested u while posting if
> u review the ques carefully it will be helpful.I dint want to hurt
> u.If u r I m sorry.Bt still I will request u to post carefully.Lets
> finish this.And sorry once again.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to 
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread Ankur Khurana
ya i agree , your questions are good though.

On Wed, Dec 22, 2010 at 10:19 PM, snehal jain  wrote:
> @ankur..
>
> its ok if u r asking for approach.. i ll do it from next tym.. bt posting in
> bulk is not an offence.. i bet u dont the solution to all my problems.. some
> of them u mite know some of them mite b new for u.. well same here u mite
> ask a prob and i mite find it easy.. i posted these problem cz i wanted to
> discuss it.. y wud i flood the group with question? ( i dont enjoy dat) i
> just posted all my doubts in one go.. as i had finishd many blogs n sites
> recently.
>
> On Wed, Dec 22, 2010 at 10:04 PM, Ankur Khurana 
> wrote:
>>
>> @snehal : nothing wrong in what saurabh said. it was just that if you
>> are posting a question , then you should also post the approach you
>> have thought.plus you are posting in bulk . so , please whenever you
>> give a question , also mention your approach. it gives greater
>> confidence in question to be solved.
>>
>> On Wed, Dec 22, 2010 at 9:35 PM, snehal jain 
>> wrote:
>> > @saurabh
>> >
>> > u might be a genius bt for ur kind information this is the group for
>> > learners... this group is a place where people come to learn new tricks,
>> > put
>> > their ideas and ask doubts.. so it would have been better if u had put
>> > your
>> > response rather than discouraging anyone from asking doubts..
>> > while putting this problem i had the nlogn approach in my mind as
>> > pointed by
>> > vivek. but i wanted a better approach O(n) as it exist for the sum
>> > problem
>> > where sum=x. so i posted it here.. it does not mean if u know a solution
>> > than the problem is   solved. there is always a chance of optimization
>> > which
>> > u can learn only by discussing...
>> > u could simply delete mail if u find it so simple..
>> > and everybody has his own style.. now a days i was solving algorithm
>> > problems from various blogs and sites so i posted all my doubts in one
>> > go...
>> >
>> > On Wed, Dec 22, 2010 at 7:44 PM, Saurabh Koar 
>> > wrote:
>> >>
>> >> @Snehal:
>> >>
>> >> U r going crazy man.U r blindly picking up problems and throwing them
>> >> in this group.It is not a place solving ur homework problems.Plz post
>> >> problems which r either tricky so that the members can learn something
>> >> or post problems which u cant solve after giving a measurable
>> >> effort.Try to use ur minimum intelligence to solve a
>> >> problem.Otherwise(as pointed out by Swapnil some days ago) it really
>> >> decreases the value of this group.More people will be active if they
>> >> see new thought provoking problems.Also, u post problems and don't
>> >> clear doubts of the members regarding ur problems.This is also bad
>> >> habit.
>> >>
>> >> Hope u will understand.No offence intended.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Algorithm Geeks" group.
>> >> To post to this group, send email to algoge...@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algoge...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread Saurabh Koar
@Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which
r very basic.As u solved the looping prob in other thread I think u r
intelligent enough to solve this prob(difference x) easily and also
some other probs posted by u(not all).Some problems posted by u are
really very tricky and I loved them.I jst requested u while posting if
u review the ques carefully it will be helpful.I dint want to hurt
u.If u r I m sorry.Bt still I will request u to post carefully.Lets
finish this.And sorry once again.

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread snehal jain
@ankur..

its ok if u r asking for approach.. i ll do it from next tym.. bt posting in
bulk is not an offence.. i bet u dont the solution to all my problems.. some
of them u mite know some of them mite b new for u.. well same here u mite
ask a prob and i mite find it easy.. i posted these problem cz i wanted to
discuss it.. y wud i flood the group with question? ( i dont enjoy dat) i
just posted all my doubts in one go.. as i had finishd many blogs n sites
recently.

On Wed, Dec 22, 2010 at 10:04 PM, Ankur Khurana wrote:

> @snehal : nothing wrong in what saurabh said. it was just that if you
> are posting a question , then you should also post the approach you
> have thought.plus you are posting in bulk . so , please whenever you
> give a question , also mention your approach. it gives greater
> confidence in question to be solved.
>
> On Wed, Dec 22, 2010 at 9:35 PM, snehal jain 
> wrote:
> > @saurabh
> >
> > u might be a genius bt for ur kind information this is the group for
> > learners... this group is a place where people come to learn new tricks,
> put
> > their ideas and ask doubts.. so it would have been better if u had put
> your
> > response rather than discouraging anyone from asking doubts..
> > while putting this problem i had the nlogn approach in my mind as pointed
> by
> > vivek. but i wanted a better approach O(n) as it exist for the sum
> problem
> > where sum=x. so i posted it here.. it does not mean if u know a solution
> > than the problem is   solved. there is always a chance of optimization
> which
> > u can learn only by discussing...
> > u could simply delete mail if u find it so simple..
> > and everybody has his own style.. now a days i was solving algorithm
> > problems from various blogs and sites so i posted all my doubts in one
> go...
> >
> > On Wed, Dec 22, 2010 at 7:44 PM, Saurabh Koar 
> > wrote:
> >>
> >> @Snehal:
> >>
> >> U r going crazy man.U r blindly picking up problems and throwing them
> >> in this group.It is not a place solving ur homework problems.Plz post
> >> problems which r either tricky so that the members can learn something
> >> or post problems which u cant solve after giving a measurable
> >> effort.Try to use ur minimum intelligence to solve a
> >> problem.Otherwise(as pointed out by Swapnil some days ago) it really
> >> decreases the value of this group.More people will be active if they
> >> see new thought provoking problems.Also, u post problems and don't
> >> clear doubts of the members regarding ur problems.This is also bad
> >> habit.
> >>
> >> Hope u will understand.No offence intended.
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algoge...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com
> .
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com
> .
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Find The Looping Node

2010-12-22 Thread rajat ahuja
awesummm reply :)

On Wed, Dec 22, 2010 at 9:56 PM, snehal jain  wrote:

> @ above
>
> well this a ver old and easy problem.. but unlike u, criticizing others wen
> u knw the solution i wud rather post my solution..
>
> int removeCycle(list head)
> {
>
>   struct listnode * slow, *fast,*slow;
>   slow=fast=head;
>  do
>{
>if(!fast || ! fast->next) rteurn -1;
>slow=slow->next;
> fast=fast->next->next;
> } while(slow!=fast);
>
> slow1=head;
>  while( slow1!=slow)
> {
> prev=slow;
> slow=slow->next;
> slow1=slow1->next;
>
> }
>
> prev->next=null;
> return 1;
> }
>
>
> well this is the code for solving ur prob.. but i hv nt attached y this
> works.. i hope u ll work out on this.. rather than having spoon feeding..
> still if u cant work out, u can ask it.. i would love to answer and explain
> to a genius (/ or the person who considers himself genius and the one who
> considers others doubts as homework problem and his own doubts as a big
> tricky problem although it is too old and common problem :P).
>
>
>
> On Wed, Dec 22, 2010 at 9:11 PM, Saurabh Koar wrote:
>
>> Finding whether a loop exists or not in a linked list, is a very
>> familiar problem.But I want an algorithm that will find the node that
>> is causing the loop.
>> Well,I have an approach.Start from the head.Copy its data into an
>> array.Mark node's data as infinity.Move to the next node.When u find
>> node->next->data=infinity u will say that the current node is causing
>> the loop.Then restore the data of the linked list from the array.But I
>> think more optimized algorithm is possible.Reply if you know more
>> optimized way.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread Ankur Khurana
@snehal : nothing wrong in what saurabh said. it was just that if you
are posting a question , then you should also post the approach you
have thought.plus you are posting in bulk . so , please whenever you
give a question , also mention your approach. it gives greater
confidence in question to be solved.

On Wed, Dec 22, 2010 at 9:35 PM, snehal jain  wrote:
> @saurabh
>
> u might be a genius bt for ur kind information this is the group for
> learners... this group is a place where people come to learn new tricks, put
> their ideas and ask doubts.. so it would have been better if u had put your
> response rather than discouraging anyone from asking doubts..
> while putting this problem i had the nlogn approach in my mind as pointed by
> vivek. but i wanted a better approach O(n) as it exist for the sum problem
> where sum=x. so i posted it here.. it does not mean if u know a solution
> than the problem is   solved. there is always a chance of optimization which
> u can learn only by discussing...
> u could simply delete mail if u find it so simple..
> and everybody has his own style.. now a days i was solving algorithm
> problems from various blogs and sites so i posted all my doubts in one go...
>
> On Wed, Dec 22, 2010 at 7:44 PM, Saurabh Koar 
> wrote:
>>
>> @Snehal:
>>
>> U r going crazy man.U r blindly picking up problems and throwing them
>> in this group.It is not a place solving ur homework problems.Plz post
>> problems which r either tricky so that the members can learn something
>> or post problems which u cant solve after giving a measurable
>> effort.Try to use ur minimum intelligence to solve a
>> problem.Otherwise(as pointed out by Swapnil some days ago) it really
>> decreases the value of this group.More people will be active if they
>> see new thought provoking problems.Also, u post problems and don't
>> clear doubts of the members regarding ur problems.This is also bad
>> habit.
>>
>> Hope u will understand.No offence intended.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Find The Looping Node

2010-12-22 Thread snehal jain
@ above

well this a ver old and easy problem.. but unlike u, criticizing others wen
u knw the solution i wud rather post my solution..

int removeCycle(list head)
{

  struct listnode * slow, *fast,*slow;
  slow=fast=head;
 do
   {
   if(!fast || ! fast->next) rteurn -1;
   slow=slow->next;
fast=fast->next->next;
} while(slow!=fast);

slow1=head;
 while( slow1!=slow)
{
prev=slow;
slow=slow->next;
slow1=slow1->next;

}

prev->next=null;
return 1;
}


well this is the code for solving ur prob.. but i hv nt attached y this
works.. i hope u ll work out on this.. rather than having spoon feeding..
still if u cant work out, u can ask it.. i would love to answer and explain
to a genius (/ or the person who considers himself genius and the one who
considers others doubts as homework problem and his own doubts as a big
tricky problem although it is too old and common problem :P).


On Wed, Dec 22, 2010 at 9:11 PM, Saurabh Koar wrote:

> Finding whether a loop exists or not in a linked list, is a very
> familiar problem.But I want an algorithm that will find the node that
> is causing the loop.
> Well,I have an approach.Start from the head.Copy its data into an
> array.Mark node's data as infinity.Move to the next node.When u find
> node->next->data=infinity u will say that the current node is causing
> the loop.Then restore the data of the linked list from the array.But I
> think more optimized algorithm is possible.Reply if you know more
> optimized way.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread snehal jain
@saurabh

u might be a genius bt for ur kind information this is the group for
learners... this group is a place where people come to learn new tricks, put
their ideas and ask doubts.. so it would have been better if u had put your
response rather than discouraging anyone from asking doubts..
while putting this problem i had the nlogn approach in my mind as pointed by
vivek. but i wanted a better approach O(n) as it exist for the sum problem
where sum=x. so i posted it here.. it does not mean if u know a solution
than the problem is   solved. there is always a chance of optimization which
u can learn only by discussing...
u could simply delete mail if u find it so simple..
and everybody has his own style.. now a days i was solving algorithm
problems from various blogs and sites so i posted all my doubts in one go...

On Wed, Dec 22, 2010 at 7:44 PM, Saurabh Koar wrote:

> @Snehal:
>
> U r going crazy man.U r blindly picking up problems and throwing them
> in this group.It is not a place solving ur homework problems.Plz post
> problems which r either tricky so that the members can learn something
> or post problems which u cant solve after giving a measurable
> effort.Try to use ur minimum intelligence to solve a
> problem.Otherwise(as pointed out by Swapnil some days ago) it really
> decreases the value of this group.More people will be active if they
> see new thought provoking problems.Also, u post problems and don't
> clear doubts of the members regarding ur problems.This is also bad
> habit.
>
> Hope u will understand.No offence intended.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] Find The Looping Node

2010-12-22 Thread Saurabh Koar
Finding whether a loop exists or not in a linked list, is a very
familiar problem.But I want an algorithm that will find the node that
is causing the loop.
Well,I have an approach.Start from the head.Copy its data into an
array.Mark node's data as infinity.Move to the next node.When u find
node->next->data=infinity u will say that the current node is causing
the loop.Then restore the data of the linked list from the array.But I
think more optimized algorithm is possible.Reply if you know more
optimized way.

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



Re: [algogeeks] Re: spy in the city

2010-12-22 Thread Terence

I second Bhavesh.

If A knows B, then B is not a spy; else A is not a spy.
Thus we can hold an elimination races:
 for each pair A,B in a match, ask if A knows B, and eliminate as 
above.

In total N-1 matches are needed to decide the final winner.
If there is a spy, then the spy is the winner.
Otherwise, Another 2N-2 queries are needed to check if the winner is a spy.
(or 2N-2-logN, making use of the results of previous matches)



On 2010-12-21 22:39, janak wrote:

O(N) if everybody knows everybody.
O(N^2) if there is no such condition. (i.e. Ask for each person to 
everybody.)



On Mon, Dec 20, 2010 at 9:43 PM, Bhavesh Chauhan 
mailto:chauhan.bhave...@gmail.com>> wrote:


Every question can eliminate 1 person so you can identify the spy
in N-1 questions.

Bhavesh



On 19 December 2010 23:46, Dave mailto:dave_and_da...@juno.com>> wrote:

Here is an algorithm:

spy = 1
for i = 2 to N do
   if person[spy] knows person[i]
   then person[i] is not the spy.
   else if person[i] knows person[spy]
   then person[spy] is not the spy, set spy = i
   end if
end for
for i = 1 to spy-1 do
   if (person[spy] does not know person[i]) or (person[i] knows
person[spy])
   then there is no spy, set spy = undefined, break
   end if
end for

If there is a spy, you find him in at least 2*N - 2 questions
and at
most 4*N - 4 questions.

Dave

On Dec 19, 8:01 am, snehal jain mailto:learner@gmail.com>> wrote:
> There is a city of N people. The government learnt that some
> unfriendly nation planted a spy there. A spy possesses unique
> characteristics: he knows everybody in the city, but nobody
knows him.
>
> You are a counteragent sent by the government to catch the
spy. You
> may ask the people in the city only one question: "Do you
know the
> person X?" You may ask as many people as you wish, and one
person may
> be asked as many times as you wish. All the people,
including the spy,
> always answer honestly.
>
> How many questions you need to find out who is the spy?

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


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



[algogeeks] TopCoder Bad Neighbour

2010-12-22 Thread mohit ranjan
Hi All,

Can anybody help me with some hint for
http://www.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009


Mohit

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



Re: [algogeeks] Find the element with more than n/k occurrences

2010-12-22 Thread Nikhil Agarwal
@saurabh : This solution is applicaiton to some special K .Not in
general .sorry.

On 12/22/10, Saurabh Koar  wrote:
> @Nikhil: What if the array is 1 2 3 4 9 6 6 6 5 and k=3 ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Thanks & Regards
Nikhil Agarwal
Senior Undergraduate
Computer Science & Engineering,
National Institute Of Technology, Durgapur,India
http://tech-nikk.blogspot.com
http://beta.freshersworld.com/communities/nitd

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



[algogeeks] Re: TopCoder Bad Neighbour

2010-12-22 Thread mohit ranjan
Ok, I got the recurrence relation at
http://www.topcoder.com/tc?module=Static&d1=match_editorials&d2=tccc04_online_rd_4


Mohit


On Wed, Dec 22, 2010 at 8:33 PM, mohit ranjan wrote:

> Hi All,
>
> Can anybody help me with some hint for
> http://www.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009
>
>
> Mohit
>
>

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



Re: [algogeeks] bits groups

2010-12-22 Thread Terence

@Saurabh:
You are right. I was supposed there were infinite 0's on the left.
For 32-bit number, the MSB should also be checked in  addition to LSB.
Change the first line to:  c=1-(N&1)-((N>>31)&1); will fix this case.


On 2010-12-22 14:44, Saurabh Koar wrote:

@Terence: I think the above fails for 0X.Correct me if I m wrong.



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



Re: [algogeeks] Re: Minimum Triplet Distance

2010-12-22 Thread Priyanka Chatterjee
@SOURABH:As explained correctly by *Yq* ,it's a greedy approach., when u
find the min(x,y,z) and take with difference with max(x,y,z) to find the
triplet distance, you see that if you consider that min(x,y,z) with other
tuples of the other two variables , the max difference either remains same
or increases as the arrays are sorted in nondecreasing order. As you are
asked to find the minimum of such max difference(triplet distance) ,, its
meaningless to find out the triplet difference >= current triplet
difference. So to discard that path we increment the index of smallest
variable by one.

@Nikhil/Swapnil: No point discussing O(1) . It's never possible better than
O(n1+n2+n3).

On 21 December 2010 02:10, Saurabh Koar  wrote:

> @yq: Can u plzz inform what was ur approach/logic while deriving the
> condition that "index will be increased of that array which contains
> minimum of three elements to get the desired ans"?
> It will be very helpful.Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Thanks & Regards,
Priyanka Chatterjee
Final Year Undergraduate Student,
Computer Science & Engineering,
National Institute Of Technology,Durgapur
India
http://priyanka-nit.blogspot.com/

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



[algogeeks] Re: number

2010-12-22 Thread tamilhere
#include
using namespace std;
int main()
{
  string src;
  cin>>src;
  reverse(src.begin(),src.end());
  src.insert(src.begin()+3,',');
  reverse(src.begin(),src.end());
  cout

[algogeeks] Re: array partition

2010-12-22 Thread rajessge...@yahoo.com
sort the array and from the last elements of the array, put element
i(last) in set A and i-1 in set B,
now for the i-2 th element put this element in the set whichever has
lesser sum of elements in both sets and continue this till the least
element


On Dec 22, 7:09 am, Devil Wang  wrote:
> *Hi,*
> *
> *
> *I wonder that if the element of the array contains negative integer?
> *
>
> On Wed, Dec 22, 2010 at 1:25 AM, snehal jain  wrote:
> > There is an array, how will you partition that into two parts so that
> > the sum of both the sub set is minimum
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
>
> **
> *
>
> Best Regards,
>
> Devil Wang
>
> *

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



[algogeeks] Valid subsets

2010-12-22 Thread Prims
given a set of distinct integers {a1, a2, a3, a4, a5, ...}
and a set of exclusion rules: R = {{a1, a3}, {a2, a4, a10}, ...}
can you print out all the valid subsets?
Example:
what is a valid subset? {a1, a4}
what is an invalid subset? {a1, a2, a4}

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



Re: [algogeeks] Re: N companies merge

2010-12-22 Thread Saurabh Koar
@Prims:Only 2 companies are involved in merging?? Or a merger may
cover more than two companies??

If a merger can involve more than two companies then the ans is I
think ((2^N)-1)-N

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



Re: [algogeeks] Re: 1s and 0s

2010-12-22 Thread Carl Barton
Could be modelled as a deterministic finite statemachine to be checked in
linear time.


On 22 December 2010 07:47, snehal jain  wrote:

> @above
> nice approach :)
>
>
> On Wed, Dec 22, 2010 at 1:06 PM, juver++  wrote:
>
>> Use bits manipulation tricks.
>> 1. There is a way to remove a group of consecutive 1's from the right: A =
>> n & (n + 1). Then check if A==0 then OK.
>> 2. Second approach: B=n+1, check if B & (B-1) (this checks if B is a power
>> of 2, so it contains only 1 set bit) is zero then OK.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: difference x

2010-12-22 Thread Saurabh Koar
@Snehal:

U r going crazy man.U r blindly picking up problems and throwing them
in this group.It is not a place solving ur homework problems.Plz post
problems which r either tricky so that the members can learn something
or post problems which u cant solve after giving a measurable
effort.Try to use ur minimum intelligence to solve a
problem.Otherwise(as pointed out by Swapnil some days ago) it really
decreases the value of this group.More people will be active if they
see new thought provoking problems.Also, u post problems and don't
clear doubts of the members regarding ur problems.This is also bad
habit.

Hope u will understand.No offence intended.

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



[algogeeks] Re: difference x

2010-12-22 Thread juver++
There is simple solution of the similar problem: given sorted array, find 
two values which sum up to X.
It can be solved with two pointers, such approach has been discussed on the 
forum some months ago.

Your problem is similar.

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



Re: [algogeeks] difference x

2010-12-22 Thread VIVEK RAMAMURTHY
for each element i,implement binary search to find the position of i+x..
this will take o(n log n)
correct me if i m wrong

On Wed, Dec 22, 2010 at 3:35 PM, snehal jain  wrote:

> How will you find the pair from an sorted array whose difference is x
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] difference x

2010-12-22 Thread snehal jain
How will you find the pair from an sorted array whose difference is x

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



Re: [algogeeks] palindrome

2010-12-22 Thread Azhar Hussain
Hi,

   Here is the simple solution

unsigned int r = v; // r will be reversed bits of v; first get LSB of v
int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end

 for (v >>= 1; v; v >>= 1)
 {
  r <<= 1;
  r |= v & 1;
  s--;
 }
r <<= s; // shift when v's highest bits are zero
if (v == r)
  printf("palindrome\n");
else
  printf("not a palindrome\n");


source and more optimized versions
http://www-graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious

-
Azhar.



On Wed, Dec 22, 2010 at 2:09 PM, pacific pacific wrote:

>
>
> On Wed, Dec 22, 2010 at 12:11 PM, mo...@ismu  wrote:
>
>>
>>
>> if x is a  32 bit number
>> if((x&0x)==((x>>16)&0x)))
>>x's  bit pattern is a polyndrome
>>
>> @snehal :Do you want to consider binary representation of 5 as 101 or
> ..0101 ?
> --
>
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] palindrome

2010-12-22 Thread pacific pacific
On Wed, Dec 22, 2010 at 12:11 PM, mo...@ismu  wrote:

>
>
> if x is a  32 bit number
> if((x&0x)==((x>>16)&0x)))
>x's  bit pattern is a polyndrome
>
> @snehal :Do you want to consider binary representation of 5 as 101 or
..0101 ?
-- 

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

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