[algogeeks] Problems on Linked List
Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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] Problems on Linked List
for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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] Problems on Linked List
@naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.comwrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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] Problems on Linked List
reverse the list inplace and compare the two list element by element On Thu, Aug 11, 2011 at 12:01 AM, Piyush Kapoor pkjee2...@gmail.com wrote: @naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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] Problems on Linked List
Ques 1: Let l1 and l2 be the 2 lists. Step 1 : Reverse l1 O(n) Step 2 : Compare l1 and l2 by comparing each node and traversing ahead.--O(n) Step 3: Reverse l1 -O(n) Ques 2: Let cur be the node of the linked list which is to be deleted. LinkedList temp=cur-next; cur-data=temp-data; cur-next=temp-next; free(temp); TC : O(1) This solution does not work if cur is the last node of the link list. In that case u will have to traverse the whole link list and TC will be O(n) -- 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] Problems on Linked List
and for second no need to delete that very node pointer, take the data of the node next to the node you want to delete and copy that to the node you want to delete, do it for all next nodes. delete the last node. On Thu, Aug 11, 2011 at 12:12 AM, sukran dhawan sukrandha...@gmail.com wrote: reverse the list inplace and compare the two list element by element On Thu, Aug 11, 2011 at 12:01 AM, Piyush Kapoor pkjee2...@gmail.com wrote: @naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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. -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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] Problems on Linked List
1)similar to list palindrome problem(soln already there in net) 2)it has discussed 2 day before on same group. please search once Thank you, Siddharam On Thu, Aug 11, 2011 at 12:01 AM, Piyush Kapoor pkjee2...@gmail.com wrote: @naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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] Problems on Linked List
thanks all On Thu, Aug 11, 2011 at 12:21 AM, siddharam suresh siddharam@gmail.comwrote: 1)similar to list palindrome problem(soln already there in net) 2)it has discussed 2 day before on same group. please search once Thank you, Siddharam On Thu, Aug 11, 2011 at 12:01 AM, Piyush Kapoor pkjee2...@gmail.comwrote: @naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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] Problems on Linked List
1)for the fst one you dont have to reverse the linked list just traverse the linked list recursively and read it from back . correct me if m wrong ! On Thu, Aug 11, 2011 at 12:41 AM, Piyush Kapoor pkjee2...@gmail.com wrote: thanks all On Thu, Aug 11, 2011 at 12:21 AM, siddharam suresh siddharam@gmail.com wrote: 1)similar to list palindrome problem(soln already there in net) 2)it has discussed 2 day before on same group. please search once Thank you, Siddharam On Thu, Aug 11, 2011 at 12:01 AM, Piyush Kapoor pkjee2...@gmail.comwrote: @naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- 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. -- 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 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- 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.