Sei sulla pagina 1di 5

UBC CPSC221 Written Assignment 1

Devin Meckling
35723105
E-mail: devinmeckling@gmail.com
Abstract. This assignment was completed by Devin Meckling alone. No other students should
be marked for this submission.

1.
This method assumes two non-NULL linked lists exist, and that the pointers are pointing to the
desired positions as a precondition. It also assumes that a struct such as the one used in lab3
exists.
/*
* a: head of linked list to insert into b
* b: pointer to position in list to insert a after
*/
void insertAintoB(Node * a, Node *b) {
Node *c = b;
b->next = a;
while (a->next) a=a->next;
a->next = c->next;
c=NULL;
}
2.
(i) Such a data structure could quickly be searched for the house in question in O(log(n)) using
binary search. The second operation proceeds in O(n) time as arrays cannot be dynamically
resized, and would therefore need to be copied to insert the new house.
(ii) For the singly linked list, outputting the neighbours would proceed in O(n) time, because
your execuation time is some integer multiple of n. The same is true of inserting the new
house, as you would simply be iterating the list multiple times.
(iii) I would pick the array because one of the operations proceeds in O(log(n)) so one of two
operations would be significantly faster.
3.
(i) lg32n = nlg32 = 5n
(ii) 2( lg(n2 m2 ) lg(m2 )) = 2( lg(n2 )) = n2

(iii) lg(1/8) = (lg(1) lg(8)) = 3


(iv) logp(1/p) = logp(1) logp(p) = 0 1 = 1
2)

(v) 64lg(n

= [2lgn ]6 = (n2 )6 = n12

4.
log(n) < n1/2 < n < log(n!) < nlog(n) < n2 < 13 + 23 + ... + n3 < n2log(n) < 2n < nn < (22 )n
5.
(i) (n2 )
(ii) (2n )
(iii) (n3 )
(iv) (2n/2 )
(v) (n)
6.

a.

b.

c.
7. Example of a Table
Table 1. caption goes here
left title

centre title

right title

entry 1
entry 4

entry 2
entry 5

entry 3
entry 6

8. Example of entering code


insert code here
9. Insert scetion title
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim[1] veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
9.1. Numbered list example
(i) First item

(ii)
(iii)
(iv)
(v)

Second item
Third item
Fourth item
Fifth item

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo[2] consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
9.2. Inserting figures example

Figure 1. Figure caption for first


of two sided figures.

Acknowledgments
Insert acknowledgements here
Appendix
Insert Appendix here
References
[1] Reference 1 goes here
[2] Reference 2 goes here

Figure 2. Figure caption for second of two sided figures.

Potrebbero piacerti anche