CSE 1302C Final Exam_SU11.docx

advertisement
July 6th, 2011
CSE 1302C Final Exam
Name:____________________________________
Directions: You have 90 minutes to complete this exam. All answers are to be your own.
Question 0 (25 pts): Imagine there is a server at “www.cse1302c.com” that has port 80 open. When
someone connects to it, the server will send the final exam grades for each student (as strings with no
names). Write a chunk of code that connects to that server, reads the final exam grade for each
student, and then prints out the final exam average. Use Int32.Parse() to convert strings to ints. YOUR
CODE MUST HANDLE ANY EXCEPTIONS THAT OCCUR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Question 1 (25 pts): Assume we have an array of n sorted numbers (ints) and a linked list of n unsorted
numbers (ints). Using O-notation (e.g. O(log2n) ), fill in how long it takes to do the following operations
in the most efficient way possible.
Array
Find the min
Find the max
Find the average of all numbers
Insert a new number
Find if a number is in the data
structure (e.g. if it exists)
Remove a number if it exists
Linked List
Question 2: What is the output of the following code? Make sure you print ALL OF THE
OUTPUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
static int recurse(int i, int j)
{
Console.WriteLine("i: " + i + " j:" + j);
if (i == j)
{
return j;
}
else
{
return i + recurse(i + 1, j);
}
}
static void Main(string[] args)
{
Console.WriteLine(recurse(1, 5));
}
Question 3: Declare a 10x10 2D array of ints and then initialize each slot to the multiplied values of the
indices for that slot (e.g. slot 6 over 7 down should receive the value 42 because 6x7 = 42).
Download