Name: - : CS 3240 Spring 2011 Sample Final Exam
Name: - : CS 3240 Spring 2011 Sample Final Exam
Closed book and notes, 110 minutes Turn off your cell phones, pagers You may ask about any of the problems, but you may not ask about your answer
1. For each of the following problems, what is the time complexity (remember to use Big-O notation)? Briefly explain each answer, including what your n represents if appropriate (1-2 sentences) (a) Computing the average annual salary of a CSU-East Bay graduate.
(b) Determining the winner of an election where whoever has the most votes wins.
2.
Write code using the GraphType class to store the following information about airline ticket prices between various airports. DFW to SFO = $470 ORD to SFO = $150 ORD to DFW = $352 RDU to DFW = $372 SFO to ORD = $372
3.
These functions return the smallest and largest values in the list parameter. Write a function intersection that takes two UnsortedType parameters and returns a pointer (C++) or reference (Java) to a new UnsortedType that contains the intersection of the parameter lists. The function should use the minimum() and maximum() functions to get the smallest and largest elements of the 2 nd parameter and avoid scanning the 2 nd list for values less than the minimum or greater than the maximum. The function is not a method in the UnsortedType class.
4.
a.
Give the time complexity (in Big-O) of the following algorithms. Briefly explain.
Given an array-based sorted list, create a copy in reverse order by: pushing the values of the sorted list on a stack, then popping the values off and adding them to the copy.
b. Given two unsorted linked lists, determine if they both contain the same values, but not necessarily in the same order (or the same number of times, so the lists {2, 1, 2} and {1, 2} would satisfy this constraint) for each item X in the first list search if X is in the other list, returning false if not found return true if all items in the first list are found in the second list.
For the TreeType class (BinarySearchTree for Java), assume that the info field of the node (TreeNode for C++, BSTNode for Java) is a float. Implement average, a method in TreeType that returns the average value of all values in the tree. The solution must be recursive to receive any credit, though you may choose to divide the solution into two functions, one recursive and one not.
5.