@Ankur: Since the list is of infinite length, equal probability of selecting any given node is impossible. The probability distribution must be such that
inf sum p(i) = 1. i = 0 I.e., the individual probabilities must form a convergent series, and thus p(i) --> 0. But a uniform distribution has each p(i) = c for some nonzero constant c. This is a contradiction. Dave On Dec 24, 2:20 am, Ankur Garg <[email protected]> wrote: > The thing is ..will it ascertain that the probability is equal > > I am not sure how ur method guarantees that... > May be if you and Dave can explain the algo a bit better that wud be great . > > regards > Ankur > > On Sat, Dec 24, 2011 at 5:48 AM, Piyush Kansal <[email protected]>wrote: > > > > > Hey Ankur, > > > What is the order of time complexity we are looking for in this case. The > > option which Dave suggested can give us random node by traversing that many > > number of nodes from the head. That will be O(n). > > > This can be further reduced to n/2 if we use two pointers, both of which > > will traverse two nodes at a time: > > 1. one pointing to first node (lets call it odd pointer) > > 2. other pointing to second node (lets call it even pointer) > > > So, depending on the value returned by random number generator(even or > > odd), we can decide which pointer to pick. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To view this discussion on the web visit > >https://groups.google.com/d/msg/algogeeks/-/N-5i9YH4AkYJ. > > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
