{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MidtermSolutions

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

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

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

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

View Full Document
CS 234 Fall 2010 Midterm Model Solutions 2. Answer each of the following questions by giving a short Python code fragment.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern