1 / 6

CS208 Coursework 1

CS208 Coursework 1. Neil Ghani Mark Dukes Handin: Friday 25 February, 12pm, Departmental Office. Big O Notation. Question 1: If f and f’ re functions, define (f+f’) to be the function sending x to fx + f’x, ie (f + f’) x = f x + f’x

Download Presentation

CS208 Coursework 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS208 Coursework 1 Neil Ghani Mark Dukes Handin: Friday 25 February, 12pm, Departmental Office

  2. Big O Notation • Question 1: If f and f’ re functions, define (f+f’) to be the function sending x to fx + f’x, ie (f + f’) x = f x + f’x Show that if f is O(g) and f’ is (g’), then f + f’ is O(g + g’)

  3. More Big-O notation • Question 2: Show that the big O-notaiton is transitive. That is, show that if f is O(g) and g is O(h) then f is O(h)

  4. Reverse1 • Question 3. What is the complexity of the reverse algorithm on lists defined by rev1 [] = [] rev1 (x:xs) = rev1 xs + [x] where [] is the empty list, (x:xs) is a list with first element x and the rest of the list is xs, [x] is a list containing only the element x and + joins two lists togther. You may assume + has linear complexity, ie is O(n)

  5. Reverse2 • Question 4: What is the complexity of the following reverse algorithm rev2 [] = [] rev2 [x] = [x] rev2 xs = rev2 (back xs) + rev2 (front xs) where front xs is the first half of the list xs and back xs is the second half of the list xs. You may assume + is linear as are front and back

  6. Reverse3 • Question 5: What is the complexity of the following reverse algorithm rev3 xs = rev3’ xs [] rev3’ [] ys = ys rev3’ (x:xs) ys = rev3’ xs (x:ys) As primitive operations, count the number of uses of the operation : which attaches an element to the front of a list.

More Related