CSCI 170 (GOLDWEBER)
Spring 08: 4/1/08
Homework 6
Due Date: Tuesday April 8, 2008.
There is a possible 40 points for this homework assignment.
You will be using Python for the problems in this assignment. Create a function for each problem with the names indicated. Store the functions in one file called hwk6_lastName.py (where you replace lastName with your last name). You will hand in both a hardcopy of your file in addition to emailing a copy to me. Each function should be loadable and runnable in the Python interpreter. Ask for help early and often.
Problem 1. (5 pts.) Write a function called sumsToX that takes as input a number n and a list, listOfNumbers, of integers and outputs "yes" if two distinct integers in the list sum to n, and outputs "no" otherwise.
Problem 2. (10 pts.) Write a function called listIntersection that takes as input two lists of values, list1 and list2 and outputs/displays the values in the intersection of these two lists. (list1∩list2) An item is in the intersection of the two input lists if it (the item) is present in both lists. While the two lists are not guaranteed to contain the same number of items, a precondition of listIntersection is that each of the two input lists are guaranteed to not contain any duplicate items.
Problem 3. (10 pts.) Write a function called listIsomorphism that takes as input two lists of values, list1 and list2 and outputs/displays "SAME" if the same values are in each list, though possibly in a different order, and "DIFFERENT" if at least one value is in only one of the lists. Hint: do not assume that the two lists have the same number of values.
Problem 4. (5 pts.) Write a function called selectionSort that takes as input a list of values and returns a list of the same values in sorted -ascending- order. Your function must implement the selection sort algorithm.
Problem 5. (10 pts.) Write a function called insertionSort that takes as input a list of values and returns a list of the same values in sorted -ascending- order. Your function must implement the insertion sort algorithm.
File translated from
TEX
by
TTH,
version 3.74.
On 1 Apr 2008, 09:41.