CSE 1302C Test 2 - Retest_FA10.docx

advertisement
CSE 1302C – Retest
Directions: Don’t cheat, no textbooks, blah, blah… Each question is worth 33 points.
11/16/2010
Question 1: What is the output of the following code chunk? For clarification, draw the stack.
static int recurse(int i, int j)
{
Console.WriteLine("i is " + i + " j is " + j);
if (j <= 1)
{
return i;
}
else
{
return i * recurse(i, (j - 1));
}
}
static void Main(string[] args)
{
Console.WriteLine(recurse(3, 4));
}
Question 2: Assume we have a sorted linked list of 100 numbers and an unsorted array of 100 numbers. What are the runtimes of
the following operations? Use Big-Oh notation.
Linked List
Array
Find the minimum element
Determine if a number is in the data
structure
Insert a new number
Increase to 101 numbers (add one
more element)
Question 3: Assume you have the code below. Show the code to insert the numbers 4, 2 and 9 using the data structure provided.
Hint: this will be very sloppy code.
public class ListNode
{
public int data;
public ListNode next;
public ListNode(int x)
{
data = x;
next = null;
}
}
class Program
{
static void Main(string[] args)
{
// here
}
}
Extra credit (1 point): what is the common name of the function in question 1?
Download