Re: [algogeeks] Re: island puzzle

2011-05-30 Thread Anand
http://anandtechblog.blogspot.com/2010/10/directi-interview-question_3183.html

On Mon, May 30, 2011 at 3:54 PM, Carl Barton wrote:

> It's been posted quite a few times recently. Just check the mailing list.
>
>
> On 30 May 2011 18:46, himanshu kansal  wrote:
>
>> guys wake up
>>
>>
>> On Fri, May 27, 2011 at 9:24 PM, himanshu kansal <
>> himanshukansal...@gmail.com> wrote:
>>
>>> a king has two sons eric and bob.he wants to divide his
>>> islands
>>> the islands are in a queue.eric being elder gets the first
>>> chancethey both can pick d island alternatively from beginning or
>>> end of the queue only.design an algo so tht eric gets the max.
>>> piece of land.
>>> i hv solved it if the no of islands are even
>>> bt nt getting any clue whn no of islands are odd
>>> in the odd casei think bob vl hv an advantage ovr ericbut how
>>> to develop strategy for eric(if no of islands are odd)
>>
>>
>>
>>
>> --
>>
>> Regards
>> Himanshu Kansal
>> MCS-DU
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: island puzzle

2011-05-30 Thread Carl Barton
It's been posted quite a few times recently. Just check the mailing list.

On 30 May 2011 18:46, himanshu kansal  wrote:

> guys wake up
>
>
> On Fri, May 27, 2011 at 9:24 PM, himanshu kansal <
> himanshukansal...@gmail.com> wrote:
>
>> a king has two sons eric and bob.he wants to divide his
>> islands
>> the islands are in a queue.eric being elder gets the first
>> chancethey both can pick d island alternatively from beginning or
>> end of the queue only.design an algo so tht eric gets the max.
>> piece of land.
>> i hv solved it if the no of islands are even
>> bt nt getting any clue whn no of islands are odd
>> in the odd casei think bob vl hv an advantage ovr ericbut how
>> to develop strategy for eric(if no of islands are odd)
>
>
>
>
> --
>
> Regards
> Himanshu Kansal
> MCS-DU
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread T3rminal
Right!! that is pretty standard problem but the solution u have given
is for undirected graphs and intuitively binary trees are directed.
Piyush solution will work for binary tree.

On May 30, 2:04 am, anshu mishra  wrote:
> this is a very standard problem :D
>
> start with any node(x) find the node which is at maximum distance.
>
> now start with x travese the tree and find the node(y) which is at maximum
> distance.
>
> so finally answer wil be (x, y)
>
> traversing the tree two times. so the order for finiding the such nodes
> equals to 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 algogeeks@googlegroups.com.
To unsubscribe from 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: Binary Tree Problem

2011-05-30 Thread sunny agrawal
nope, it will not work :(
got a case

On Mon, May 30, 2011 at 11:57 PM, sunny agrawal wrote:

> won't this simple algo work ??
>
> start from root node, say it has value 0
> at any time if a node has a value v
> pass v-1 to left subtree and v+1 to right subtree
> keep track of max and min
> final answer will be max -min = Diameter of tree.
>
> correct me if i m wrong.
>



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

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



Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
won't this simple algo work ??

start from root node, say it has value 0
at any time if a node has a value v
pass v-1 to left subtree and v+1 to right subtree
keep track of max and min
final answer will be max -min = Diameter of tree.

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 algogeeks@googlegroups.com.
To unsubscribe from 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: island puzzle

2011-05-30 Thread himanshu kansal
guys wake up

On Fri, May 27, 2011 at 9:24 PM, himanshu kansal <
himanshukansal...@gmail.com> wrote:

> a king has two sons eric and bob.he wants to divide his
> islands
> the islands are in a queue.eric being elder gets the first
> chancethey both can pick d island alternatively from beginning or
> end of the queue only.design an algo so tht eric gets the max.
> piece of land.
> i hv solved it if the no of islands are even
> bt nt getting any clue whn no of islands are odd
> in the odd casei think bob vl hv an advantage ovr ericbut how
> to develop strategy for eric(if no of islands are odd)




-- 

Regards
Himanshu Kansal
MCS-DU

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

2011-05-30 Thread ross
You are given a sequence of jobs. The no. of days which each job takes
to complete is also provided.
You are also given the penalty amount to be paid per day each day a
job left done. Give an optimal ordering
among jobs to minimize penalty. There are no concurrent jobs.

eg:
Jobs:  J1 J2 J3
no. of days to complete:   1  10  4
Penalty incurred each day1000 30 40
the job is pending

output:
Schedule is J1 J3 J2
hence, J1 goes for 1st day. J3 for subsequent 4 days. J2 for the next
10 days.

Penalty incurred = (delay for job i ) * (penalty per day of job i) =
= (0)(1000) + (1)(40) + 5(30) = 190




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

2011-05-30 Thread oldman
Code::Blocks

On Sun, May 29, 2011 at 1:59 AM, Akash Mukherjee  wrote:

> devcpp
>
>
> On Sat, May 28, 2011 at 11:17 PM, sravanreddy001  > wrote:
>
>> Hi all. Can some one provide a good C editor.. preferable GUI one, that
>> works on windows 7.
>>
>> I'm good with Java, but. now would like to get some hands on C, C++
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] can ne1 pls help me

2011-05-30 Thread Abdul Rahman Shariff
thnaq

On Mon, May 30, 2011 at 8:00 PM, nagajyothi gunti <
nagajyothi.gu...@gmail.com> wrote:

> Hi Shariff
>
> I thought this document would be a help to you. There is an example with
> this string.
>
>
> On Mon, May 30, 2011 at 10:16 AM, Abdul Rahman Shariff  > wrote:
>
>> i had this qn in a previous qpaper for my semeter exams in design and
>> anlysis of algorithems
>>
>>
>> draw an optimal merge pattern tree for the srting "abracadabra"
>>
>>
>> thnks in advance
>> pls solve this asap i have the xam tomorow
>>
>> --
>>
>> Ehab Abdul Rahman Shariff
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Jyothi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

Ehab Abdul Rahman Shariff

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



[algogeeks] Re: C Output

2011-05-30 Thread Dave
@vishal: Floats and doubles are stored in different formats, so
looking at the first 8 hex digits of the two numbers isn't really
helpful.

The expression f < 0.8 is evaluated as (double)f < 0.8, so it would be
more useful to print all 16 hex digits of (double)0.8f and 0.8. Then
it would be easy to see that 0.08f < 0.08.

Dave

On May 29, 11:35 pm, Vishal Thanki  wrote:
> you may want to check how the floats and doubles are stored into
> memory using ieee notation.
>
> i tried to print 0.08 and 0.08f in hex format and got the following result.
>
> vishal@ubuntu:~/progs/c\ 10:03:56 AM >$ cat fl.c
> #include 
> int main()
> {
>         float f=0.08;
>         if (f < 0.08f)
>                 printf("hi\n");
>         else
>                 printf("hello\n");
>
>         printf ("%x %x\n",0.08, 0.08f);
>         return 0;}
>
> vishal@ubuntu:~/progs/c\ 10:04:06 AM >$ gcc fl.c
> fl.c: In function ‘main’:
> fl.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but
> argument 2 has type ‘double’
> fl.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but
> argument 3 has type ‘double’
> vishal@ubuntu:~/progs/c\ 10:04:11 AM >$ ./a.out
> hello
> 47ae147b 3fb47ae1
> vishal@ubuntu:~/progs/c\ 10:04:14 AM >$
>
> ps: please ignore the warning in the code.
>
> On Sun, May 29, 2011 at 10:23 PM, sravanreddy001
>
>
>
>  wrote:
> > and, I read it long time back that.. the value of 0.8 alone will be stored
> > as 0.7995 (not sure on the number of 9's but.. the last digit in the
> > precision will be a 5)
> > that could be a reason.
> > may be what "vishal" said is correct.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.- 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 algogeeks@googlegroups.com.
To unsubscribe from 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] can ne1 pls help me

2011-05-30 Thread Abdul Rahman Shariff
i had this qn in a previous qpaper for my semeter exams in design and
anlysis of algorithems


draw an optimal merge pattern tree for the srting "abracadabra"


thnks in advance
pls solve this asap i have the xam tomorow

-- 

Ehab Abdul Rahman Shariff

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

2011-05-30 Thread HARISH S.C
+1

On Thu, May 26, 2011 at 9:31 PM, Ashish Patel wrote:

> +1000 ..dont count this as SPAM! :D
>
> On Thu, May 26, 2011 at 9:29 PM, radha krishnan <
> radhakrishnance...@gmail.com> wrote:
>
>> +100
>>
>> On Thu, May 26, 2011 at 9:26 PM, pacific :-) wrote:
>>
>>> +1
>>>
>>>
>>> On Wed, May 25, 2011 at 11:48 PM, anuj agarwal 
>>> wrote:
>>>
 Hi,

 Are there any admins on this group? I recently joined this group and i
 liked the discussions going on here.

 But there is a problem which hurts is that unlike other groups which are
 moderated by certain admin guys (also active members of group), this one is
 not.
 So we are receiving lots of SPAMS. I guess no body wants to get a job
 from this group (specially ones which are sent by some Panzer).

 If the mods are reading this, Please take some action on that mails so
 that group will remain clean.

 Sorry for off topic.

 Anuj Agarwal
 Engineering is the art of making what you want from things you can get.

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

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

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



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Bhavesh agrawal
@piyush :

 hey buddy, check out carefully i think you missed something.

my solution says it's 18  ->18111
   187->18711
and i think you will count it carefully...

plz let me know in any case if my solution goes wrong anywhere .

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

2011-05-30 Thread Sairam Krishnamurthy
http://www.tavistockwood.com/find11.html

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

2011-05-30 Thread Maksym Melnychok
so here's oneliner code in ruby:

a.map{|x| x=x*10+1; -x/10.0**Math.log10(x).ceil}.sort.map{|x| 
(-x).to_s[2..-2]}.join

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

2011-05-30 Thread snehi jain
ok ... got it thanks ... :)


On Mon, May 30, 2011 at 5:25 PM, Maksym Melnychok  wrote:

> @halo check my previous messages
>
> we multiply every element by 10 and add 1
>
> 90, 9 -> 901, 91
> 901, 91 -> 0.901, 0.91
> sort -> 0.91, 0.901
> revert -> 9, 90
> join -> 990
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@halo check my previous messages

we multiply every element by 10 and add 1

90, 9 -> 901, 91
901, 91 -> 0.901, 0.91
sort -> 0.91, 0.901
revert -> 9, 90
join -> 990

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

2011-05-30 Thread snehi jain
@Maksym

what if we have 90 and 9
they become .9 and .9
now what to do to get result as 990 and not 909.

correct me if i am going somewhere wrong?


On Mon, May 30, 2011 at 3:55 PM, Maksym Melnychok  wrote:

> @Sunny i explained how to deal with edgecases right after my post
>
> 1, 101 -> 11, 1011
> 11, 1011 -> 0.11, 0.1011
> sort -> 0.11, 0.1011
> restore -> 1, 101
> join -> 1101
>
> i can't think of any fail examples anymore
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@Sunny i explained how to deal with edgecases right after my post

1, 101 -> 11, 1011
11, 1011 -> 0.11, 0.1011
sort -> 0.11, 0.1011
restore -> 1, 101
join -> 1101

i can't think of any fail examples anymore

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

2011-05-30 Thread Piyush Sinha
@Bhavesh...

for the inputs 18,187.. apply your method..
18 -- 188
187-- 187

18187 -> ur method

18718 -> actual

On Mon, May 30, 2011 at 3:28 PM, Bhavesh agrawal wrote:

>  solution may be
>
>
> array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all
> exceptions )
>
> then ,change this array like 3 , 21222, 9, 93999, 17111, 17811,
> 1 , 10111  ( make each number of 5 digit with rest digits same as Ist
> digit )
>  then sort this array
>
> 9, 93999,3 21222, 17811,17111, 1, 10111
>  and make it with actual numbers
>
> 9,93,3,21,178,17,1,101= 993321178171101
>
> plz let me know if any case left...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-05-30 Thread Bhavesh agrawal
 solution may be


array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all exceptions
)

then ,change this array like 3 , 21222, 9, 93999, 17111, 17811,
1 , 10111  ( make each number of 5 digit with rest digits same as Ist
digit )
 then sort this array

9, 93999,3 21222, 17811,17111, 1, 10111
 and make it with actual numbers

9,93,3,21,178,17,1,101= 993321178171101

plz let me know if any case left...

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

2011-05-30 Thread Vandana Bachani
The hijacker was the "pilot".

On Mon, May 30, 2011 at 12:34 PM, Lavesh Rawat wrote:

> *Aeroplane Hijack puzzle SOLUTION
>  *
> *
> *
> **
> *A man hijacks an aeroplane transporting both passengers(8 of them) and
> valuable cargo. After taking the cargo, the man demands nine parachutes,
> puts one of them on, and jumps, leaving the other eight behind. Why did he
> want eight?
> **
> *
>
> *Update Your Answers at* : Click 
> Here
>
> Solution:
>
> Will be updated after 1 day
>
>
>
>
> --
>
> "Never explain yourself. Your friends don’t need it and
> your enemies won’t believe it" .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

2011-05-30 Thread Piyush Sinha
I think following algo will work..I haven't tested it plus its in its crude
form...Kindly correct me if i am wrong..

*typedef struct queue
{
   struct node *q[2];
   int h1,h2;

}queue;*
**
*queue max_dist(struct node * tree)
{
   if (tree == NULL)
  return;

  queue q1,q2,q3;

   q1.h1 = height(&q1,tree->left,0);
   q1.h2 = height(&q1,tree->right,1);


   q3 = max_dist(tree->left);
   q4 = max_dist(tree->right);  *
*  *
*   if((q3.h1+q3.h2)>(q4.h1+q4.h2))
   {
 if((q3.h1+q3.h2)>(q1.h1+q1.h2+1))
  return q3;
else
 return q1;
}
   else
   {
if((q4.h1+q4.h2)>(q1.h1+q1.h2+1))
return q4;
else
   return q1;
  }*
*}   *
**
**
*int height(queue *Q,struct node* node,int i)
{
  if(node == NULL)
return;

 if(node>left == NULL && node->right == NULL)
{
   Q->(q[i]) = node;
   return 0;
 }

  return 1 +  max(height(Q,node->left,i), height(Q,node->right,i));
}*

On Mon, May 30, 2011 at 2:35 PM, anshu mishra wrote:

> little modification
> start with any node(r) find the node(x) which is at maximum distance.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-05-30 Thread Maksym Melnychok
possible fix for 100 10 edgecases would be to simply array.map{|x| x*10+1} 
and then get rid of that after sorting

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

2011-05-30 Thread sunny agrawal
@ Maksym Melnychok

Fails i think
some explanation

say we have numbers 1 , 101
divide all by something to get 0.1, 0.101
simple sort will give you 0.101, 0.1
multiply all numbers to get original ones 101,1
join 1011

but correct answer should be 1101, isn't it ??
correct me if i m wrong ??

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

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



Re: [algogeeks] Re: posix threads

2011-05-30 Thread jagannath prasad das
@anshu:thats means you say that pthreads are either kernel -level or
hybrid in nature
@lalit:mapping dependsfor user-level kernel isn't aware of
threads,m-m is for kernel-level ,m-n for hybrid
kinda
does anbody knows whether pthreads are user-level or hybrid?

On 5/30/11, anshu mishra  wrote:
> PS dont forget to bind ith thread with ith processor
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
some explanation

say we have numbers 2 3 5 78
divide all by something to get 0.2, 0.3, 0.5, 0.78
simple sort will give you 0.78, 0.5, 0.3, 0.2
multiply all numbers to get original ones 78 5 3 2
join 78532

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

2011-05-30 Thread snehi jain
i guess Sunny  has already mentioned (concatenating the two numbers and
comparing) this technique before, i liked and tried coding it ... it works
perfectly  without comparing the second digit incase the first is same. the
algorithm can run in O(nlogn) taking the best sorting technique , though i
have used the O(n^2)one.
i tried for 5 numbers, one can do it for N numbers too.

@maksym could you explain your logic

int length(int );
int power(int );
int com(int, int );
void swap(int *, int *);
main()
 {
  int a[5],l, j, temp;
  int i ;
  for(i = 0 ;i<5;i++)
   {
printf(" \n\tEnter the %d number ", i+1);
scanf("%d",&a[i]);
l =length(a[i]);
}
for (i = 0; i<5; i++)
for (j = 0 ; j<5;j++)
 {
   temp = com(a[i], a[j]);
if (temp != a[i])
  swap(a+i, a+j);
  }
  for (i =  0 ;i<5;i++)
   printf("\n\t%d",a[i]);
   printf("\n\t\t The largest possible number is\n\t ");
   for (i = 4 ;i>=0;i--)
   printf("%d",a[i]);
   getch();


}

void swap(int *n1, int *n2)
 {
 int temp;
 temp = *n1;
 *n1 = *n2;
 *n2 = temp;
}
int length(int a)
 {
 int len=0,i = 10 ;

 while (a!=0)
  {
   a = a/10;
   len++;
   }
 return len;

}
int com(int a1, int a2)
 {
int l1, l2;
int c,d;
l1 = length(a1);
l2 = length(a2);
c= a1*power(l2) +a2;
d = a2*power(l1)+a1;
  if (c>d)
   return a1;
  else
   return a2;
}

 int power(int n)
 {
int i=0, a = 1;
for (i = 0;iwrote:

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

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



Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread anshu mishra
little modification
start with any node(r) find the node(x) which is at maximum distance.

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

2011-05-30 Thread anshu mishra
this is a very standard problem :D

start with any node(x) find the node which is at maximum distance.

now start with x travese the tree and find the node(y) which is at maximum
distance.

so finally answer wil be (x, y)

traversing the tree two times. so the order for finiding the such nodes
equals to 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 algogeeks@googlegroups.com.
To unsubscribe from 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: Binary Tree Problem

2011-05-30 Thread Piyush Sinha
@ross...I think it can be done by taking a queue/stack...I am working on the
code...Please comment if there is any error in my approach..


On Mon, May 30, 2011 at 2:19 PM, Maksym Melnychok  wrote:

> simplest algo: find a node with max depth M and go up tree calculating max
> depth of all upper branches that do not contain M until reaching root node
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-05-30 Thread Maksym Melnychok
simplest algo: find a node with max depth M and go up tree calculating max 
depth of all upper branches that do not contain M until reaching root node

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

2011-05-30 Thread Maksym Melnychok
wont work for this tree:

x
  /\
 x x
   /\
 x  x
  /   \
 xy
/   \
   xx
  / 
 x

max distance in left subtree is 7 and distance between left and right is 6

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



[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread ross
@piyush,
Hi, thanks alot for the solution,
Thats to find the diameter of a tree. :)
But, how would you obtain the 2 nodes which have the max. distance
betwn them?



On May 30, 1:17 pm, Vipul Kumar  wrote:
> That is same as finding the diameter of the tree.
>
>
>
>
>
>
>
> On Mon, May 30, 2011 at 1:44 PM, Piyush Sinha  
> wrote:
> > There can be two cases to it
>
> > Case 1 - The maximum distance passes through the root node.
> >    1
> >  /   \
> >    2 3
> >  /  \
> >     4    5
> >    Maximum distance is between 4 and 5 i.e. 4
>
> > Case 2 - The maximum distance lies in either of the two subtrees
>
> >     1
> >   /    \
> >  2 3
> >    /    \
> >  4  5
> >   /    \    \
> >  6  7    8
> >    / \
> >   9  10
> >  /  \
> >     11    12
>
> > Here the greatest maximum distance is between 11 and 12. i.e 8
>
> > Hence, the greatest distance between any two nodes of a tree T is the
> > largest of the following quantities:
>
> > * the greatest distance of T’s left subtree
> > * the greatest distance of T’s right subtree
> > * the longest path between leaves that goes through the root of T (this can
> > be computed from the heights of the subtrees of T)
>
> > On Mon, May 30, 2011 at 1:26 PM, ross  wrote:
>
> >> Given a binary tree(not a BST) find the 2 nodes of the binary tree
> >> which are separated by maximum distance.
> >>  By distance, we mean no. of edges in the path from node1 to node2.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > Piyush Sinha
> > IIIT, Allahabad
> > +91-8792136657
> > +91-7483122727
> >https://www.facebook.com/profile.php?id=10655377926
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

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



Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread ankit sambyal
Here's the crude algo :
First find the node having the max depth in the left sub tree and then find
the node having the max depth in the right sub tree. Ties are broken
arbitrarily.
These will be the 2 nodes separated by the maximum distance. The sum of
their depths will give us the distance


Ankit

On Mon, May 30, 2011 at 1:17 AM, Aakash Johari wrote:

> yes, it is the diameter of the tree.
>
>
> On Mon, May 30, 2011 at 1:17 AM, Vipul Kumar wrote:
>
>> That is same as finding the diameter of the tree.
>>
>> On Mon, May 30, 2011 at 1:44 PM, Piyush Sinha 
>> wrote:
>> > There can be two cases to it
>> >
>> > Case 1 - The maximum distance passes through the root node.
>> >1
>> >  /   \
>> >2 3
>> >  /  \
>> > 45
>> >Maximum distance is between 4 and 5 i.e. 4
>> >
>> > Case 2 - The maximum distance lies in either of the two subtrees
>> >
>> > 1
>> >   /\
>> >  2 3
>> >/\
>> >  4  5
>> >   /\\
>> >  6  78
>> >/ \
>> >   9  10
>> >  /  \
>> > 1112
>> >
>> > Here the greatest maximum distance is between 11 and 12. i.e 8
>> >
>> >
>> > Hence, the greatest distance between any two nodes of a tree T is the
>> > largest of the following quantities:
>> >
>> > * the greatest distance of T’s left subtree
>> > * the greatest distance of T’s right subtree
>> > * the longest path between leaves that goes through the root of T (this
>> can
>> > be computed from the heights of the subtrees of T)
>> >
>> >
>> >
>> > On Mon, May 30, 2011 at 1:26 PM, ross  wrote:
>> >>
>> >> Given a binary tree(not a BST) find the 2 nodes of the binary tree
>> >> which are separated by maximum distance.
>> >>  By distance, we mean no. of edges in the path from node1 to node2.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Algorithm Geeks" group.
>> >> To post to this group, send email to algogeeks@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> >
>> >
>> > --
>> > Piyush Sinha
>> > IIIT, Allahabad
>> > +91-8792136657
>> > +91-7483122727
>> > https://www.facebook.com/profile.php?id=10655377926
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from 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.
>>
>>
>
>
> --
> -Aakash Johari
> (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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Aakash Johari
yes, it is the diameter of the tree.

On Mon, May 30, 2011 at 1:17 AM, Vipul Kumar  wrote:

> That is same as finding the diameter of the tree.
>
> On Mon, May 30, 2011 at 1:44 PM, Piyush Sinha 
> wrote:
> > There can be two cases to it
> >
> > Case 1 - The maximum distance passes through the root node.
> >1
> >  /   \
> >2 3
> >  /  \
> > 45
> >Maximum distance is between 4 and 5 i.e. 4
> >
> > Case 2 - The maximum distance lies in either of the two subtrees
> >
> > 1
> >   /\
> >  2 3
> >/\
> >  4  5
> >   /\\
> >  6  78
> >/ \
> >   9  10
> >  /  \
> > 1112
> >
> > Here the greatest maximum distance is between 11 and 12. i.e 8
> >
> >
> > Hence, the greatest distance between any two nodes of a tree T is the
> > largest of the following quantities:
> >
> > * the greatest distance of T’s left subtree
> > * the greatest distance of T’s right subtree
> > * the longest path between leaves that goes through the root of T (this
> can
> > be computed from the heights of the subtrees of T)
> >
> >
> >
> > On Mon, May 30, 2011 at 1:26 PM, ross  wrote:
> >>
> >> Given a binary tree(not a BST) find the 2 nodes of the binary tree
> >> which are separated by maximum distance.
> >>  By distance, we mean no. of edges in the path from node1 to node2.
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> >
> >
> > --
> > Piyush Sinha
> > IIIT, Allahabad
> > +91-8792136657
> > +91-7483122727
> > https://www.facebook.com/profile.php?id=10655377926
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from 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.
>
>


-- 
-Aakash Johari
(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 algogeeks@googlegroups.com.
To unsubscribe from 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] Binary Tree Problem

2011-05-30 Thread Vipul Kumar
That is same as finding the diameter of the tree.

On Mon, May 30, 2011 at 1:44 PM, Piyush Sinha  wrote:
> There can be two cases to it
>
> Case 1 - The maximum distance passes through the root node.
>    1
>  /   \
>    2 3
>  /  \
>     4    5
>    Maximum distance is between 4 and 5 i.e. 4
>
> Case 2 - The maximum distance lies in either of the two subtrees
>
>     1
>   /    \
>  2 3
>    /    \
>  4  5
>   /    \    \
>  6  7    8
>    / \
>   9  10
>  /  \
>     11    12
>
> Here the greatest maximum distance is between 11 and 12. i.e 8
>
>
> Hence, the greatest distance between any two nodes of a tree T is the
> largest of the following quantities:
>
> * the greatest distance of T’s left subtree
> * the greatest distance of T’s right subtree
> * the longest path between leaves that goes through the root of T (this can
> be computed from the heights of the subtrees of T)
>
>
>
> On Mon, May 30, 2011 at 1:26 PM, ross  wrote:
>>
>> Given a binary tree(not a BST) find the 2 nodes of the binary tree
>> which are separated by maximum distance.
>>  By distance, we mean no. of edges in the path from node1 to node2.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Piyush Sinha
> IIIT, Allahabad
> +91-8792136657
> +91-7483122727
> https://www.facebook.com/profile.php?id=10655377926
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Piyush Sinha
There can be two cases to it

Case 1 - The maximum distance passes through the root node.

   1
 /   \
   2 3
 /  \
45

   Maximum distance is between 4 and 5 i.e. 4

Case 2 - The maximum distance lies in either of the two subtrees

1
  /\
 2 3
   /\
 4  5
  /\\
 6  78
   / \
  9  10
 /  \
1112

Here the greatest maximum distance is between 11 and 12. i.e 8


Hence, the greatest distance between any two nodes of a tree T is the
largest of the following quantities:

* the greatest distance of T’s left subtree
* the greatest distance of T’s right subtree
* the longest path between leaves that goes through the root of T (this can
be computed from the heights of the subtrees of T)


On Mon, May 30, 2011 at 1:26 PM, ross  wrote:

> Given a binary tree(not a BST) find the 2 nodes of the binary tree
> which are separated by maximum distance.
>  By distance, we mean no. of edges in the path from node1 to node2.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-05-30 Thread Sudhir mishra
give some explanation

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

2011-05-30 Thread ross
Given a binary tree(not a BST) find the 2 nodes of the binary tree
which are separated by maximum distance.
 By distance, we mean no. of edges in the path from node1 to node2.

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

2011-05-30 Thread ankit sambyal
@Nave ::  nice solution  :)  Phoda


Sambyal


On Mon, May 30, 2011 at 12:13 AM, Naveen Agrawal wrote:

> @ shubham
>
> Your solution need some changes at step 2
>
> step 1:
>sort the given numbers in the decreasing order based on their first
> digit(left most).
>
> step 2:
>if two numbers come out to be equal in the above case & both of
> their next digit exist then sort on the basis of their next digit,
>otherwise,
>the number whose next digit *is greater than last equal digit will
> come first.(i.e, n=10 m=108  ,as next digit(n->0,m->8) is greater than last
> equal digit(0), so 108 will come first ) *
>
>
>
> Naveen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: Google Interview Question

2011-05-30 Thread Maksym Melnychok
here's efficient oneliner without any string manipulation

divide every number by 10^(log10(x).ceil)
sort
convert back to original numbers
join array into string

there are edge-cases where this doesn't work but they can be dealt with 
easily - have to go back to work :)

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

2011-05-30 Thread ross
@anshu mithra:
Hi,
Thanks for clarifying! :)

On May 30, 11:06 am, anshu mishra  wrote:
> main()
> {
> for (i = 0; i < n; i++)
> {
>      for (j = 0; j < n; j++)
>      {
>             if (flag[i][[j])
>            {
>                  bfs(mat, flag, i, j);
>                  count++;
>            }
>      }}
> }
>
> bfs(mat[][], flag[][], i, j)
> while (!q.empty())
> {
> x = q.top();
> q.pop();
> if(node notvisited already && adjacent to x && value = x)
> add to queue
>
> }
> }
>
> this is thw whole code

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

2011-05-30 Thread Naveen Agrawal
@ shubham

Your solution need some changes at step 2

step 1:
   sort the given numbers in the decreasing order based on their first
digit(left most).
step 2:
   if two numbers come out to be equal in the above case & both of their
next digit exist then sort on the basis of their next digit,
   otherwise,
   the number whose next digit *is greater than last equal digit will
come first.(i.e, n=10 m=108  ,as next digit(n->0,m->8) is greater than last
equal digit(0), so 108 will come first ) *



Naveen

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

2011-05-30 Thread anshu mishra
main()
{
for (i = 0; i < n; i++)
{
 for (j = 0; j < n; j++)
 {
if (flag[i][[j])
   {
 bfs(mat, flag, i, j);
 count++;
   }
 }
}
}
bfs(mat[][], flag[][], i, j)
while (!q.empty())
{
x = q.top();
q.pop();
if(node notvisited already && adjacent to x && value = x)
add to queue
}
}

this is thw whole code

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