Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sameer.mut...@gmail.com
@sagar: The question says Algo should be in place. So use of an array to print the right border of tree is not advisable. We can do it recursively without using an array also . On Sat, Jul 16, 2011 at 10:48 PM, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: @sagar: There is one flaw in

Re: [algogeeks] What is the output of the following program? Why?

2011-07-17 Thread Shubham Maheshwari
i wasnt sure abt the first part of it. the one with multiple initializations ... :P On Sun, Jul 17, 2011 at 3:09 AM, sagar pareek sagarpar...@gmail.com wrote: Well shubham if you know about the unions very well then why u asked this question? On Sun, Jul 17, 2011 at 2:27 AM, Shubham

Re: [algogeeks] Re: Finding the Kth Prime

2011-07-17 Thread Shubham Maheshwari
@Dave: could you please extrapolate on the 'sequence point rule' a bit more. i am nt familiar with it ... On Sun, Jul 17, 2011 at 3:01 AM, Dave dave_and_da...@juno.com wrote: @Anthony: Your code violates the sequence point rule, which states that the value of a variable can change at most one

[algogeeks] Reverse a List with Recursion

2011-07-17 Thread Navneet Gupta
Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Ankur Khurana
int reverse(node * tmp) { static int i; // couti ; i++; if(tmp==NULL) { return 0; } if((tmp-next)==NULL) { head=tmp; i--; return 0; } if((tmp-next)!=NULL) { reverse(tmp-next); (tmp-next)-next=tmp;

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-17 Thread sagar pareek
OK... suppose our tree is 5 /\ 4 6 / \ 3 7 / \ 2 8

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread vaibhav shukla
struct node *reverse_recurse(struct node *start) { if(start-next) { reverse_recurse(start-next); start-next-next=start; return(start); } else { head=start; } } in main if(head) { temp = reverse_recurse(head); temp-next =NULL; } head and

[algogeeks] Free memory

2011-07-17 Thread Ankur Khurana
Can we do this ? int i=12; free(i); Regards, Ankur Khurana Computer Science , 4th year Netaji Subhas Institute Of Technology Delhi. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-17 Thread saurabh singh
9 1 is analogous to 1 9...And the question requires only two nodes,it does not says about all such pairs. On Sun, Jul 17, 2011 at 2:52 PM, sagar pareek sagarpar...@gmail.com wrote: OK... suppose our tree is 5 /\

[algogeeks] Re: Free memory

2011-07-17 Thread Ankur Khurana
more generally what is the memory structure of local , global and runtime allocated variable . I guess , runtime allocation is done from memory heap , local goes in to a stack . What about global ? On Sun, Jul 17, 2011 at 2:57 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Can we do this ?

Re: [algogeeks] Free memory

2011-07-17 Thread saurabh singh
Obviously you can't free the memory allocated in stack.The compiler won't call an error but once the code is executed it will cause run time error. On Sun, Jul 17, 2011 at 2:57 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Can we do this ? int i=12; free(i); Regards, Ankur

Re: [algogeeks] Re: Free memory

2011-07-17 Thread saurabh singh
Global too goes to stack,the data stack.Static variables also go to the stack.That's how they retain their values during function calls. On Sun, Jul 17, 2011 at 3:02 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: more generally what is the memory structure of local , global and runtime

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread sagar pareek
This can be done like this 1. find out the height of the tree 2. make the number of arrays(node* pointers)=height of tree 3. traverse the tree from root as arr0[0]=root; arr1[0]=root-left; arr1[1]=root-right arr2[0]=arr1[0]-left arr2[1]=arr1[1]-right . . . and so on note:-

Re: [algogeeks] Re: Free memory

2011-07-17 Thread Ankur Khurana
local stack is different and global is different ? and runtime memory is going to memory heap that i know. Saurabh : above snippet does not give runtime error. On Sun, Jul 17, 2011 at 3:04 PM, saurabh singh saurab...@gmail.com wrote: Global too goes to stack,the data stack.Static variables

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Nishant Mittal
void rev_recursion(NODE **head) { if(*head==NULL) return; NODE *first, *rest; first=*head; rest=first-next; if(!rest) return; rev_recursion(rest); first-next-next=first; first-next=NULL; *head=rest; } On Sun, Jul 17, 2011 at 2:53 PM, vaibhav shukla

Re: [algogeeks] Counting the ways.

2011-07-17 Thread surender sanke
i have an idea of changing each row to decimal equilant so we have an array of size n each array element has logn bits, resetting each all bits except one everytime and checking for AND of all n array it should take maximum of O(logn)^n. improvements or ideas are welcome surender On Sat, Jul 16,

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sagar pareek
@reynaled :- Happy to help @Sameer :- Thanks for pointing out and i think all you guyz now can optimize it :) On Sun, Jul 17, 2011 at 11:35 AM, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: @sagar: The question says Algo should be in place. So use of an array to print the right border

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-17 Thread sagar pareek
OK On Sun, Jul 17, 2011 at 2:59 PM, saurabh singh saurab...@gmail.com wrote: 9 1 is analogous to 1 9...And the question requires only two nodes,it does not says about all such pairs. On Sun, Jul 17, 2011 at 2:52 PM, sagar pareek sagarpar...@gmail.comwrote: OK... suppose our tree is

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sourabh jakhar
hey today ms visited our campus they asked simple 10 c output in first round and than 45 minutes coding round one question on test case on notepad,design bigint class,one simple question on array. On Sun, Jul 17, 2011 at 3:42 PM, sagar pareek sagarpar...@gmail.com wrote: @reynaled :- Happy to

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sagar pareek
Yeah best of luck saurabh whaen results will be out? On Sun, Jul 17, 2011 at 3:47 PM, sourabh jakhar sourabhjak...@gmail.comwrote: hey today ms visited our campus they asked simple 10 c output in first round and than 45 minutes coding round one question on test case on notepad,design bigint

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread sagar pareek
This can be done using single array too... :) :) Do anybody wants the code? On Sun, Jul 17, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com wrote: This can be done like this 1. find out the height of the tree 2. make the number of arrays(node* pointers)=height of tree 3. traverse the

Re: [algogeeks] Re: Free memory

2011-07-17 Thread saurabh singh
Machine/OS? I am pretty sure it will give. On Sun, Jul 17, 2011 at 3:09 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: local stack is different and global is different ? and runtime memory is going to memory heap that i know. Saurabh : above snippet does not give runtime error. On Sun,

Re: [algogeeks] Re: Free memory

2011-07-17 Thread vaibhav shukla
yups it will give segmentation fault u should only free the memory allocated dynamically(heap) On Sun, Jul 17, 2011 at 3:59 PM, saurabh singh saurab...@gmail.com wrote: Machine/OS? I am pretty sure it will give. On Sun, Jul 17, 2011 at 3:09 PM, Ankur Khurana

Re: [algogeeks] Re: Free memory

2011-07-17 Thread saurabh singh
http://www.ideone.com/LmFES On Sun, Jul 17, 2011 at 3:59 PM, saurabh singh saurab...@gmail.com wrote: Machine/OS? I am pretty sure it will give. On Sun, Jul 17, 2011 at 3:09 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: local stack is different and global is different ? and runtime

[algogeeks] MICROSOFT

2011-07-17 Thread geek forgeek
given an array a[0..n-1] .required to find the output array out [0.n-1] such that out [i] is the product of all the numbers a[0] to a[n-1] excluding a[i] for ex out[2]=a[0]*a[1]*a[3]*a[4]a[n-1] constraint is not using division operator how to do this in O(n)?? -- You received

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Anika Jain
node *listing::rev(node *p) { if(p-next==NULL) { head=p; return p; } else { node *t=rev(p-next); t-next=p; p-next=NULL; tail=p; return p; } } On Sun, Jul 17, 2011 at 3:21 PM, Nishant Mittal

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Anika Jain
initial call to this will be rev(head); On Sun, Jul 17, 2011 at 4:28 PM, Anika Jain anika.jai...@gmail.com wrote: node *listing::rev(node *p) { if(p-next==NULL) { head=p; return p; } else { node *t=rev(p-next); t-next=p;

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Nishant Mittal
take 2 arrays before and after... before[i] contains the product of all the numbers before i and after[i] contains product of all the numbers after i something like this before[0]=1; after[n-1]=1; for(i=1;in;i++) { before[i]=a[i-1]*before[i-1];

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread prasanth n
@sourabh jakhar: how to design that big int class?? what data structure to use?? On Sun, Jul 17, 2011 at 3:55 PM, sourabh jakhar sourabhjak...@gmail.comwrote: i donot know abt the results but one thing for sure get your basic first right and than do the weird question On Sun, Jul 17, 2011

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Anurag Aggarwal
take two extra arrays b[] and c[] in b[] store the following thing b[0]=1; b[i]=b[i-1]*a[i-1]; in c[] store following things c[n-1]=1; c[i]=c[i+1]*a[i+1] (in-1) fill the c[] array in reverse order i.e. start from n-1 then go to 0; now output[] would be output[i]=b[i]*c[i]; On Sun, Jul 17,

Re: [algogeeks] MICROSOFT

2011-07-17 Thread geek forgeek
ohh its pretty easy i cudnt make it in the written.. nywayz thanx @nishant and @anurag On Sun, Jul 17, 2011 at 4:35 PM, Anurag Aggarwal anurag19aggar...@gmail.com wrote: take two extra arrays b[] and c[] in b[] store the following thing b[0]=1; b[i]=b[i-1]*a[i-1]; in c[] store following

Re: [algogeeks] MICROSOFT

2011-07-17 Thread manish patel
thanx the question was asked by MS today in MNNIT. On Sun, Jul 17, 2011 at 4:35 PM, Anurag Aggarwal anurag19aggar...@gmail.com wrote: take two extra arrays b[] and c[] in b[] store the following thing b[0]=1; b[i]=b[i-1]*a[i-1]; in c[] store following things c[n-1]=1;

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Piyush Sinha
It can be done using one extra array only that is the output array out[] *int out = (int *)malloc(sizeof(n)); //n is the number of elements in a int i,temp = 1; for(i=0;in;i++) { out[i] = temp; temp*=a[i]; } temp =1; for(i=n-1;i=0;i--) { out[i] *= temp;

Re: [algogeeks] Re: Free memory

2011-07-17 Thread Ankur Khurana
holy sh*t . I need to switch from MinGw was using codeblocks. Thanks :) On Sun, Jul 17, 2011 at 4:02 PM, saurabh singh saurab...@gmail.com wrote: http://www.ideone.com/LmFES On Sun, Jul 17, 2011 at 3:59 PM, saurabh singh saurab...@gmail.comwrote: Machine/OS? I am pretty sure it

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread bharath kannan
node * reverse(node *head) { if(head-next) { node * temp=reverse(head-next); head-next-next=head; head-next=NULL; return temp; } return head; } On Sun, Jul 17, 2011 at 4:57 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: *node *reverse(node

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Harshal
@manish, can you please tell other questions asked by ms today? On Sun, Jul 17, 2011 at 4:53 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: It can be done using one extra array only that is the output array out[] *int out = (int *)malloc(sizeof(n)); //n is the number of elements in a int

Re: [algogeeks] MICROSOFT

2011-07-17 Thread sourabh jakhar
10 c output question . questions were moderate type but negative marking +3 and -2.(30 min) coding round.(45 min) 1.array simple question d.p 2.test cases of notepad 3.Design Big Int class in C or c++ On Sun, Jul 17, 2011 at 5:14 PM, Harshal hc4...@gmail.com wrote: @manish, can you please

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Piyush Sinha
Use linked list for designing big int class On Sun, Jul 17, 2011 at 5:17 PM, sourabh jakhar sourabhjak...@gmail.comwrote: 10 c output question . questions were moderate type but negative marking +3 and -2.(30 min) coding round.(45 min) 1.array simple question d.p 2.test cases of

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Harshal
thanks sourabh :) On Sun, Jul 17, 2011 at 5:17 PM, sourabh jakhar sourabhjak...@gmail.comwrote: 10 c output question . questions were moderate type but negative marking +3 and -2.(30 min) coding round.(45 min) 1.array simple question d.p 2.test cases of notepad 3.Design Big Int class

Re: [algogeeks] MICROSOFT

2011-07-17 Thread sourabh jakhar
we can also use dynamically allocated array where they contain the digits of number and than apply the operation it is a better option i think as we can go to any index in 0(1) time. On Sun, Jul 17, 2011 at 5:19 PM, Harshal hc4...@gmail.com wrote: thanks sourabh :) On Sun, Jul 17, 2011 at

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sagar pareek
@saurabh Ok... on 20th amazon is coming :) On Sun, Jul 17, 2011 at 4:35 PM, prasanth n nprasnt...@gmail.com wrote: @sourabh jakhar: how to design that big int class?? what data structure to use?? On Sun, Jul 17, 2011 at 3:55 PM, sourabh jakhar sourabhjak...@gmail.comwrote: i donot

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sagar pareek
@prasanth Trie will be used... :) :) On Sun, Jul 17, 2011 at 5:28 PM, sagar pareek sagarpar...@gmail.com wrote: @saurabh Ok... on 20th amazon is coming :) On Sun, Jul 17, 2011 at 4:35 PM, prasanth n nprasnt...@gmail.com wrote: @sourabh jakhar: how to design that big int class??

Re: [algogeeks] MICROSOFT

2011-07-17 Thread Piyush Sinha
@Saurabh...ya true buddy...using malloc and realloc functions...gr88 On Sun, Jul 17, 2011 at 5:24 PM, sourabh jakhar sourabhjak...@gmail.comwrote: we can also use dynamically allocated array where they contain the digits of number and than apply the operation it is a better option i think as

[algogeeks] Re: Finding the Kth Prime

2011-07-17 Thread Dave
@Shubham: Google is your friend. Dave On Jul 17, 3:22 am, Shubham Maheshwari shubham.veloc...@gmail.com wrote: @Dave: could you please extrapolate on the 'sequence point rule' a bit more. i am nt familiar with it ... On Sun, Jul 17, 2011 at 3:01 AM, Dave dave_and_da...@juno.com wrote:

Re: [algogeeks] MICROSOFT

2011-07-17 Thread aanchal goyal
@piyush, @sourabh I also think that array would be a better choice than a linked list. General strategy is take input as string and place digits in suitable size array. Upto this point its ok, but are we required to implement the +,-,/,* or comparison operators also? On Sun, Jul 17, 2011 at 5:24

Re: [algogeeks] MICROSOFT

2011-07-17 Thread sourabh jakhar
when we have + and - than we can also implement division as we do in assembly language subtract the divisor form dividend and keep track of remainder On Sun, Jul 17, 2011 at 5:34 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: @AnchalI think + - and * wont create much problemwe have to

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread prasanth n
@sagar pareek: we cant use linked list ah?? On Sun, Jul 17, 2011 at 6:44 PM, sagar pareek sagarpar...@gmail.com wrote: kk... On Sun, Jul 17, 2011 at 5:31 PM, sourabh jakhar sourabhjak...@gmail.comwrote: @sagar pareek if you are from mnnit than donot disclose these kind of things here .

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread sagar pareek
yeah it can be On Sun, Jul 17, 2011 at 6:47 PM, prasanth n nprasnt...@gmail.com wrote: @sagar pareek: we cant use linked list ah?? On Sun, Jul 17, 2011 at 6:44 PM, sagar pareek sagarpar...@gmail.comwrote: kk... On Sun, Jul 17, 2011 at 5:31 PM, sourabh jakhar

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread prasanth n
@sagar pareek: thanks On Sun, Jul 17, 2011 at 6:50 PM, sagar pareek sagarpar...@gmail.com wrote: yeah it can be On Sun, Jul 17, 2011 at 6:47 PM, prasanth n nprasnt...@gmail.com wrote: @sagar pareek: we cant use linked list ah?? On Sun, Jul 17, 2011 at 6:44 PM, sagar pareek

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-17 Thread karthiga m
can anyone pls tell me how to print 2D array in spiral manner?/ On 7/17/11, prasanth n nprasnt...@gmail.com wrote: @sagar pareek: thanks On Sun, Jul 17, 2011 at 6:50 PM, sagar pareek sagarpar...@gmail.com wrote: yeah it can be On Sun, Jul 17, 2011 at 6:47 PM, prasanth n

[algogeeks] Re: Reverse a List with Recursion

2011-07-17 Thread Navneet
I am looking for a solution with no 'tail' node available/static types used etc. Also with algorithms given without above two conditions, i don't see they doing the right thing for me. Maybe i need to check more. Have you guys tried to see if this is working for you? On Jul 17, 4:42 pm, bharath

Re: [algogeeks] MICROSOFT

2011-07-17 Thread archita monga
@manish-can u plz give more details about the Big Int class ques??what exactly was d ques? On Sun, Jul 17, 2011 at 5:38 PM, sourabh jakhar sourabhjak...@gmail.comwrote: when we have + and - than we can also implement division as we do in assembly language subtract the divisor form dividend

Re: [algogeeks] MS question

2011-07-17 Thread Nishant Mittal
1.while typing it must show most popular searches starting from the string which we have typed so far 2.it must show most popular websites first 3.it must show related searches there can be many more On Sun, Jul 17, 2011 at 8:05 PM, swetha rahul swetharahu...@gmail.comwrote: Write

Re: [algogeeks] MS question

2011-07-17 Thread ankit sambyal
1. If u entered nothing and just pressed search, it should display nothing. 2. If u just entered a space and just pressed search, it should display nothing. 3.Verify the results are really related to give word or not 4.Check if proper Result is displayed for key word. 5. Check for the Order of the

Re: [algogeeks] MS question

2011-07-17 Thread swetha rahul
ya got it..thanks... how abt test cases for program to check whether a given string is palindrome or not..? On Sun, Jul 17, 2011 at 8:35 PM, ankit sambyal ankitsamb...@gmail.comwrote: 1. If u entered nothing and just pressed search, it should display nothing. 2. If u just entered a space and

[algogeeks] Re: MS question

2011-07-17 Thread Nishant
1.If string is NULL then it should return 1 i.e. string is palindrome 2.If there is only one character in string then it is palindrome 3.If reverse of given string is same as string On Jul 17, 8:18 pm, swetha rahul swetharahu...@gmail.com wrote: ya got it..thanks... how abt test cases for

[algogeeks] Median of billion numbers - Map Reduce

2011-07-17 Thread Dumanshu
Given billions of integers in a file. Memory Constraints exist so need to parallelize. One solution can be to split the file over a 100 machines and each machine calculates median of their part using quickselect and sends the result to host machine. Now the host calculates median of these medians

Re: [algogeeks] Re: MS question

2011-07-17 Thread swetha rahul
is this ans sufficient..? any other possible test cases for palindrome ? On Sun, Jul 17, 2011 at 8:53 PM, Nishant mittal.nishan...@gmail.com wrote: 1.If string is NULL then it should return 1 i.e. string is palindrome 2.If there is only one character in string then it is palindrome 3.If

[algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread Dumanshu
plz give some example..sry but what do you mean by child sibling version?? On Jul 16, 3:46 pm, Reynald reynaldsus...@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- You received this message

Re: [algogeeks] Re: Puzzle

2011-07-17 Thread Tushar Bindal
thanks sagar for this wonderful shortcut but can you please explain it better. in what cases can we use this approach? -- 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

[algogeeks] Re: MS question

2011-07-17 Thread Dumanshu
Well, for the third case, you can elaborate on the implementation. We need to compare the first half with the later half. So, in case of even no. of characters it splits perfectly and in case of odd number of characters, just ignore the middle character. On Jul 17, 8:28 pm, swetha rahul

Re: [algogeeks] Re: Puzzle

2011-07-17 Thread sagar pareek
Well you can find it in WILLIAM STALLINGS's book of cryptography. or foundation of cryptography by wenbo mao :) :) On Sun, Jul 17, 2011 at 9:02 PM, Tushar Bindal tushicom...@gmail.comwrote: thanks sagar for this wonderful shortcut but can you please explain it better. in what cases can

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread naveen ms
im a bit confused with child-sibling term, this expects output for input: A /\ B C / \ / \ DE F G output: A / B C / / DE FG -- You received this message because you are subscribed to the Google

Re: [algogeeks] Microsoft Interview Qn

2011-07-17 Thread Ashish Goel
1. PUSH ROOT IN Q 2. PUSH DUMMY NODE IN Q, DEFINE PREVIOUS NODE AS NULL 3. WHILE Q IS NOT EMPTY 3A. POP CURRENT NODE 3B. IF CURRENT NODE IS NOT DUMMY 3B1. IF PREVIOUS, PREVIOUS-SIBLING = CURRENT. 3B2. PREVIOUS = CURRENT 3B3. PUSH CURRENT-LEFT, CURRENT-RIGHT TO Q (ONLY IF THE NODES ARE NOT NULL) 3C

Re: [algogeeks] Median of billion numbers - Map Reduce

2011-07-17 Thread Ashish Goel
WOULDN'T MEDIAN OF MEDIANS WORK? mappers and reducers using hadoop Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sun, Jul 17, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: Given billions of integers in a file. Memory Constraints exist so

Re: [algogeeks] Re: Puzzle

2011-07-17 Thread Tushar Bindal
thankyou :) -- 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

Re: [algogeeks] c++ output

2011-07-17 Thread varun pahwa
@sourabh are you sure the code int main() { g(); f(); } inline int f(){ g(); return g()+1; } inline int g() { return 1; } does work i think i must give compilation error. Because a function need to be declared, before it is called in case of c++. and by inline the code in the function is

Re: [algogeeks] Re: MS question

2011-07-17 Thread vaibhav agarwal
check for query injection,string like (spaces,nothing) entered. On Sun, Jul 17, 2011 at 9:04 PM, Dumanshu duman...@gmail.com wrote: Well, for the third case, you can elaborate on the implementation. We need to compare the first half with the later half. So, in case of even no. of characters

Re: [algogeeks] Re: MS question

2011-07-17 Thread ankit sambyal
Check for case senstivity also: eg: Madam and madam both are palindromes. Also for clarify with the interviewer whether whitespace and punctuation can be ignored. eg: is the following string a palindrome or not: A man, a plan, a canal, Panama And check for this condition accordingly -- You

Re: [algogeeks] Re: Reverse a List with Recursion

2011-07-17 Thread sameer.mut...@gmail.com
@Navneet: Its not possible to solve this without a single tail pointer. I have come across this question saying it requires a single pointer and that pointer is the tail pointer. So along with head you need a tail pointer or a global pointer. Otherwise cannot keep track of header for reversed

[algogeeks] C Doubts

2011-07-17 Thread Abhi
1.When I declare a variable as const then any subsequent assignment of it gives an error assignment of read only variable. Is a const variable treated as a read only variable? 2. #includestdio.h struct s1 { char a; }; char s2 { char b; int c; };

Re: [algogeeks] C Doubts

2011-07-17 Thread Harshal
1. Yes, you cannot modify a const variable. This itself means that it is read-only. 2.Google structure padding. It is done to make sure that variables start in memory at addresses that are a multiple of their size. This is more efficient at hardware level. 'char' (1 byte) variables can be byte

Re: [algogeeks] C Doubts

2011-07-17 Thread aditya kumar
1) you cannot change the const variable . 2) generally sizeof behaviour in case of structure is just undefined. Either it follows the summation of size of members or it uses padding concept ie in your example 4 byte each for character(1 byte for char rest of the 3 bytes is padded up) and 4 byte

Re: [algogeeks] C Doubts

2011-07-17 Thread Abhi
That was really helpful. -- 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/-/KvxrTcPf104J. To post to this group, send email to algogeeks@googlegroups.com. To

[algogeeks] Re: C Doubts

2011-07-17 Thread Parthiban
@Abhi: Answers: 1. whenever a 'const' qualifier is added previously to a variable declaration it means that the value of the variable is automatically initialized to '0'(because of the 'auto' type of the const variable) and cannot be changed in any of the following assignment statements to the

Re: [algogeeks] c++ output

2011-07-17 Thread Tushar Bindal
@varun you are contradicting your own statement when inline replaces the code at place where it is called, then this code will work fine. and the other one w/o inline won't as explained by others also. there seems to be some confusion in your statement. -- Tushar Bindal Computer Engineering

[algogeeks] Re: c++ output

2011-07-17 Thread Parthiban
The keyword inline means the code is substituted for the declared inline function call in its place itself and this is done at compile time and mostly an optional one left to the compiler to substitute or not. since you have used inline in the snippet it means i checks for the function

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
struct st { char ch1; long double ld; }s; printf(%d,sizeof(s)); //output : 24 (for 32-bit compiler) -as i have mentioned above the behaviour is undefined in case of sizeof (struct) can any one explain me why the padding concept does not work here ?? On Mon, Jul 18, 2011 at 12:13 AM,

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread sagar pareek
sizeof long double is 12. So padding concept is perfectly working On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar aditya.kumar130...@gmail.com wrote: struct st { char ch1; long double ld; }s; printf(%d,sizeof(s)); //output : 24 (for 32-bit compiler) -as i have mentioned above

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
@prateek . can you explain me ?? i dint get padding logic in this example of mine. On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek sagarpar...@gmail.comwrote: sizeof long double is 12. So padding concept is perfectly working On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar

Re: [algogeeks] Re: MS question

2011-07-17 Thread swetha rahul
Thanks everyone!! On Sun, Jul 17, 2011 at 10:56 PM, ankit sambyal ankitsamb...@gmail.comwrote: Check for case senstivity also: eg: Madam and madam both are palindromes. Also for clarify with the interviewer whether whitespace and punctuation can be ignored. eg: is the following string a

[algogeeks] MS Ques

2011-07-17 Thread swetha rahul
Hi, Given 2 linked lists L1 and L2 create a linked list that gives the multiplication of the above 2 linked lists. Eg: L1 =1-5 L2 =1-0 Ans must be 1-5-0 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread Nikhil Gupta
@Aditya Here is the padding effect : Address of char : starts anywhere Address of long double : starts at 11 address locations from char variable -- 1+11+12=24 bytes On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek sagarpar...@gmail.com wrote: @aditya actually first see your post, you have

[algogeeks] Re: MICROSOFT

2011-07-17 Thread Parthiban
one way is through the log concept: log(A/B)=logA-logB antilog(logA-logB) will give u log(A/B) without using division operator... but this will work iff there is a log function and an antilogfunction in the math.h header file... -- You received this message because you are subscribed to the

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
@pareek..my compiler gives 24 . newazz if ansa is 16 acc to you then it follows padding principle perfectly. since memory cycle invloves 1 word hence char will take 1 byte nd 3 bytes will be padded up . rest 12 bytes will come from long double so 4+12=16 bytes :) n ya sry abt d name . On Mon, Jul

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread Nikhil Gupta
@Sagar Memory sizes of long double variables are compiler and system configuration dependent. So obviously, in accordance with your compiler, the size of long double is 8 bytes. On Mon, Jul 18, 2011 at 1:22 AM, Nikhil Gupta nikhilgupta2...@gmail.comwrote: @Aditya Here is the padding effect :

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
@Nikhil why is Address of long double : starts at 11 address locations from char variable ?? is shud start from 3rd adress location from char variable bcoz memory cycle involves a word so are you padding 11bytes ?? On Mon, Jul 18, 2011 at 1:24 AM, Nikhil Gupta nikhilgupta2...@gmail.comwrote:

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread Nikhil Gupta
That is again compiler dependent. Usually when hardware configuration is taken into account, the compiler uses padding of 3 bytes. But in some cases, for the ease of hardware access and faster implementation, 11 bytes are padded. Possibly depends on your system hardware's synchronization with the

[algogeeks] Re: Median of billion numbers - Map Reduce

2011-07-17 Thread Dumanshu
it will work. But i want to avoid case of computing the median by sub machines. So as to improve upon the complexity, i want the sub machines to just take a random number k and split their data into two sets and and then pass the information to host machine which after having all the outputs of

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread sagar pareek
@nikhil my compiler gives sizeof long double =12 so aditya's concept is correct On Mon, Jul 18, 2011 at 1:35 AM, aditya kumar aditya.kumar130...@gmail.comwrote: @Nikhil thnks :) On Mon, Jul 18, 2011 at 1:32 AM, Nikhil Gupta nikhilgupta2...@gmail.comwrote: That is again compiler

[algogeeks] In-memory dictionary

2011-07-17 Thread Dumanshu
I want to have an in-memory dictionary. One word can have multiple meanings. 1. If you want to go with hash tables then do Suggest some good choices for hash functions. 2. Also, how can you modify this dictionary so that it can be used to solve a crossword puzzle? -- You received this message

Re: [algogeeks] Re: MICROSOFT

2011-07-17 Thread hary rathor
assume that ; all element in array are short integer; int i; long long long long long int multi=1; for(i=0;ia.len;i++) { multi*=a[i]; } for(i=0;ia.len;i++) { out[i]=mul[i]/a[i]; } O(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Re: MICROSOFT

2011-07-17 Thread Parthiban
the question also had these words: donot use division operator -- 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/-/87l39yN8v6sJ. To post to this group, send

Re: [algogeeks] Re: MICROSOFT

2011-07-17 Thread Saket Choudhary
^*constraint is not using division operator* * * * * On 18 July 2011 01:44, hary rathor harry.rat...@gmail.com wrote: assume that ; all element in array are short integer; int i; long long long long long int multi=1; for(i=0;ia.len;i++) { multi*=a[i]; } for(i=0;ia.len;i++) {

Re: [algogeeks] Re: MICROSOFT

2011-07-17 Thread hary rathor
sorry: i didn't see -- 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

Re: [algogeeks] In-memory dictionary

2011-07-17 Thread sagar pareek
1. you can use hash function with link list. 2. u can use trie with link list. On Mon, Jul 18, 2011 at 1:43 AM, Dumanshu duman...@gmail.com wrote: I want to have an in-memory dictionary. One word can have multiple meanings. 1. If you want to go with hash tables then do Suggest some good

Re: [algogeeks] Re: MICROSOFT

2011-07-17 Thread hary rathor
int dividend,divisor,remainder; int division(int p,int q){ int quotient=1; /*if divisor and diviend are equal then quotient=1*/ if(p==q){ remainder=0; return 1; } /*if dividend is smaller than divisor then remainder=dividend*/ if(pq){ remainder=p; return 0; } /*shift left till divisor dividend*/

[algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread Dumanshu
@Ashish: if i got ur algo correct, contrary to all the above examples, u r forming a linked list of level order traversal of the tree. m i right? On Jul 17, 8:49 pm, Ashish Goel ashg...@gmail.com wrote: 1. PUSH ROOT IN Q 2. PUSH DUMMY NODE IN Q, DEFINE PREVIOUS NODE AS NULL 3. WHILE Q IS NOT

Re: [algogeeks] MS Ques

2011-07-17 Thread aditi garg
p=L1 q=L2 while(p!=NULL q!=NULL) {int r; r-=p-info*q-info; p=p-next; q=q-next; insert(L3,r); } insert is the normal insert operation of linked list On Mon, Jul 18, 2011 at 1:15 AM, swetha rahul swetharahu...@gmail.comwrote: Hi, Given 2 linked lists L1 and L2 create a linked list

Re: [algogeeks] MS Ques

2011-07-17 Thread hary rathor
aditi : problem your code 1 .you are not putting single digit in third list but whole multiplication of two digit 2. forward add carry to next result ; 3. keep mind that list size may not be equal 4. list is singly so start processing from right side you need reverse them -- You received this

  1   2   >