Remove duplicate elements: Difference between revisions

Content added Content deleted
No edit summary
Line 5: Line 5:
* Sort the elements and remove consecutive duplicate elements. The complexity of the best sorting algorithms is O(''n'' log ''n''). This approach requires that your type be "comparable", i.e., have an ordering. Putting the elements into a self-balancing binary search tree is a special case of sorting.
* Sort the elements and remove consecutive duplicate elements. The complexity of the best sorting algorithms is O(''n'' log ''n''). This approach requires that your type be "comparable", i.e., have an ordering. Putting the elements into a self-balancing binary search tree is a special case of sorting.
* Go through the list, and for each element, check the rest of the list to see if it appears again, and discard it if it does. The complexity is O(''n''<sup>2</sup>). The up-shot is that this always works on any type (provided that you can test for equality).
* Go through the list, and for each element, check the rest of the list to see if it appears again, and discard it if it does. The complexity is O(''n''<sup>2</sup>). The up-shot is that this always works on any type (provided that you can test for equality).

=={{header|ACL2}}==
<lang lisp>(remove-duplicates xs)</lang>


=={{header|Ada}}==
=={{header|Ada}}==