MidtermSolutions

MidtermSolutions - CS 234 Fall 2010 Midterm Model Solutions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 234 Fall 2010 Midterm Model Solutions 1. Short answer. Only provide explanation when asked. (a) Give two ways in which abstract data types help programmers solve problems. [2 marks] Here are four ways: simplify algorithms by hiding how the data is represented separation of implementation and interface increases ability to adapt to change grouping of related operations likely to be reused modularity and interfaces of ADTs support working in teams (b) Describe a real-world application of ADT Queue. [1 mark] Tracking bank customers waiting for a teller (FIFO) in a bank simulation. (c) List three distinct implementations of ADT Priority Queue. [3 marks] unsorted list, sorted list, heap (d) Consider the following function mystery . All runtimes are expressed as a function of n , the length of L . def mystery(L): for x in L: another_mystery(x,L) i. What worst-case runtime of another mystery guarantees that the worst-case run- time of mystery is ( n )? [1 mark] (1) ii. If the worst-case runtime of another mystery is ( n 2 ), explain how it is possible for the worst-case runtime of mystery to be ( n ). [1 mark] This can happen if the best-case runtime of another mystery is (1) and only it occurs in this context (e.g. for x in L ). Alternatively, this can also happen if another mystery removes all the elements from L. (e) Which sorting algorithm would probably run fastest on the list L constructed as follows? [1 mark] L = range(100000000) L.append(7.2) L.append(3.14) L.append(6.0) insertion sort (because the list is nearly sorted) Page 1 of 8 CS 234 Fall 2010 Midterm Model Solutions 2. Answer each of the following questions by giving a short Python code fragment....
View Full Document

Page1 / 7

MidtermSolutions - CS 234 Fall 2010 Midterm Model Solutions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online