Re: [algogeeks] sum of subsequence

2010-07-04 Thread Anand
Here is one more approach: http://codepad.org/h0Ycg99P On Sun, Jul 4, 2010 at 7:56 PM, Ashish Goel wrote: > knapsack problem > > alternate :sort the array keep two pointers one from start one from end > > move inwards till the sum is k (move start pointer if the sum right pointer if the sum >k

Re: [algogeeks] oops

2010-07-04 Thread Raj N
For the first question answer is 2 copy constructors are called. One when you call foo(*a) and the other when you are assigning object b to *a On Sun, Jul 4, 2010 at 8:49 PM, sharad wrote: > 1)void foo(A a){} > A* a =new A(); > foo(*a); > A b=*a; > b=*a; > How many copy ctors of class A are call

Re: [algogeeks] cops n robber

2010-07-04 Thread harit agarwal
yes if one having speed greater than other then at some point of time he will catch the robber -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, se

Re: [algogeeks] shift operators

2010-07-04 Thread harit agarwal
bitwise are ony applicable to unsignedtheir behaviour is undefined on negative numbers... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, sen

Re: [algogeeks] amazon question

2010-07-04 Thread harit agarwal
in my approach a( b,c)-> this implies that nodes within parenthesis are child of a where b is left child and c is right child if there is no left child then we can use a(,c) and if there is no right child then use a(b) and if there is no child use only a -- You received this message because you

Re: [algogeeks] shift operators

2010-07-04 Thread UMESH KUMAR
On Sun, Jul 4, 2010 at 9:07 PM, jalaj jaiswal wrote: > how do we perform left shift and right shift on negative numbers.. > > for eg -1<<3 > >if negative number is shifted left (<<) then vacent space is filled by 0's and right sift (<<) then vacents space is filled by sign bits

Re: [algogeeks] Re: number of 1's

2010-07-04 Thread Ashish Goel
in general, preprocessing is preferred over run time calculation hence i would have he number of bits on a platform known/calculated upfront and then use the log n algo Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Mon, Jul 5, 2010 at 9:16 AM

Re: [algogeeks] graphs again

2010-07-04 Thread Ashish Goel
i would prepare the transitivity matrix while inserting the edge into the matrix the search then would be a O(1) Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Jul 4, 2010 at 3:15 PM, jalaj jaiswal wrote: > A graph is given. You need to

Re: [algogeeks] Re: number of 1's

2010-07-04 Thread Rahul Kushwaha
@ashish : you are correct but the number of bits in the integer datatype is fixed while using anding algo.. but the looping algorithm is valid for any number of bit in the integer.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to t

Re: [algogeeks] Re: C declaration

2010-07-04 Thread Rahul Kushwaha
this type of error is prominent in turbo c compilers.. but above mentioned c99,gcc and many other allow mixing of declarations.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.c

Re: [algogeeks] Re: impossible microsoft puzzle

2010-07-04 Thread manoj janoti
If all the men gusses the same number then the solution could be wrong. for example the the value of N is 5 and numbers given are 1,2,1,1,1 and everybody guesses 4 then the solution is wrong. A different solution is like - All men will stand in a row and and everybody can think of his hat number

Re: [algogeeks] Re: number of 1's

2010-07-04 Thread Ashish Goel
the looping algo in the worst case can be o(n) whereas the anding with 0x555 and so on is a log n algo :) Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Jul 4, 2010 at 10:21 AM, shrinivas yadav wrote: > it is easy > int count =0; > take inp

Re: [algogeeks] Re: n-ary

2010-07-04 Thread Ashish Goel
additionally the space usage can be optimized by using adjacency list Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Jul 4, 2010 at 11:49 AM, ashgoel wrote: > wouldn't the inorder and postorder traversals sufficient? save the > inorder and

Re: [algogeeks] sum of subsequence

2010-07-04 Thread Ashish Goel
knapsack problem alternate :sort the array keep two pointers one from start one from end move inwards till the sum is k (move start pointer if the sum k Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Jul 4, 2010 at 11:46 PM, jalaj jaiswal

[algogeeks] Re: C declaration

2010-07-04 Thread Gene
On Jul 4, 2:38 pm, Faadu wrote: > In c , it is necessary to declare all variables at the beginning of > the program. > But surprisingly we can declare a variable anywhere within the code > using gcc compiler. > Can anyone explain me the reason for this strange behavior ?? C99 and C++ both allow d

[algogeeks] oops contd

2010-07-04 Thread sharad
1)in singleton class how will u delete the obj ? 2)what happens if I throw exception from destructor. can I throw exception from construtor and destructor ? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to

[algogeeks] shift operators

2010-07-04 Thread jalaj jaiswal
how do we perform left shift and right shift on negative numbers.. for eg -1<<3 -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to al

[algogeeks] sum of subsequence

2010-07-04 Thread jalaj jaiswal
find the subsequence in an array which sum to k -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubs

Re: [algogeeks] 0 and 1 again :)

2010-07-04 Thread Nikhil Jindal
Hello Jalaj, I am not sure whether I have understood your approach corectly, but do you want to say that you will always get a subsequence with number of terms equal to twice the min(count0, count1)? Consider for ex: 00 The longest subsequence is 01 or 10, both of length 2(and none of length

Re: [algogeeks] C declaration

2010-07-04 Thread jalaj jaiswal
c doesn't have any declaration section like pl/sql On Mon, Jul 5, 2010 at 12:08 AM, Faadu wrote: > In c , it is necessary to declare all variables at the beginning of > the program. > But surprisingly we can declare a variable anywhere within the code > using gcc compiler. > Can anyone explain m

Re: [algogeeks] Re: impossible microsoft puzzle

2010-07-04 Thread Nikhil Jindal
Hello All, Since duplicates are allowed, the fact that I can see the number on others hat is of no significance to me. My guess with this information is as good without it. Hence, I will consider the situation as: I am sitting alone in a dark room and I am given a hat with a number from 1 to N. I

[algogeeks] Re: numbers

2010-07-04 Thread Gene
On Jul 4, 6:31 am, jalaj jaiswal wrote: > There is very long array of ints, and you are given pointer to base addr of > this array.. each int is 16bit representation... you need to return the > pointer to tht "bit" inside array where longest sequence of "1"s start > for example. if your array has

[algogeeks] C declaration

2010-07-04 Thread Faadu
In c , it is necessary to declare all variables at the beginning of the program. But surprisingly we can declare a variable anywhere within the code using gcc compiler. Can anyone explain me the reason for this strange behavior ?? -- You received this message because you are subscribed to the Goo

[algogeeks] Re: impossible microsoft puzzle

2010-07-04 Thread Dave
But everyone guesses simultaneously. I take it to mean that no one knows anyone else's guess when making his own. Dave On Jul 4, 2:01 am, agnibha nath wrote: > can it be like... one person sees any other person's number and > guesses it first. then, everybody else guesses the same number. this >

Re: [algogeeks] Yahoo

2010-07-04 Thread ashish agarwal
it will be 1:1 because probability of guy is 1/2+1/2*1/2+1/2*1/2*1/2.=1 and girls and boys has same probability On Sun, Jul 4, 2010 at 6:00 AM, jalaj jaiswal wrote: > yeah 1:1 > > On Sun, Jul 4, 2010 at 4:57 PM, Amit Jaspal wrote: > >> it will be 1:1 >> >> >> On Sun, Jul 4, 2010 at 4:50 PM,

Re: [algogeeks] Download Full Movies Hot Type +18

2010-07-04 Thread Anil C R
somebody kick this guy out!! Anil On Sun, Jul 4, 2010 at 9:48 PM, wrote: > Download Full Movies Hot Type +18 > > http://bit.ly/cWhJJk > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@g

[algogeeks] Download Full Movies Hot Type +18

2010-07-04 Thread mailar
Download Full Movies Hot Type +18 http://bit.ly/cWhJJk -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@goo

[algogeeks] oops

2010-07-04 Thread sharad
1)void foo(A a){} A* a =new A(); foo(*a); A b=*a; b=*a; How many copy ctors of class A are called? 2)When C++ compiler can't generate default = operator for the class? 3)what all errors is possible if u write past the array bounds -- You received this message because you are subscribed to the

Re: [algogeeks] google

2010-07-04 Thread topojoy biswas
a linked list with pointer to the head and tail stored containing each request response tuple, and the pointers to the tuple stored in a hashtable described below. a hash table of size n containing the hash of the request identifier as the hashfunction, and the pointer to the element in the linke

Re: [algogeeks] Yahoo

2010-07-04 Thread jalaj jaiswal
yeah 1:1 On Sun, Jul 4, 2010 at 4:57 PM, Amit Jaspal wrote: > it will be 1:1 > > > On Sun, Jul 4, 2010 at 4:50 PM, Jitendra Kushwaha < > jitendra.th...@gmail.com> wrote: > >> it will be half... >> >> >> On Sun, Jul 4, 2010 at 4:18 PM, Piyush Verma <114piy...@gmail.com> wrote: >> >>> In a village

[algogeeks] هيفاء وهبي في

2010-07-04 Thread mailar
الحمام http://bit.ly/cWhJJk هيفاء وهبي في  [1] --- الحمام الحمام الحمام هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي في  هيفاء وهبي

[algogeeks] هيفاء وهبي فيلمها الا باحي

2010-07-04 Thread mailar
[1][2][3][4]هيفاء وهبي فيلمها الاباحي[5]او http://bit.ly/cWhJJk هيفاء وهبي فيلمها الاباحي[6] هيفاء وهبي فيلمها الاباحي[7] هيفاء وهبي فيلمها الاباحي[8] هيفاء وهبي فيلمها الاباحي[9] هيفاء وهبي فيلمها الاباحي[10] هيفاء وهبي فيلمها الاباحي[11] هيفاء وهبي فيلمها الاباحي[12] هيفاء وهبي في

Re: [algogeeks] Re: Yahoo

2010-07-04 Thread karthik m
@peeyush: the ratio is based on probability, it will be 1:1. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...

Re: [algogeeks] Re: Yahoo

2010-07-04 Thread Jitendra Kushwaha
ya i mean half girl and half boys i.e. 1:1 ratio of boys to girl On Sun, Jul 4, 2010 at 5:25 PM, peeyush wrote: > It can not be determined. > > On Jul 4, 4:27 pm, Amit Jaspal wrote: > > it will be 1:1 > > > > On Sun, Jul 4, 2010 at 4:50 PM, Jitendra Kushwaha > > wrote: > > > > > it will be hal

Re: [algogeeks] merge sorted lists

2010-07-04 Thread Raajay
According to the problem there should be 'n * k' elements in all (on an average). For merging all the elements into a single list one has to look at all the elements at least once. (For eg in case of merging two lists of size n1 and n2, the worst case complexity in O(n1 + n2)). Extending to the mu

[algogeeks] Re: Yahoo

2010-07-04 Thread peeyush
It can not be determined. On Jul 4, 4:27 pm, Amit Jaspal wrote: > it will be 1:1 > > On Sun, Jul 4, 2010 at 4:50 PM, Jitendra Kushwaha > wrote: > > > it will be half... > > > On Sun, Jul 4, 2010 at 4:18 PM, Piyush Verma <114piy...@gmail.com> wrote: > > >> In a village in each family they give bir

Re: [algogeeks] Yahoo

2010-07-04 Thread Amit Jaspal
it will be 1:1 On Sun, Jul 4, 2010 at 4:50 PM, Jitendra Kushwaha wrote: > it will be half... > > > On Sun, Jul 4, 2010 at 4:18 PM, Piyush Verma <114piy...@gmail.com> wrote: > >> In a village in each family they give birth to children till they >> get a boy. IF girl child they try again. What is t

Re: [algogeeks] Yahoo

2010-07-04 Thread Jitendra Kushwaha
it will be half... On Sun, Jul 4, 2010 at 4:18 PM, Piyush Verma <114piy...@gmail.com> wrote: > In a village in each family they give birth to children till they > get a boy. IF girl child they try again. What is the ratio of boys to > girls. > > -- > You received this message because you are sub

[algogeeks] Yahoo

2010-07-04 Thread Piyush Verma
In a village in each family they give birth to children till they get a boy. IF girl child they try again. What is the ratio of boys to girls. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@goog

Re: [algogeeks] Re: isbst

2010-07-04 Thread sharad kumar
@dheeraj for this tree inorder is 12 14 13 first 12 comes,it is saved in temp now 14 comes since 14>12 so temp =14 now when 13 comes which is less than temp hence not a bst correct me if i wrong -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.

[algogeeks] numbers

2010-07-04 Thread jalaj jaiswal
There is very long array of ints, and you are given pointer to base addr of this array.. each int is 16bit representation... you need to return the pointer to tht "bit" inside array where longest sequence of "1"s start for example. if your array has following in bit representation: ,0111,0011,1

Re: [algogeeks] 2_D matrix

2010-07-04 Thread jalaj jaiswal
@amir ..could you please provide a rough pseudocode for it... :-? On Sun, Jul 4, 2010 at 3:12 AM, Amir hossein Shahriari < amir.hossein.shahri...@gmail.com> wrote: > @jalaj: oops! i'm sorry but by diameter i meant diagonal! > > binary search on the diagonal 0 4 10 14 the result is 4<9<10 > so the

Re: [algogeeks] Re: merge sorted lists

2010-07-04 Thread jalaj jaiswal
@sharad in the first step you will have to merge k lists each of n size .. you will mwrge 2 at a time wouldn't that be O(n*k/2) so t(n)=n(k/2)+n(k/4)+.. correct me if i'm wrong anyways On Sun, Jul 4, 2010 at 9:56 AM, Dave wrote: > > @Sharad. Haven't you changed the roles of

[algogeeks] graphs again

2010-07-04 Thread jalaj jaiswal
A graph is given. You need to design a data structure with minimum space complexity such that it does the follows --> Finds whether nodes u and v have a path in between them in O(1) time. --> Finds whether there is a path of length k between u and v in O(k) time. The same data structure to be used

[algogeeks] 0 and 1 again :)

2010-07-04 Thread jalaj jaiswal
You are given an array ' containing 0s and 1s. Find O(n) time and O(1) space algorithm to find the maximum sub sequence which has equal number of 1s and 0s. Examples 1) 10101010 The longest sub sequence that satisfies the problem is the input itself 2)1101000 The longest sub sequence that satisfi

Re: [algogeeks] Re: merge sorted lists

2010-07-04 Thread sharad kumar
@dave u r rite its my fault -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more optio

Re: [algogeeks] Re: isbst

2010-07-04 Thread Raj N
@Dheeraj: It would return false. Initially temp=12, next temp=14, then it'll compare 13 wrote: > @Raj N > It won't work for the tree like. your method would return true for the > following tree. > > 13 > / > 12 >\ >14 > > > > > On Sat, Jul 3, 2010 at 3:45 AM, Raj N wrote: > >> A

Re: [algogeeks] Re: number of 1's

2010-07-04 Thread Rahul Kushwaha
no of bits set int v; int c; for(c=0;v;c++) v&=v-1; this is best method without consideration of no of bits in an integer and for executes only the number of times the bit is set in the number// -- You received this message because you are subscribed to the Google Groups "Algorithm

[algogeeks] Re: impossible microsoft puzzle

2010-07-04 Thread agnibha nath
can it be like... one person sees any other person's number and guesses it first. then, everybody else guesses the same number. this way, atleast one guesses it right, since there is no boundation on the no. of wrong guesses. On Jul 3, 11:10 pm, jalaj jaiswal wrote: > N people team up and decide