CS 14 - Homework 1
Due Tuesday, April 16 (at beginning
of class)
2.
Given
the following running times, rank them from fastest to slowest (for large n).
nlogn, 4n2+n+8, 10logn, 2n+nlogn, 46n2, 7n-11.
for(i=0; i<n; i++)
x++
for(i=0; i<n; i++)
for(j=0; j<i; j++)
x++
4.
Program A has a running time of n2-1500, where n is the size
of the input. Program B has running time 400n+16. For what values of n
does program A run faster? For what values of n does program B run faster?
5.
Draw
a singly linked list that contains three items X, Y, and Z. The head pointer points to the X item. Now explicitly write out the pointer
operations required for each of the following parts (each part operates on the
original list).
p = new node
p.item = "ABC"
p.next = new node
q = p.next
q.item = "abc"
q.next = NULL
r = new node
r.item = "xyz"
r.next = q
p.next = r