Re: [algogeeks] Re: Number problem

2010-09-21 Thread saurabh agrawal
@dave:
your code is producing 4526 for input=24526 instead of 2456
Here's corrected code :)
/CODE///
int function(int n){
int a[10]={0},temp=0,result =0;
while(n){   //reverse the number..
 temp=10*temp+n%10;
 n/=10;
}
n=temp;
while(n){   ///remove duplicate digits...
 if(a[n%10]==0){
 a[n%10]=1;
 result=10*result+n%10;
 }
n/=10;
}
return result;
}
///END/
On Wed, Sep 22, 2010 at 8:51 AM, Dave  wrote:

> @Saurabh: Doesn't your code turn 123 into 321? Try this:
>
> int function(int n)
> {
>int a[10]={0};
>int result=0;
> int place=1;
> while(n){
>if(a[n%10]==0){
>a[n%10]=1;
> result+=(n%10)*place;
>place*=10;
>}
>n/=10;
>}
>return result;
> }
>
>
> Dave
>
> On Sep 21, 3:12 pm, saurabh agrawal  wrote:
> > int function(int n){
> >
> > int a[10]={0};
> > int result =0;
> > while(n){
> > if(a[n%10]==0){
> > a[n%10]=1;
> > result=10*result+n%10;
> > }
> > n/=10;}
> >
> > return result;`
> >
> >
> >
> > }
> > On Wed, Sep 22, 2010 at 12:39 AM, Albert 
> wrote:
> > > Given a number find the number by eliminating the duplicate digits in
> > > the number..
> >
> > > for eg:   24526  ans is 2456
> > > .
> >
> > > int function(int n)
> > > {
> >
> > >  .
> > >  .
> > >  .
> >
> > > }
> >
> > > Give all sort of solutions to this problem.
> >
> > > Efficiency in the code is important 
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algoge...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com
> 
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] ALgo help pls

2010-09-21 Thread pre
Hi all,
pls help me solve this problem..
Design an algorithm to find the majority element of an array..
majority element must be an element tht has the cardinality greater
than 2n/3 where n is the number of elements in the array and the time
complexity must be a linear time.. ie o(n)..

hint : use mode or median to solve ..

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

2010-09-21 Thread Dave
If you can use both, it would be

head -10 foo | tail -6

It doesn't do the right thing if the file has fewer than 10 lines,
though.

Dave

On Sep 21, 4:04 pm, Divesh Dixit 
wrote:
> How to get  line no. 5 to line no. 10  only from a file.. using tail
> or head command.?

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

2010-09-21 Thread Dave
@Saurabh: Doesn't your code turn 123 into 321? Try this:

int function(int n)
{
int a[10]={0};
int result=0;
int place=1;
while(n){
if(a[n%10]==0){
a[n%10]=1;
result+=(n%10)*place;
place*=10;
}
n/=10;
}
return result;
}


Dave

On Sep 21, 3:12 pm, saurabh agrawal  wrote:
> int function(int n){
>
> int a[10]={0};
> int result =0;
> while(n){
>     if(a[n%10]==0){
>         a[n%10]=1;
>         result=10*result+n%10;
>     }
>     n/=10;}
>
> return result;`
>
>
>
> }
> On Wed, Sep 22, 2010 at 12:39 AM, Albert  wrote:
> > Given a number find the number by eliminating the duplicate digits in
> > the number..
>
> > for eg:   24526  ans is 2456
> > .
>
> > int function(int n)
> > {
>
> >  .
> >  .
> >  .
>
> > }
>
> > Give all sort of solutions to this problem.
>
> > Efficiency in the code is important 
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
>
> - Show quoted text -

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



[algogeeks] Help required

2010-09-21 Thread Nikhil Agarwal
Can anybody share his/her E-copy of An Introduction to algorithm by Udi
manber.It's a great resource.If anybody has please share his E-copy.Thanks
in advance.

-- 
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: Unbounded dictionary lookup

2010-09-21 Thread Minotauraus
high= const.(10^const)

What's const? The point of this isn't that it's a difficult prob to
solve. Point lies in working with the design to make this close to log
n.

Define what value "const" holds.

On Sep 21, 9:12 am, "coolfrog$" 
wrote:
> its dictionary means shorted ordered arry.
> let low = 1; and high= const.(10^const)
>
> Boolean isWord(String word)
>    {  while(low <= high)
>         {   mid = (low+ high)/2;
>                 if(word = getWordAt(mid))
>                   return true;
>                if( word > getWordAt(mid))
>                    {  high = mid-1
>                    }
>                 else
>                      low = mid+1;
>          }
>
>  }
> Its a simple Binary Search Algorithm ...
>    who's complexity is O(log n) times.

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

2010-09-21 Thread Divesh Dixit
How to get  line no. 5 to line no. 10  only from a file.. using tail
or head command.?

-- 
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 Question-Linux Shell

2010-09-21 Thread Prem Mallappa
Sorry this doesn't work all grep out there ...

On 22 Sep, 01:40, Prem Mallappa  wrote:
> @Neeraj:
> Your approach is good, this however lists .999.999.999 which is
> not a valid IP address.
>
> grep -lR "[0-255]\.[0-255]\.[0-255]\.[0-255]" *
>
> further filter out the output of above to invalidate any ip address
> that are reserved.
>
> -l is for suppressing normal output and printing only filename
> -R is recursive
>
> On 21 Sep, 18:46, Neeraj <17.neera...@gmail.com> wrote:
>
>
>
> > *grep -R "\<[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\>" * | awk -F':' '{print $1}' |
> > uniq
> > *
> > works on my system :P
>
> > On Tue, Sep 21, 2010 at 2:07 PM, Chi  wrote:
> > > With perl installed:
>
> > >  find directory | xargs perl -pi -e 's/needle/replace/g'
>
> > > With sed installed:
>
> > >  #!/bin/bash
>
> > >  find directory > mirror
> > >  exec 3
> > >  while read file <&3
> > >  do
> > >  replace=`more $file | sed -r -e 's/needle/replace/g'`
> > >  cat $replace > $file
> > >  done
>
> > > On Sep 19, 11:30 pm, bittu  wrote:
> > > > Linux shell command to find all files in a directory which contain ip
> > > > addresses
>
> > > --
> > > 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.
>
> > --
> > Neeraj

-- 
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 Question-Linux Shell

2010-09-21 Thread Prem Mallappa
@Neeraj:
Your approach is good, this however lists .999.999.999 which is
not a valid IP address.

grep -lR "[0-255]\.[0-255]\.[0-255]\.[0-255]" *

further filter out the output of above to invalidate any ip address
that are reserved.

-l is for suppressing normal output and printing only filename
-R is recursive

On 21 Sep, 18:46, Neeraj <17.neera...@gmail.com> wrote:
> *grep -R "\<[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\>" * | awk -F':' '{print $1}' |
> uniq
> *
> works on my system :P
>
>
>
>
>
> On Tue, Sep 21, 2010 at 2:07 PM, Chi  wrote:
> > With perl installed:
>
> >  find directory | xargs perl -pi -e 's/needle/replace/g'
>
> > With sed installed:
>
> >  #!/bin/bash
>
> >  find directory > mirror
> >  exec 3
> >  while read file <&3
> >  do
> >  replace=`more $file | sed -r -e 's/needle/replace/g'`
> >  cat $replace > $file
> >  done
>
> > On Sep 19, 11:30 pm, bittu  wrote:
> > > Linux shell command to find all files in a directory which contain ip
> > > addresses
>
> > --
> > 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.
>
> --
> Neeraj

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

2010-09-21 Thread saurabh agrawal
int function(int n){

int a[10]={0};
int result =0;
while(n){
if(a[n%10]==0){
a[n%10]=1;
result=10*result+n%10;
}
n/=10;
}
return result;`

}

On Wed, Sep 22, 2010 at 12:39 AM, Albert  wrote:

> Given a number find the number by eliminating the duplicate digits in
> the number..
>
> for eg:   24526  ans is 2456
> .
>
>
> int function(int n)
> {
>
>  .
>  .
>  .
>
> }
>
> Give all sort of solutions to this problem.
>
> Efficiency in the code is important 
>
> --
> 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: 2 power five digit no

2010-09-21 Thread rajess
check this way of using list


#include
#include
#include
using namespace std;
struct node
{
int data;
struct node * rev;
};
int main()
{
struct node * pass,*start1,*store;
stack  s1;
int i=1,carry=0,n,s;
printf("Enter");
scanf("%d",&n);
struct node * news=(struct node*)malloc(sizeof(struct node));
news->data=2;
news->rev=NULL;
start1=news;
for(i=1;idata)*2)+carry)/10;
pass->data=(((pass->data)*2)+s)%10;
pass=pass->rev;
}
if(carry>0)
{
struct node * news=(struct node*)malloc(sizeof(struct node));
news->data=carry;
news->rev=NULL;
store->rev=news;
}
}
while(start1!=NULL)
{
s1.push(start1->data);
start1=start1->rev;
}
while(!(s1.empty()))
{
printf("%d",s1.top());
s1.pop();
}


}

correct me if im wrong


On Sep 21, 10:30 pm, Dave  wrote:
> 1 followed by x zeros would be 2^x in base 2.
>
> Dave
>
> On Sep 21, 8:54 am, rajess  wrote:
>
>
>
>
>
>
>
> > why you can ,print a 1 followed by x number of zeros

-- 
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: Inserting a box with lesser dimension into a box of bigger dimensions than that.

2010-09-21 Thread Dave
Certainly having a smaller volume is necessary for a box to fit in
another box, but it is not sufficient. E.g., a box of size 1 x 1 x 1
will not fit in a box of size 2 x 2 x 1/2.

Dave

On Sep 21, 1:16 pm, rajess  wrote:
> find the volume of boxes as v=l*b*h
> sort boxes in volumes in descending order and this is the way to
> insert boxes one into another
>
> On Sep 21, 7:55 pm, Rashmi Shrivastava  wrote:
>
>
>
> > If there are n number of boxes and each with different dimensions and your
> > job is to insert one box having lesser dimension than that to another.
> > Consider size of boxes as,
> > b1->s1(h1,l1,w1)
> > b2->s2(h2,l2,w2)
> > .
> > .
> > .
> > bn->sn(hn,ln,wn)- Hide quoted text -
>
> - Show quoted text -

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



[algogeeks] Number problem

2010-09-21 Thread Albert
Given a number find the number by eliminating the duplicate digits in
the number..

for eg:   24526  ans is 2456
.


int function(int n)
{

 .
 .
 .

}

Give all sort of solutions to this problem.

Efficiency in the code is important 

-- 
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: Inserting a box with lesser dimension into a box of bigger dimensions than that.

2010-09-21 Thread rajess
find the volume of boxes as v=l*b*h
sort boxes in volumes in descending order and this is the way to
insert boxes one into another

On Sep 21, 7:55 pm, Rashmi Shrivastava  wrote:
> If there are n number of boxes and each with different dimensions and your
> job is to insert one box having lesser dimension than that to another.
> Consider size of boxes as,
> b1->s1(h1,l1,w1)
> b2->s2(h2,l2,w2)
> .
> .
> .
> bn->sn(hn,ln,wn)

-- 
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: 2 power five digit no

2010-09-21 Thread Dave
1 followed by x zeros would be 2^x in base 2.

Dave

On Sep 21, 8:54 am, rajess  wrote:
> why you can ,print a 1 followed by x number of zeros

-- 
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] ind out which row has the maximum number of 1's in 2D array

2010-09-21 Thread coolfrog$
There is a 2 dimensional array with each cell containing a 0 or 1 ,
 Design an algorithm to
find out which row has the maximum number of 1's , Your algorithm should
have O(n2)
time and no space complexity.

-- 
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: print largest continue subsequent in int array

2010-09-21 Thread LG JAYARAM .
Guys!!

On Mon, Sep 20, 2010 at 7:08 PM, LG JAYARAM .  wrote:

> @Krunal:
> can u explain hwz 7
>
>
> On Mon, Sep 20, 2010 at 6:02 PM, Krunal Modi wrote:
>
>> @LG JAYARAM:
>>
>> It is 7.
>>
>> --
>> 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:Unbounded dictionary lookup

2010-09-21 Thread coolfrog$
its dictionary means shorted ordered arry.
let low = 1; and high= const.(10^const)

Boolean isWord(String word)
   {  while(low <= high)
{   mid = (low+ high)/2;
if(word = getWordAt(mid))
  return true;
   if( word > getWordAt(mid))
   {  high = mid-1
   }
else
 low = mid+1;
 }


 }
Its a simple Binary Search Algorithm ...
   who's complexity is O(log n) times.

-- 
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] Point lies inside or outside of triangle?

2010-09-21 Thread Bharath
Find area of Triangle(A) and area of Polygon with these four points(B)

if AB point lies inside triangle
else on  if they are equal, it lies on triangle.

On Mon, Sep 20, 2010 at 10:39 PM, Nikhil Agarwal
wrote:

>
> Method 1:
> Yes you can do by writing equation of 3 lines taking 2 points at a time
> and finding the sign with the third point.
>
> Suppose: ax+by+c=0 is your first line and (x,y) is the third point then
> find out the sign of the 3rd point satisfying it on the line. suppose this
> sign is S (for +ve)
>
> Similarly calculate for signs for other 2 lines.
>
> Now give a point(p,q) should give the same signs for all the 3 lines .If it
> gives the same sign for all the 3 lines that means it lies btwn all the 3
> lines and all the 3 points.hence proved.
>
> Method 2: Area mentioned by praveen
>
> Method 3:
> http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)#Determining_if_a_point_is_inside_a_triangle
>
> You can choose the best method.
>
> On Mon, Sep 20, 2010 at 9:18 PM, Nicolae Titus 
> wrote:
>
>> there are some approximations involved there, it should be (area(big) -
>> sum(area small)) < error
>> a better approach would be to find if the point is on the proper side of
>> each edge
>> take all the edges clockwise and calculate the sinus between each edge and
>> the point, if they are all positive, the point is inside.
>>
>> Titus
>>
>> --
>> 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.
>



-- 
<>

-- 
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] recursion to remove duplicate characters in a string

2010-09-21 Thread sharad kumar
instead of creating a bst why dontwe create a heap.then sort the heap .then
remove the duplictes from string...but will also chnge th order of
string.

On Sun, Sep 19, 2010 at 4:20 PM, Umer Farooq  wrote:

> creating a bst would require extra space. You can do this with an array of
> char dude.
>
> On Sun, Sep 19, 2010 at 3:31 PM, LG JAYARAM .  wrote:
>
>> hi buddy ...Im clear with the ideahereby I share the concept...
>>
>> wat exactly need to be done to solve this task isbetter create a
>> Binary search tree...the Binary search tree will not allow duplicates and If
>> u perform a inorder traversalu can get the result...the task is
>> oversimple and thts it.
>>
>>  On Sat, Sep 18, 2010 at 11:12 PM, jagadish wrote:
>>
>>> You are given a string which is sorted.. Write a recursive function to
>>> remove the duplicate characters in the string.
>>> eg: potatoeos
>>> output: potaes
>>> NO extraspace like hash/ bitmaps..
>>>
>>> --
>>> 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.
>>
>
>
>
> --
> Umer
>
> --
>  You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
yezhu malai vaasa venkataramana Govinda Govinda

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



Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-21 Thread LG JAYARAM .
Guyswe need to find two numbers in a array with minimum difference ah


On Tue, Sep 21, 2010 at 8:52 PM, Rahul Singal wrote:

> try running it on [ 11 , 6 , 100, 101]
>
>  --
> 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: do this: two numbers with min diff

2010-09-21 Thread Rahul Singal
try running it on [ 11 , 6 , 100, 101]

-- 
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 Question-Linux Shell

2010-09-21 Thread Chi
What does [0-9]\+. means? Why do you nested it?

On Sep 21, 3:46 pm, Neeraj <17.neera...@gmail.com> wrote:
> *grep -R "\<[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\>" * | awk -F':' '{print $1}' |
> uniq
> *
> works on my system :P
>
>
>
> On Tue, Sep 21, 2010 at 2:07 PM, Chi  wrote:
> > With perl installed:
>
> >  find directory | xargs perl -pi -e 's/needle/replace/g'
>
> > With sed installed:
>
> >  #!/bin/bash
>
> >  find directory > mirror
> >  exec 3
> >  while read file <&3
> >  do
> >  replace=`more $file | sed -r -e 's/needle/replace/g'`
> >  cat $replace > $file
> >  done
>
> > On Sep 19, 11:30 pm, bittu  wrote:
> > > Linux shell command to find all files in a directory which contain ip
> > > addresses
>
> > --
> > 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.
>
> --
> Neeraj

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

2010-09-21 Thread Minotauraus
XOR all the elements from both arrays, the value that is left is x.

On Sep 20, 5:06 pm, Anand  wrote:
> Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers
> and B contains n+1 integers of which n are same as in array B but in
> different order and one extra element x. Write an optimized algorithm to
> find the value of element x. Use only one pass of both arrays A and B.

-- 
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] Unbounded dictionary lookup

2010-09-21 Thread Minotauraus
Consider you have a dictionary of unknown size. The size could be 10,
or 1000 or 10^30.
You are given a method- String GetWordAt(int index), which returns the
word at 'index',
or null if the index is invalid (or out of bounds).

How will you write a method that returns a boolean for a particular
word look up?
Boolean isWord(String word), returns true, if the dictionary contains
the word, or false if it doesn't.

Further constraint: Do this in O(log n) time.

-- 
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: point lies inside or outside of triangle..

2010-09-21 Thread Bharath
Find area of Triangle(A) and area of Polygon with these four points(B)

if AB point lies inside triangle
else on  if they are equal, it lies on triangle.

On Tue, Sep 21, 2010 at 5:03 PM, jagadish  wrote:

> Here is the Simplest working solution :)
>
> bool check(int x[],int y[],int n)
> {
> c=0;
> for(int i=0;i j=(i+1)%n;
> if( ((y[i]>y) != (y[j]>y)) && (x-x[i]/x[j]-x[i] < y-y[i]/y[j]-y[i])
> c=!c;
> }
> return c;
> }
>
>
> On Sep 20, 7:46 pm, umesh kewat  wrote:
> > Initially we have given  three point A , B, C in plane represent three
> nodes
> > of triangle, now given another point Z  which lies in same plane,  find
> out
> > whether that point lies on/inside the triangle or outside of
> triangletry
> > to get in min time and space complexity
> >
> > --
> > Thanks & Regards
> >
> > Umesh kewat
>
> --
> 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: Amazon Question-Linux Shell

2010-09-21 Thread Neeraj
*grep -R "\<[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\>" * | awk -F':' '{print $1}' |
uniq
*
works on my system :P

On Tue, Sep 21, 2010 at 2:07 PM, Chi  wrote:

> With perl installed:
>
>  find directory | xargs perl -pi -e 's/needle/replace/g'
>
> With sed installed:
>
>  #!/bin/bash
>
>  find directory > mirror
>  exec 3
>  while read file <&3
>  do
>  replace=`more $file | sed -r -e 's/needle/replace/g'`
>  cat $replace > $file
>  done
>
> On Sep 19, 11:30 pm, bittu  wrote:
> > Linux shell command to find all files in a directory which contain ip
> > addresses
>
> --
> 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.
>
>


-- 
Neeraj

-- 
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] Point lies inside or outside of triangle?

2010-09-21 Thread Nikhil Agarwal
Method 1:
Yes you can do by writing equation of 3 lines taking 2 points at a time and
finding the sign with the third point.

Suppose: ax+by+c=0 is your first line and (x,y) is the third point then find
out the sign of the 3rd point satisfying it on the line. suppose this sign
is S (for +ve)

Similarly calculate for signs for other 2 lines.

Now give a point(p,q) should give the same signs for all the 3 lines .If it
gives the same sign for all the 3 lines that means it lies btwn all the 3
lines and all the 3 points.hence proved.

Method 2: Area mentioned by praveen

Method 3:
http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)#Determining_if_a_point_is_inside_a_triangle

You can choose the best method.

On Mon, Sep 20, 2010 at 9:18 PM, Nicolae Titus wrote:

> there are some approximations involved there, it should be (area(big) -
> sum(area small)) < error
> a better approach would be to find if the point is on the proper side of
> each edge
> take all the edges clockwise and calculate the sinus between each edge and
> the point, if they are all positive, the point is inside.
>
> Titus
>
> --
> 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: do this: two numbers with min diff

2010-09-21 Thread Modeling Expert
Trying to put down a method, I think would work ( with a small running
example )

//! Assuming non--negative numbers and difference is MOD of difference
of numbers

Let array be A[1..n]//! e.g.  { 11 , 6 , 17 , 9 ]
Start with pari ( A[1], A[2] ) and difference be D = | A[1] - A[2]
|/// A[1] = 11 , A[2] = 6  , D = 5

   Now take A[3] , see if it lies b/w A[1] and A[2] //!  A[3] = 17 ,
is it b/w { 11, 6} => NO
   if NO , continue
   else
   check where left or right member of pair is closer to
it   //! pair = (11,6) , next num = 9
   new pair = (Left,A[3])  OR ( A[3],
right )//! new pair = (11,9)

Time : O(n) as we are traveling array once
Space Coplexity : O(1) just need to store pair of numbers..


Thoughts ?
-Manish

-- 
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 Question-Linux Shell

2010-09-21 Thread Minotauraus
grep /home/user/dir -d recurse -H \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?
[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

the ugly looking block matches IP address. GREP is a gnu regex utility
in linux (also available for windows).
/home/user/dir is the location of the directory
-d recurse, tells grep to use all files in the directory
-H prints the names of the file(s) that the said expression matched.


On Sep 19, 2:30 pm, bittu  wrote:
> Linux shell command to find all files in a directory which contain ip
> addresses

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

2010-09-21 Thread Modeling Expert
no need to addi all element if overflow is feared , subtract values
for given index in the loop
something like this
   result = 0 ;
   for(count = 0; count < n ;count ++){
  result  += (B[count]-A[count]);
   }
   result += B[count] ; //! this is the answer...

-Manish


On Sep 21, 9:44 am, Baljeet Kumar  wrote:
> There can be overflow in case of adding up all the elements. Use Xor
> instead.
>
>
>
>
>
> > int result = 0;
> > for (int i = 0; i < n ;i++){
> >       result ^= A[i]^B[i];
> > }
>
> > result ^= B[n]; <=== (correction)
> > result is the number we need.
>
> > On Tue, Sep 21, 2010 at 9:48 AM, vishal raja wrote:
>
> >> add up all the elements in array A  say sumA and array B say sumB
> >> ,substract the sumA from sumB... You'll get the element.
>
> >> On Tue, Sep 21, 2010 at 5:36 AM, Anand  wrote:
>
> >>> Two unsorted arrays are given A[n] and B[n+1]. Array A contains n
> >>> integers and B contains n+1 integers of which n are same as in array B but
> >>> in different order and one extra element x. Write an optimized algorithm 
> >>> to
> >>> find the value of element x. Use only one pass of both arrays A and B.
>
> >>> --
> >>> 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.
>
> > --
> > Baljeet Kumar
>
> --
> Baljeet Kumar

-- 
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] Inserting a box with lesser dimension into a box of bigger dimensions than that.

2010-09-21 Thread Rashmi Shrivastava
If there are n number of boxes and each with different dimensions and your
job is to insert one box having lesser dimension than that to another.
Consider size of boxes as,
b1->s1(h1,l1,w1)
b2->s2(h2,l2,w2)
.
.
.
bn->sn(hn,ln,wn)

-- 
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: recursion to remove duplicate characters in a string

2010-09-21 Thread abhishek

void remove_duplicate(char * str)
{

  if (*str == '\0')
  return ;

 else
 {
char ch = *str;
char * temp ;
int i = 0 ;
while ( ch ==  *(str+i) )
 {
  i++;
 }
 if ( *(str+i) == '\0')
 *(str+1)='\0';
 if ( i>1)
 {
  i--;
  temp = str ;
while ( *(str+i) !='\0' )
 {
 *(str) = *(str+i);
 ++str;
 }
 str = temp ;
  }
  remove_duplicate(str +1);
 }
}


hope this is correct.
On Sep 20, 3:10 pm, "LG JAYARAM ."  wrote:
> Yes ur correct...it will require some extra spacebst can be represented
> in the array form ritelet me think in tht logic.
>
> On 9/19/10, Umer Farooq  wrote:
>
>
>
>
>
> > creating a bst would require extra space. You can do this with an array of
> > char dude.
>
> >  On Sun, Sep 19, 2010 at 3:31 PM, LG JAYARAM .  wrote:
>
> >> hi buddy ...Im clear with the ideahereby I share the concept...
>
> >> wat exactly need to be done to solve this task isbetter create a
> >> Binary search tree...the Binary search tree will not allow duplicates and 
> >> If
> >> u perform a inorder traversalu can get the result...the task is
> >> oversimple and thts it.
>
> >>  On Sat, Sep 18, 2010 at 11:12 PM, jagadish wrote:
>
> >>> You are given a string which is sorted.. Write a recursive function to
> >>> remove the duplicate characters in the string.
> >>> eg: potatoeos
> >>> output: potaes
> >>> NO extraspace like hash/ bitmaps..
>
> >>> --
> >>> 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.
>
> >> --
> >> 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.
>
> > --
> > Umer
>
> > --
> > 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.

-- 
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] path of a node

2010-09-21 Thread rajess
do a preorder traversal,if you call the function put in stack,on
returning from the function delete the top element from the queue,if
find element return the queue.

-- 
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] 2 power five digit no

2010-09-21 Thread rajess
why you can ,print a 1 followed by x number of zeros

-- 
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] search a 2d sorted array in less than O(n)

2010-09-21 Thread saurabh singh
solution 1:
use concept of quad-tree and do binary search in that tree

solution 2:
do binary search on major diagonal. ultimately u will narrow down to search
for element in  2 rows. in these two rows again do binary search.

any solution will lead you to O(log(n)) time

On Tue, Sep 21, 2010 at 5:10 PM, jagadish  wrote:

> Hi all,
> Given a 2d array which is sorted row wise and column wise as well,
> find a specific element in it in LESS THAN O(n).
> PS: an O(n) solution would involve skipping a column or a row each
> time from the search and moving accordingly.
> Solution less than O(n) is desirable!
>
> --
> 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,
Saurabh

-- 
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] search a 2d sorted array in less than O(n)

2010-09-21 Thread jagadish
Hi all,
Given a 2d array which is sorted row wise and column wise as well,
find a specific element in it in LESS THAN O(n).
PS: an O(n) solution would involve skipping a column or a row each
time from the search and moving accordingly.
Solution less than O(n) is desirable!

-- 
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: point lies inside or outside of triangle..

2010-09-21 Thread jagadish
Here is the Simplest working solution :)

bool check(int x[],int y[],int n)
{
c=0;
for(int i=0;iy) != (y[j]>y)) && (x-x[i]/x[j]-x[i] < y-y[i]/y[j]-y[i])
c=!c;
}
return c;
}


On Sep 20, 7:46 pm, umesh kewat  wrote:
> Initially we have given  three point A , B, C in plane represent three nodes
> of triangle, now given another point Z  which lies in same plane,  find out
> whether that point lies on/inside the triangle or outside of triangletry
> to get in min time and space complexity
>
> --
> Thanks & Regards
>
> Umesh kewat

-- 
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: Finding max for all positions of a moving window

2010-09-21 Thread jagadish
@Minotauraus: ur approach is flawed!
the BEST solution would be to use a maxheap as navin said! :)

On Sep 21, 1:55 pm, Naveen Agrawal  wrote:
> @Minotauraus
>
> Your algo is wrong
> Consider this case:
> 1    2  3   4   5   6  7   8   9  10 11 12 13  14 15 16  17 18 19 20
> 99 98 97 96 95 94 93 92 91 90 89 88  87  86 85 84 83 82 81 80
>
> According to your algo
> 1)Max for first window =99,i.e,curr max=99
> 2)Compare with new element,i.e wlth element number (11) = 89,as it is small
> than curr max ,curr max=99 which is wrong as the correct answer is 98.
>
> Improvisation of your algo but complexity of O(n2)
>
> if curr max then curr max = new elemnt
> else
> *again calculate max of the whole window*
>
> So it will be better to use heap as suggested by Navin Naidu.,which
> reduces the complexity..

-- 
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: Finding max for all positions of a moving window

2010-09-21 Thread Naveen Agrawal
@Minotauraus

Your algo is wrong
Consider this case:
12  3   4   5   6  7   8   9  10 11 12 13  14 15 16  17 18 19 20
99 98 97 96 95 94 93 92 91 90 89 88  87  86 85 84 83 82 81 80

According to your algo
1)Max for first window =99,i.e,curr max=99
2)Compare with new element,i.e wlth element number (11) = 89,as it is small
than curr max ,curr max=99 which is wrong as the correct answer is 98.

Improvisation of your algo but complexity of O(n2)

if curr maxhttp://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Amazon Question-Linux Shell

2010-09-21 Thread Chi
With perl installed:

 find directory | xargs perl -pi -e 's/needle/replace/g'

With sed installed:

 #!/bin/bash

 find directory > mirror
 exec 3 $file
 done

On Sep 19, 11:30 pm, bittu  wrote:
> Linux shell command to find all files in a directory which contain ip
> addresses

-- 
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 Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-21 Thread kartheek muthyala
Thanks for clearing

On Tue, Sep 21, 2010 at 1:58 PM, Naveen Agrawal wrote:

>
> @Kartheek
>
> Ashish algo is perfectly workingBy making before[0]&after[length-1]=1
> the array is shifted ,which prevents the inclusion of current index.
>
> Ex:
>
> int a[5]={10,4,8,3,9}
>
> before[0]=1
> before[1]=10
> before[2]=40
> before[3]=320
> before[4]=960
>
> after[4]=1
> after[3]=9
> after[2]=27
> after[1]=216
> after[0]=864
>
> ans[0]=  ( before[0]=1 )*(after[0]=864)
> .
> .
> .
> similarly others
>
> -
> Naveen
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-21 Thread Naveen Agrawal
@Kartheek

Ashish algo is perfectly workingBy making before[0]&after[length-1]=1
the array is shifted ,which prevents the inclusion of current index.

Ex:

int a[5]={10,4,8,3,9}

before[0]=1
before[1]=10
before[2]=40
before[3]=320
before[4]=960

after[4]=1
after[3]=9
after[2]=27
after[1]=216
after[0]=864

ans[0]=  ( before[0]=1 )*(after[0]=864)
.
.
.
similarly others

-
Naveen

-- 
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: Finding max for all positions of a moving window

2010-09-21 Thread Soundar
You are correct ...It depends on the max element's index...

-- 
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: Finding max for all positions of a moving window

2010-09-21 Thread Soundar
1)Sort the first 10 elements (first window)
2)initialise i=1,l=j=10
3)last element is the maximum(l=10) printf(a[l])
4)i=i+1,j=j+1 if(a[j]>a[l])
 then printf(a[j])
 l=j
5)else printf(a[l])
6)if(i==l)
   repeat from step 1
for worst case it needs 10 sorts
Correct if i am 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.