List Processing Algorithms

On this page, you will test if the elements of a list are distinct (no duplicates).
are the numbers of (list {7, 47, 88, 62, 9, 11}) distinct? reporting false are the numbers of (list {7, 47, 88, 62, 9, 11}) distinct? reporting false

Suppose you have a list of items and want to know if the elements of the list are distinct (unique). This kind of question pops up frequently: for example, a Web search engine would want to be sure all of the search results are different from each other.

Here is one algorithm to solve the problem:

Brian wants us to delete every single place we say pseudocode. To be revisited another day. --MF, 12/27/17
Algorithms can be expressed in natural language or in pseudocode, text that describes the steps a program might carry out. These languages for human understanding may help write the algorithm in a programming language.

  1. Build a predicate that implements the above algorithm.
    are the numbers in () distinct?
  2. Talk with Your Partner If you doubled the length of the list, would this algorithm take the same amount of time? Twice as long? More than twice as long?
Alphie: Our predicate tells us if the elements of a list are distinct. I want more.
Gamal: What would you like?
Alphie: If there are any duplicates in the list, I'd like to see what they are. That way, I could remove them.
Betsy: Ok, let's write a reporter that produces the list of duplicates in a list.
  1. Build a reporter that returns all the duplicated items in a list:
  2. duplicates in (list{3,10,7,3,20,12,7}) reporting {3,7}
  1. Build a reporter, remove duplicates, that takes a list as input and reports a new list that has the same elements as the input list but has no duplicate elements.