top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to delete the duplicate elements in a linklist?

+8 votes
1,034 views
How to delete the duplicate elements in a linklist?
posted Oct 28, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
One way is to use Binary Search Tree, though it will take O(nLogn) but it will take extra space.
Agree with salil. Make a binary search tree. so you can fine dup element while traversing and make a note of this dub and delete it from linked list.

2 Answers

0 votes

first sort link list , then it can easily deleted in O(n) time

answer Oct 28, 2013 by Raushan Kumar
if you make a sort then how you revert back a original linked list.

did you meant temp list with sorted form? then fine.
How to sort either BST or some similar machenism which will take o(NLogN)
Agree with sivanraj, once you sort getting back the original would be a challenge.
0 votes

One of the possibility is to use hash table i.e, for each element in the linked list check in the hash table if it is already present remove it from the linked list if not update it in the hash table

answer Nov 25, 2013 by Raghu
Similar Questions
+2 votes

In linux system how can I implement a linklist to communicate between two processes?

+4 votes

Say you have only this structure only to implement Doubly LL

struct Node
{
   int val;
   Node* p;
};
+4 votes

If we delete the mth number from a circle which is composed of numbers 0, 1, …, n-1 counting from 0 at every time, what is the last number?

For example, a circle is composed of five numbers 0, 1, 2, 3, 4. If we delete the 3rd number at every time, the deleted numbers are in order of 2, 0, 4, 1, so the last remaining number is 3.

...