Two lists, list1 and list2, contain the names of books found in two different collections.
A librarian wants to create newList
, which will contain the names of all books found in either list, in alphabetical order,
with duplicate entries removed.
For example, if list1 contains
["Macbeth", "Frankenstein", "Jane Eyre"]
and list2 contains
["Frankenstein", "Dracula", "Macbeth", "Hamlet"],
then newList will contain
["Dracula", "Frankenstein", "Hamlet", "Jane Eyre", "Macbeth"].
The following procedures are available to create newList.
Which of the following code segments will correctly create newList?
- newList ← Combine (list1, list2)
- newList ← Sort (newList)
- newList ← RemoveDuplicates (newList)
This option is the best choice. It combines the lists, sorts them alphabetically, and then removes duplicates.
- list1 ← Sort (list1)
- list2 ← Sort (list2)
- newList ← Combine (list1, list2)
- newList ← RemoveDuplicates (newList)
The combined list will not be in alphabetical order. List 2 will be added to the end of list 1.
- list1 ← RemoveDuplicates (list1)
- list2 ← RemoveDuplicates (list2)
- newList ← Combine (list1, list2)
- newList ← Sort (newList)
There are no duplicates in the initial lists. When they are combined, there will be duplicates.
- list1 ← RemoveDuplicates (list1)
- list1 ← Sort (list1)
- list2 ← RemoveDuplicates (list2)
- list2 ← Sort (list2)
- newList ← Combine (list1, list2)
Similar to the previous choice, removing duplicates prior to combining the lists does nothing.