thear
BAN USER- 0of 0 votes
AnswersYou are given a function. When it is called, it returns 0 with 60% probability, and 1 with 40% probability. Now using this function, write a new function that returns 0 with 50% probability and 1 with 50% probability.
- thear| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Coding
Following is the code to generate the frog path generically(means for ne number of stone) and recursively...I havnt run the code in the complier(it may not be complete syntax compliant)...just wrote and think that it will work fine..Do tell me if there are ne issues..
Following is the concept...
Take the array as 1 1 1 1 1 as for five stones each initially represents '1'...here 1 represents that frog doesnt skip that particular stone..
and if it is 1 1 0 1 1 ..then it skips the 3rd one..
Take the following array to pass into array
a[]=[1, 1 , 1 , 1 ,1] for five stones
so call the following function-- printPathsForFrog(a,1)
printPathsForFrog(int a[],int counter)
{
for(int i=0;i<a.length;i++)
{
if(a[i]==1)
{
printf(i+1);
}
}
for(int j=counter;j<a.length-1;j++)
{
if(a[j-1]==1)
{
a[j]=0;
printPathsForFrog(a,counter++);
a[j]=1;
}
else
{
j++;
}
}
Anyways If u still not clear..lemme explain u in a more broader way..
Do the followin example practically
Take a coin.. and toss it six times..
Can u be sure that it wud give 3 heads and 3 tails.. I dont think it will give me this combination everytime(inspite both head and tail having 1/2 probability)..it may be 4 heads 2tails...and multiple cases...
So buddy we can not just take probability on these 6 tosses..rather practically we take it for infinite cases..
I hope now u get it..
I dont have any doubt.. You said everythin right.. But u got it wrong on the number of events..probability of head is 1/2 defintly..but if i toss a coin for first two times..I cant say that i wud get one head and one coin..coz probabilty covers infinite events...and there may be case i wud get two heads on first two tosses becoz its just a probabilty ..we are just guessin the measure of truth in the statemnt..thats it.. I hope you understand the probability..
- thear March 01, 2011Sorry that was wrong..
See this one..
Do the Inorder traversal ...and through the traversal keep linkin the right link of the node to its parent or grand parent or so on...
and finally link the first and the last node .. first(left link) and last's right link..
This makes ur circular linked list..
Enjoyee
Well PKT ... you got it wrong.. We always consider probability for limit -> infinity... now here you taking the limited case of 5 function calls.. ur probability just tells about the chance ...it never talks about the outcome..hence here it can give 0 on all these five calls.. but it will maintain the probability for infinity events..
For eg :
lets following be the return of the some first 15 fun6040() of infinite calls..
0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 ........
Here if we take first five calls then for 0 its 100 percent probability but on an avg i.e..15 or infinity it is 60 % i.e.. So your answer is wrong... Saurabh got it right I guess...
hey how did you applied for yahoo@bangalore..thru referral ?
- thear June 23, 2011