Re: [algogeeks] Re: Single linked list questions.
@SVIX group members still can post the questions they consider good, doesnt matter they were able to solve it or not. There can be many ways to solve the same question. On Fri, Jan 7, 2011 at 12:39 AM, SVIX saivivekh.swaminat...@gmail.comwrote: are u sure u were not able to solve this on ur own? On Jan 6, 3:26 am, dinesh bansal bansal...@gmail.com wrote: Hi Guys, There are some questions asked to me: 1. How do you print the SLL in reverse order. List should not be changed. 2. Two SLLs are merging at one point, how can you find out efficiently. Thanks -- Dinesh Bansal The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshal Choudhary, III Year B.Tech Undergraduate, Computer Science and Engineering, National Institute of Technology Surathkal, Karnataka India. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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: Single linked list questions.
Hi, I'm new here and looking to learn more on algos and participate in discussions. @juver++, Recursion solution to the 1st problem implicitly using stack. No? print (list l) { if(i-next) print(l-next); print l; } On Jan 6, 4:55 pm, juver++ avpostni...@gmail.com wrote: 1. Recursive function. Print node's element after processing next link of the current node. Also this can be achieved using stack. 2. Please clarify the question. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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: Single linked list questions.
On Thu, Jan 6, 2011 at 5:25 PM, juver++ avpostni...@gmail.com wrote: 1. Recursive function. Print node's element after processing next link of the current node. Also this can be achieved using stack. 2. Please clarify the question. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. Hi juver++, Ya.. recurrsive function call was a good idea.. thanks. Regrading second question, there are two SLLs L1 and L2, at some node both lists nodes point to the same node and create single linked list. hope I am clear. -- Dinesh Bansal The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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: Single linked list questions.
Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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: Single linked list questions.
@sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.comwrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com wrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: Single linked list questions.
@aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.com wrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.comwrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com wrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: Single linked list questions.
@ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.com wrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.com wrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.comwrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com wrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers Naveen Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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: Single linked list questions.
Hii @ Question 2 - 1. Just count the no of nodes in each link list lets say N1 and N2 are the number of the nodes in first and second linklist respectively. 2. Now calculate the difference of the Nodes like as p = {N1~N2) 3. Now take 2 pointers say P1 and P2. 4. a. If N1 N2 then put the pointer p1 at Pth Node from the starting of the first list and the pointer P2 at the starting of the second list b. If N2 N1 then put the pointer p2 at the Pth node from the starting of the second list and the pointer P1 at the starting of the first list. 5. Now Increase the pointer one by one and at every step check if P1 == P2 and when it will true ,it will be your intended node. Please correct me if i am wrong Thanks -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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: Single linked list questions.
There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.com mailto:vishal.ge...@gmail.com wrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.com mailto:aditya...@gmail.com wrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.com mailto:vishal.ge...@gmail.com wrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com mailto:sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com mailto:avpostni...@gmail.com wrote: Yes, but recursion stack's size is limited instead of iterative version. -- 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 mailto:algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com mailto:algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- 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 mailto:algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com mailto:algogeeks%2bunsubscr...@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 mailto:algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com mailto:algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- 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 mailto:algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com mailto:algogeeks%2bunsubscr...@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
Re: [algogeeks] Re: Single linked list questions.
Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.comwrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.com wrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com wrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers Naveen Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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. -- Regards Aditya -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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.
Re: [algogeeks] Re: Single linked list questions.
How can two list just intersect, each node can have one pointer to the next. So, if they intersect they will definitely be merging. On Thu, Jan 6, 2011 at 11:01 PM, Tushar Bindal tushicom...@gmail.comwrote: Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.comwrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.comwrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.comwrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers Naveen Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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. -- Regards Aditya -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to
Re: [algogeeks] Re: Single linked list questions.
I agree But my doubt is that whether we have to find that they just have their last node as common or they can have many nodes common(which I was calling intersecting) On Thu, Jan 6, 2011 at 11:07 PM, Naveen Kumar naveenkumarve...@gmail.comwrote: How can two list just intersect, each node can have one pointer to the next. So, if they intersect they will definitely be merging. On Thu, Jan 6, 2011 at 11:01 PM, Tushar Bindal tushicom...@gmail.comwrote: Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.comwrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.comwrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.comwrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers Naveen Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@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. -- Regards Aditya -- You received this
Re: [algogeeks] Re: Single linked list questions.
for 2nd question. Let m1,m2 be the length of sll1 and sll2.. now we know that after the merge no of nodes are same in both the slls. So take the difference , k= m1 - m2 skip k nodes frm the longer lists, then increment both sll1 and sll2 till you find a match. The matched node is the required answer. On Thu, Jan 6, 2011 at 11:14 PM, Tushar Bindal tushicom...@gmail.comwrote: I agree But my doubt is that whether we have to find that they just have their last node as common or they can have many nodes common(which I was calling intersecting) On Thu, Jan 6, 2011 at 11:07 PM, Naveen Kumar naveenkumarve...@gmail.comwrote: How can two list just intersect, each node can have one pointer to the next. So, if they intersect they will definitely be merging. On Thu, Jan 6, 2011 at 11:01 PM, Tushar Bindal tushicom...@gmail.comwrote: Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.comwrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.comwrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.comwrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers Naveen
Re: [algogeeks] Re: Single linked list questions.
Problem hav been solved u all giving same answers..! On Thu, Jan 6, 2011 at 11:30 PM, nishaanth nishaant...@gmail.com wrote: for 2nd question. Let m1,m2 be the length of sll1 and sll2.. now we know that after the merge no of nodes are same in both the slls. So take the difference , k= m1 - m2 skip k nodes frm the longer lists, then increment both sll1 and sll2 till you find a match. The matched node is the required answer. On Thu, Jan 6, 2011 at 11:14 PM, Tushar Bindal tushicom...@gmail.comwrote: I agree But my doubt is that whether we have to find that they just have their last node as common or they can have many nodes common(which I was calling intersecting) On Thu, Jan 6, 2011 at 11:07 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: How can two list just intersect, each node can have one pointer to the next. So, if they intersect they will definitely be merging. On Thu, Jan 6, 2011 at 11:01 PM, Tushar Bindal tushicom...@gmail.comwrote: Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.comwrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.comwrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.comwrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to
Re: [algogeeks] Re: Single linked list questions.
@Sanchit..sorry i didnt see the replies :P On Thu, Jan 6, 2011 at 11:32 PM, sanchit mittal sm14it...@gmail.com wrote: Problem hav been solved u all giving same answers..! On Thu, Jan 6, 2011 at 11:30 PM, nishaanth nishaant...@gmail.com wrote: for 2nd question. Let m1,m2 be the length of sll1 and sll2.. now we know that after the merge no of nodes are same in both the slls. So take the difference , k= m1 - m2 skip k nodes frm the longer lists, then increment both sll1 and sll2 till you find a match. The matched node is the required answer. On Thu, Jan 6, 2011 at 11:14 PM, Tushar Bindal tushicom...@gmail.comwrote: I agree But my doubt is that whether we have to find that they just have their last node as common or they can have many nodes common(which I was calling intersecting) On Thu, Jan 6, 2011 at 11:07 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: How can two list just intersect, each node can have one pointer to the next. So, if they intersect they will definitely be merging. On Thu, Jan 6, 2011 at 11:01 PM, Tushar Bindal tushicom...@gmail.comwrote: Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.comwrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.comwrote: @vishal saurabh is right its merging at only one point its a Y-shaped structure On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.com wrote: @sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.com wrote: for second question calculate the difference in length of two linked list. and than shift the head of longest linked list to the calculated difference. while the head of shorest is at the first node of that linked list. Than iterate both to see if info is equal and that is the merging point. complexity-o(n). hope this help On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.comwrote: Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Aditya Kumar B-tech 3rd year Computer Science Engg. MNNIT, Allahabad. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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