Re: [algogeeks] Re: ARICENT PATTERN

2012-02-26 Thread vivek kumar
hey guys any one have idea about aricent online paper ..
plzzz tell me thankss

On Sat, Feb 25, 2012 at 8:25 PM, vivek kumar kumarvivek1...@gmail.comwrote:

 can u provide me some question


 On Thu, Feb 23, 2012 at 1:59 AM, saurabh tripathi sonu6...@gmail.comwrote:

 Question in each section varies from 20-25.If u clear this round u
 have 95% chances because after this round there will b no elimination round.
So, all the best.


 On Wed, Feb 22, 2012 at 10:51 AM, vivek kumar 
 kumarvivek1...@gmail.comwrote:

 thanks bro ...
 plz tell me no of question in each section

 --
 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: ARICENT PATTERN

2012-02-26 Thread sunny agrawal
this is not the right place to ask such queries

On Sun, Feb 26, 2012 at 5:38 PM, vivek kumar kumarvivek1...@gmail.comwrote:

 hey guys any one have idea about aricent online paper ..
 plzzz tell me thankss

 On Sat, Feb 25, 2012 at 8:25 PM, vivek kumar kumarvivek1...@gmail.comwrote:

 can u provide me some question


 On Thu, Feb 23, 2012 at 1:59 AM, saurabh tripathi sonu6...@gmail.comwrote:

 Question in each section varies from 20-25.If u clear this round u
 have 95% chances because after this round there will b no elimination round.
So, all the best.


 On Wed, Feb 22, 2012 at 10:51 AM, vivek kumar 
 kumarvivek1...@gmail.comwrote:

 thanks bro ...
 plz tell me no of question in each section

 --
 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.




-- 
Sunny Aggrawal
B.Tech. V 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: ARICENT PATTERN

2012-02-26 Thread rahul sharma
even i was banned arlier for these typ of queries

On Sun, Feb 26, 2012 at 5:39 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 this is not the right place to ask such queries

 On Sun, Feb 26, 2012 at 5:38 PM, vivek kumar kumarvivek1...@gmail.comwrote:

 hey guys any one have idea about aricent online paper ..
 plzzz tell me thankss

 On Sat, Feb 25, 2012 at 8:25 PM, vivek kumar kumarvivek1...@gmail.comwrote:

 can u provide me some question


 On Thu, Feb 23, 2012 at 1:59 AM, saurabh tripathi sonu6...@gmail.comwrote:

 Question in each section varies from 20-25.If u clear this round u
 have 95% chances because after this round there will b no elimination 
 round.
So, all the best.


 On Wed, Feb 22, 2012 at 10:51 AM, vivek kumar kumarvivek1...@gmail.com
  wrote:

 thanks bro ...
 plz tell me no of question in each section

 --
 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.




 --
 Sunny Aggrawal
 B.Tech. V 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.


-- 
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 question

2012-02-26 Thread Dumanshu
You are assuming is to be a binary tree, its not. Some nodes will
share a common pour.

On Feb 25, 9:24 pm, atul anand atul.87fri...@gmail.com wrote:
 i guess this would work...
 n=number of nodes
 h=height;
 pour=quantity poured;
 capacity = capacity of each cup

 n=pow(2,h+1) -1;
 call(capacity,pour,0,n)

 node* fillCup(float capacity,float pour,int left,int right)
 {
 node *root;
 int mid;
 if(left  right)
 return NULL;

 root=(node *)malloc(sizeof(node));
 if(left==right)
 {
 if(pour =capacity)
 root-data=capacity;
 else
 root-data=pour;
 root-left=root-right=NULL;}

 else
 {
 mid=left+(right-left)/2;
 if(pour = capacity)
 {
 root-data=capacity;
 pour=pour-capacity;
 pour=pour/2;}

 else
 {
 root-data=pour;
 root-left=root-right=NULL;
 return root;

 }

 root-left=fillCup(capacity,pour,left,mid-1);
 root-right=fillCup(capacity,pour,mid+1,right);

 }

 return root;

 }

 On Sat, Feb 25, 2012 at 5:05 PM, Ravi Ranjan ravi.cool2...@gmail.comwrote:







  |_|
  |_| |_|
  |_| |_| |_|
  |_| |_| |_| |_|
  |_| |_| |_| |_| |_|

  Each cup has capacity C and once a cup gets full, it drops half extra
  amount to left child and half extra amount to right child

  for Eg : let' first cups get 2C amount of liquid then extra amount C(2C-C)
  will be divided equally to left and right child cup of next level

  i.e. C/2 to left child and C/2 to right child

  Write a function which takes input parameter as amount of liquid poured at
  top (L) and height of particular cup (h) index of that cup (i) and it
  should return amount of liquid absorbed in that cup.

  source

 http://www.careercup.com/question?id=12770661

  whats exactly the qestion???

  --
  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] Pbm with rand() function

2012-02-26 Thread karthikeya s
RAND() func  returns value between 1 to INTMAX, as we know. But when
smone tries to find out value between 1 to N he takes remainder of o/p
of RAND() with N and adds one..but isn't it wrong coz RAND() will
generate numbers with equal probability between 1 and INTMAX but
taking remainder can alter the prob. of generating numbers.
e.g.

INTMAX=50
N=30
RAND(50) gives numbers 1 to 30, then prob. will remain same but if it
gives numbers 31 to 50, they'll be mapped to the numbers 1 to 20,
which means probability of getting numbers 1 to 20 is more than the
probability for 21 to 30.

-- 
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: Pbm with rand() function

2012-02-26 Thread Dave
@Karthikeya: Doesn't rand() actually return numbers in the range 0 to
RANDMAX? Proceeding as if that is the case:

If N is much smaller than RANDMAX, the process probably works well
enough for most applications, but if you want numbers as good as the
numbers rand() generates, do the following:

int random(int N)
{
int m = (RANDMAX / N) * N
while(1)
{
k = rand();
if( k  m ) break;
}
return k % N + 1;
}

This rejects the values of rand() that would skew the result. In your
example, m = 30, so if rand() generates a number greater than or equal
to 30, rand() is called again. The loop terminates with probability 1
if rand() truly generates uniformly distributed numbers between 0 and
RANDMAX. The average number of calls is

ceiling((double)RANDMAX / (double)((int)(RANDMAX/N)*N)),

so in your example, it would be 50/30 = 5/3.

Dave

On Feb 26, 10:10 am, karthikeya s karthikeya.a...@gmail.com wrote:
 RAND() func  returns value between 1 to INTMAX, as we know. But when
 smone tries to find out value between 1 to N he takes remainder of o/p
 of RAND() with N and adds one..but isn't it wrong coz RAND() will
 generate numbers with equal probability between 1 and INTMAX but
 taking remainder can alter the prob. of generating numbers.
 e.g.

 INTMAX=50
 N=30
 RAND(50) gives numbers 1 to 30, then prob. will remain same but if it
 gives numbers 31 to 50, they'll be mapped to the numbers 1 to 20,
 which means probability of getting numbers 1 to 20 is more than the
 probability for 21 to 30.

-- 
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: Pbm with rand() function

2012-02-26 Thread karthikeya s
int m = (RANDMAX / N) * N
isn't m= RANDMAX simplyit couldn't understand the what is the
logic here.

-- 
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] generate random number

2012-02-26 Thread karthikeya s
Assuming we have an implementation of RANDOM(0.1), how can we
implement RANDOM(a.b) - i.e. given we have a function that returns 0
OR 1 both with a probability of 1/2, how can we implement a function
that returns integers from a to b (b  a), all with a probability of 1/
n, where n = (b-a+1)

my soln:
1.we can run random(0,1) b-a timesand sum up all the values
generatedthat is what i thought...but smone told me that
it is not correct coz sum follows binomial distribution, thus don't
have equally like chance

2.on some site:

RANDOM(a,b)
range = b - a;
d = the number of binary bits %range has
do
for(i = 1 to d):
i th bit of integer res = rand(0,1);
while(res range);
return (a + res);

Each time of while loop need O(log(b-a)) time, and the expectation of
that while loop is constant. Therefore, it takes time O(log(b-
a))..how does he say that expectation of that while loop is
constantm weak with probability.plz enlighten me

-- 
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: Constructing Binary Tree from a sorted Doubly Linked List

2012-02-26 Thread Gene
One way to think about it: Given an input list with n items, consume
the first ceiling((n-1)/2)=floor(n/2) items building the left
subtree.  Then consume the next item to use for the new tree root.
Then consume the rest of the elements, which number n - floor(n/2) - 1
to build the right subtree.

If n = 0, you have the base case, which is to return the empty tree.

As code:

// Convert the sorted list of n elements with head pointer (*head) to
a bst and return the root.
NODE *sorted_list_to_bst(NODE **head, int n)
{
  if (n == 0) return NULL;
  NODE *left_subtree = sorted_list_to_bst(head, n / 2);
  NODE *root = *head;  // head is now the root
  *head = (*head)-next;  // consume head
  NODE *right_subtree = sorted_list_to_bst(head, n - n/2 - 1)
  root-prev = left_subtree; // using prev/next for left/right child
  root-next = right_subtree;
  return root;
}

NODE *convert(NODE *head)
{
  int n = 0;
  for (NODE *p = head; p; p = p-next) n++;
  return sorted_list_to_bst(head, n);
}

This turns out to be an O(n) algorithm.
On Feb 25, 5:24 pm, Supraja Jayakumar suprajasank...@gmail.com
wrote:
 Hi All

 A sorted doubly linked list is given. We are asked to construct a balanced
 binary tree.

 I have designed an n^2 solution. Kindly comment on it and also suggest
 possible improvements and definitely let me know if something is wrong.

 Btree* ConstructTreeFromDLList(DLList *dll) {

 // Assuming there is a head and tail
 DLLNode *head = dll-head;
 DLLNode *tail = dll-tail;

 Btree *root = BuildTree(DLList *dll, head, tail);
 return root;

 }

 Btree * BuildTree(DLList *dll, DLLNode * head, DLLNode *tail) {
 // Find mid node using two pointers from head and tail.
 // Boundary cases - no head ? no tail ? - handle here.
 Node *this = head;
 Node *that = tail;
 int mid = 0;
 while(this != that  || this-prev != that || that-next != this) {        //
 Until they have not crossed
         this=this-next;
         that=that-prev;
 mid++;}

 printf(“Mid Node Index=%d \n”, mid);
 BTree *root = this = that;
 root-left = BuildTree(head, that-prev);
 root-right = BuildTree(this-next, tail);
 return root;

 }

 Thank You
 Supraja J
 --
 U

-- 
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: google question

2012-02-26 Thread Ravi Ranjan
@all
same doubt qstn appears to be of binary tree DS
but the diagram given in between qstn is not like Binary tree  so
sharing is there

so how sharing is done plz explain??

-- 
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: Pbm with rand() function

2012-02-26 Thread Dave
@Karthikeya: Integer division truncates. So m is the largest multiple
of N that is less than or equal to RANDMAX. E.g., in your example, m =
(50 / 30) * 30 = 1 * 30 = 30, since 50/30 truncates to 1.

Dave

On Feb 26, 12:33 pm, karthikeya s karthikeya.a...@gmail.com wrote:
 int m = (RANDMAX / N) * N
 isn't m= RANDMAX simplyit couldn't understand the what is the
 logic here.

-- 
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: generate random number

2012-02-26 Thread Dave
@Karthikeya: You accept that your for-loop generates a random integer
between 0 and 2^d - 1, right? Then take a look at
http://en.wikipedia.org/wiki/Rejection_sampling. Basically, you reject
any random integer that exceeds b-a. The probability that you reject a
number is 1 - (b - a + 1) / (2^d - 1). Call this r. Then the average
number of integers rejected is r + r^2 + r^3 + ... = r / (1 - r), so
the average number of integers required to produce one [a, b] sample
is 1 + r / (1 - r) = 1 / (1 - r) = (2^d - 1) / (b - a + 1).

Dave

On Feb 26, 12:40 pm, karthikeya s karthikeya.a...@gmail.com wrote:
 Assuming we have an implementation of RANDOM(0.1), how can we
 implement RANDOM(a.b) - i.e. given we have a function that returns 0
 OR 1 both with a probability of 1/2, how can we implement a function
 that returns integers from a to b (b  a), all with a probability of 1/
 n, where n = (b-a+1)

 my soln:
 1.we can run random(0,1) b-a timesand sum up all the values
 generatedthat is what i thought...but smone told me that
 it is not correct coz sum follows binomial distribution, thus don't
 have equally like chance

 2.on some site:

 RANDOM(a,b)
 range = b - a;
 d = the number of binary bits %range has
 do
 for(i = 1 to d):
 i th bit of integer res = rand(0,1);
 while(res range);
 return (a + res);

 Each time of while loop need O(log(b-a)) time, and the expectation of
 that while loop is constant. Therefore, it takes time O(log(b-
 a))..how does he say that expectation of that while loop is
 constantm weak with probability.plz enlighten me

-- 
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: Pbm with rand() function

2012-02-26 Thread karthikeya s
oh my bad.really nice concept+1 dave.

-- 
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: Pbm with rand() function

2012-02-26 Thread amrit harry
@dave +1.. :)

On Mon, Feb 27, 2012 at 10:55 AM, karthikeya s karthikeya.a...@gmail.comwrote:

 oh my bad.really nice concept+1 dave.

 --
 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.




-- 
AMRIT

-- 
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: google question

2012-02-26 Thread atul anand
@Ravi: checkout this code...i have created tree where there is sharing of
nodes..

here is my code :-
please let me know is case you find any bug.

#includestdio.h

typedef struct tree{
int idx;
float data;
struct tree *left;
struct tree *right;

}node;

node *createNode(int index)
{

node *temp;

temp=(node *)malloc(sizeof(node));
temp-idx=index;
temp-data=0.0;
temp-left=temp-right=NULL;

return temp;

}

void inorder(node *root)
{
if(root!=NULL)
{
inorder(root-left);
printf(%d ) %f \n,root-idx,root-data);
inorder(root-right);


}

}

node* fillCup(node *root,float pour,float capacity)
{
float temp;
if(root==NULL)
return NULL;

if(root-data+pour = capacity)
{
if(root-data==0)
{
root-data=capacity;
pour=pour-capacity;
}
else
{
temp=capacity-(root-data);
root-data=capacity;
pour=pour-temp;
if(pour==0)
{
return root;
}

}
}
else
{
root-data+=pour;
return root;

}

fillCup(root-left,pour/2,capacity);
fillCup(root-right,pour/2,capacity);
}

int main()
{
node *root;
float pour,capacity;
root=createNode(1);//1
root-left=createNode(2);//2
root-right=createNode(3);//3
root-left-left=createNode(4);//4
root-left-left-left=createNode(7);//7
root-right-right=createNode(6);//6
root-right-right-right=createNode(10);//10
root-left-right=createNode(5);//5
root-right-left=root-left-right;
root-left-left-right=createNode(8); // 8
root-left-right-left=root-left-left-right;
root-left-right-right=createNode(9);//9
root-right-right-left=root-left-right-right;
printf(\nEnter capacity = );
scanf(%f,capacity);
printf(\nEnter quantity poured = );
scanf(%f,pour);
fillCup(root,pour,capacity);
printf(\nPrinting tree\n\n);
inorder(root);
printf(\n\n);
return 1;

}

-- 
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.