tag:blogger.com,1999:blog-4115025577315673827.post1422923354087585480..comments2019-12-04T14:40:09.489+05:30Comments on CSE Blog - quant, math, computer science puzzles: Traffic JamUnknownnoreply@blogger.comBlogger12125tag:blogger.com,1999:blog-4115025577315673827.post-71576191766062742752017-08-21T09:31:42.432+05:302017-08-21T09:31:42.432+05:30It would be easier if we condition on the position...It would be easier if we condition on the position of the fastest car...Lebeshttps://www.blogger.com/profile/02767398772267935545noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-52826457084513448262014-06-22T19:30:19.907+05:302014-06-22T19:30:19.907+05:30Yep. I agree. ThanksYep. I agree. ThanksPratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-20396389329479338512013-08-24T06:23:52.132+05:302013-08-24T06:23:52.132+05:30Like Sid said above, the answer is the sum of the ...Like Sid said above, the answer is the sum of the harmonic series ONLY IF the following assumptions are made. They should have been mentioned in the original puzzle question!<br /><br />1. we assume that the n cars have speeds which come from a finite set e.g (1,2,...,N)<br /><br />AND<br /><br />2. we assume that all cars have different speedsJ Leehttps://www.blogger.com/profile/01272602666631034265noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-83443944630072505122011-01-29T15:04:03.882+05:302011-01-29T15:04:03.882+05:30@wonderwice.. I do not know how I missed your comm...@wonderwice.. I do not know how I missed your comment! Amazingly simple solution. Thanks a ton :)Pratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-20857379064904160192010-05-03T16:53:34.937+05:302010-05-03T16:53:34.937+05:30Here is a simpler way to look at it:
Car number i...Here is a simpler way to look at it:<br /><br />Car number i (ith car from front) is at the head of a clump iff it is slower than all cars that were ahead of it to begin with.<br /><br />So by linearity of expectation, expected number of clumps, E_N = sum(i=1 to N)P_i<br /><br />where P_i is the probability that car number i is slower than all cars that were ahead of it to begin with.<br /><br />P_i is 1/i as the first i cars are all equally likely to be the slowest one.<br /><br />From here it directly follows that E_N = H_nwonderwicehttps://www.blogger.com/profile/11745210084404197781noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-67806344796405325902010-03-05T21:09:54.611+05:302010-03-05T21:09:54.611+05:30Solution I got from a forum:
Note that the actual...Solution I got from a forum:<br /><br />Note that the actual speed of car is not important. It is important that which car is travelling faster.<br /><br />Let X(1), X(2), ...,X(N) be a sequence of random variables over the set {1,2,...,N}, with X(i) different form X(j) if i is different from j. Here X(i) represents the speed of car i, and the set {1,2,...,N} represents the speeds of the cars. We can suppose that the cars, represented by C(1),C(2),...,C(N), are in the order given and move in the East-West (Left To Right) direction. So, if X(N)=1, then there will be exactly one clump, all moving at the speed X(N)=1 of car C(N). If X(N-1)=1, then there will be exactly two clumps, one of which is the right-most car C(N) -- a single-car clump -- having speed greater than 1. The other clump, consisting of (N-1) cars, will be moving behind the car C(N) at the speed X(N-1)=1. <br /><br />For any k in {1,2,...,N}, the probability P{X(k)=1}=(1/N). If X(k)=1, then all the cars C(1) through C(k) will form a clump and will be moving at the speed X(k)=1. Looking at the cars C(k+1) through C(N), we see that their speeds are all different and any of them can have any of the speeds with equal probability. So, it makes no difference what we assume to be the actual speeds of these cars, what matters is that they be different. So, we may just as well assume the speeds for the cars C(k+1) through C(N) to be {1,2,...,(N-k)}. Also we can rename these cars as A(1),...,A(N-k), so that A(i)=C(k+i) for i in {1,2,...,(N-k)}.<br /><br />Now let E(N) denote the expected number of clumps of N cars.<br /><br />It is obvious that E(0)=0.<br /><br />If X(k)=1, then we get 1 clump consisting of the first k cars (i.e., C(1),...,C(k)). Depending on the value of k, we get on average E(N-k) clumps for the remaining (N-k) cars that are moving ahead of the first k cars.<br /><br />So, <br /><br />E(N) = 1 + SUM{(P{X(k)=1})*E(N-k); [k,1,N]}.<br /><br />Simplifying, we get:<br /><br />E(N) = 1 + SUM{(1/N)*E(N-k); [k,1,N]},<br /><br />or<br /><br />E(N) = 1 + (1/N)*SUM{E(k); [k,1,(N-1)]}.<br /><br />We can easily show that E(N)=(1/N)+E(N-1), with E(0)=0.<br /><br />From which we get the Harmonic series E(N)=(1)+(1/2)+(1/3)+...+(1/N).<br />:)<br />Finally.. phew!! :)Pratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-76394792379550701862010-03-05T20:59:06.602+05:302010-03-05T20:59:06.602+05:30@sid. thanx..
@asad.. this is the answer you are ...@sid. thanx..<br /><br />@asad.. this is the answer you are getting if you assume uniform distribution. Just thought of an easy example. Three random numbers are chosen uniformly. What is the probability that the graph they form is a pointed one, that is /\ or \/<br />Ideally, we know its 1-(1/6)-(1/6) = 2/3 {i.e 1-prob(increasing) - prob(decreasing)}. <br />Let the three numbers be a,b,c. But once two points are chosen (say a and b), according to your method, probability that the three numbers form an increasing sequence is 1/2 {If numbers are a,b,c in order. P(c>b) = 1/2 but P(c>b|b>a) = (1/6)/(1/2) = 1/3}<br />Hence, the problem. Hope this example clarifies the problem. Thanx Sid.Pratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-24533033035296675172010-03-05T19:52:31.648+05:302010-03-05T19:52:31.648+05:30Well then it's a matter of assumptions. My app...Well then it's a matter of assumptions. My approach was to apply the uniformity principle to the speeds if no information is given. Thus if you pick any car, then the speed of any other car will be either less than it or greater with equal prob.<br />But I implement this problem in excel with speeds ranging uniformly from 1 to 1000 and checking for N=2,3,4,5 and the nos. I get do not match my solution. I guess they are closer to the HP sum solution.Asad Alihttps://www.blogger.com/profile/07133281473683565210noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-30835030923148232322010-03-05T13:48:31.617+05:302010-03-05T13:48:31.617+05:30The problem arises from the assumption that the (n...The problem arises from the assumption that the (n-1)th car has 50% prob of being at a higher speed as compared to the nth car "Irrespective" of the speed of the nth car.<br /><br />If we assume that the n cars have speeds which come from a finite set e.g (1,2,...,N) and also assume that all cars have different speeds then we get the ans as written in the book i.e 1+1/2+...+1/N (didnt prove it but verified for N=4)sidhttps://www.blogger.com/profile/04179126136399818676noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-23784103464259136002010-03-05T12:49:32.553+05:302010-03-05T12:49:32.553+05:30@Asad.. The point I raised in your solution is not...@Asad.. The point I raised in your solution is not really valid. You solution seems correct.<br /><br />I can apply recursion in the backward direction.<br /><br />Let E[n] denote expected number of clumps with n cars.<br /><br />The last car (n-1) cars would be in some clump. The nth car would form another clump if the speed is less than the speed of the clump. Else, one clump extra is formed.<br /><br />So,<br />E[n] = 0.5(E[n-1]) + 0.5(E[n-1]+1)<br />So, <br />E[n] = E[n-1] + 1/2<br /><br />But, the answer posted in books I saw is (1)+(1/2)+(1/3)+...+(1/N).<br /><br />There has to be a mistake in our solution. What is it? :(Pratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-91888000170555433792010-03-05T11:46:12.979+05:302010-03-05T11:46:12.979+05:30@Asad.. I don't think your solution is correct...@Asad.. I don't think your solution is correct. That's because when the following car is faster, sure it does not add a new clump but the speed of the following car is reduced. You have not included it in your solution.<br /><br />BTW, The answer I got was (1)+(1/2)+(1/3)+...+(1/N) and I believe its correct.Pratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-59758507445657547622010-03-05T00:17:13.849+05:302010-03-05T00:17:13.849+05:30Assume that when a faster car approaches a slower ...Assume that when a faster car approaches a slower one it starts moving at the slower speed creating a clump of two cars moving with the speed of slower car.<br />Thus a clump is created every time a slower car has a faster car following it.<br />Now assume that the front-most car has speed x. It is a clump in itself. If the car behind it is slower it will give rise to another clump of itself without ever meeting the 1st one else it will join the clump of 1st car.<br />Now assume that speed of other cars is either >x or <=x with prob. 1/2 each.<br />Thus expected no. of clumps f[N] = 0.5*[f[N-1]+1]+0.5*f[N-1] =><br />f[N] = 1+(N-1)/2Asad Alihttps://www.blogger.com/profile/07133281473683565210noreply@blogger.com