This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 realworld 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 worstcase runtime of another mystery guarantees that the worstcase run time of mystery is ( n )? [1 mark] (1) ii. If the worstcase runtime of another mystery is ( n 2 ), explain how it is possible for the worstcase runtime of mystery to be ( n ). [1 mark] This can happen if the bestcase 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
 Fall '09
 BARANOSKI
 Algorithms

Click to edit the document details