{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MidtermSolutions

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern