Sprint2019-Quiz4 Key1 2.docx - COMP 2150 – Spring 2019 Quiz 4 Stacks Queues LinkedList Set 69 points Multiple Choice(14 pts 2 each Questions 1-2 refer

# Sprint2019-Quiz4 Key1 2.docx - COMP 2150 – Spring 2019...

• Test Prep
• 6

This preview shows page 1 - 3 out of 6 pages.

COMP 2150 – Spring 2019 Quiz 4: Stacks, Queues, LinkedList, Set. ( 69 points) Multiple Choice (14 pts, 2 each) Questions 1-2 refer to the code below: // Assume s is an initially empty Stack<String> object s . push ( "Susan" ); s . peek (); s . push ( "Greg" ); s . pop (); s . push ( "Casey" ); s . push ( "Darnell" ); s . peek (); s . push ( "Bennett" ); s . pop (); s . peek (); 1.What element is at the top of the stack after the code executes? (A)Susan(B)Darnell(C)Casey(D)Greg(E)Bennett 2. What happens when a new element is added to an arrayList that’s at maximum capacity? (A) An IndexOutOfBoundsException is thrown (B) A NullPointerException is thrown (C) Extra spaces are added to the end of the existing data array (D) A new larger data array is created, and the old elements are copied over (E) The add method executes, but does not change anything about the array list object 3. Suppose you want to visit every element of a single linked list. You write a loop that repeatedly calls get on each list index – list.get(0) , list.get(1) , list.get(2) , and so on. Assuming get is written the way that we did and used in our assignment exercise , what’s the overall Big-O (tightest possible bound) of this loop? (A) O(1) (B) O(log n ) (C) O( n ) (D) O( n 2 ) (E) O( n !)
4.Suppose you want to visit every element of a single linked list. You start by creating an iterator over thelist, then repeatedly call the iterator’s nextmethod until it runs out of elements. What’s the overall Big-O (tightest possible bound) of this loop?

#### You've reached the end of your free preview.

Want to read all 6 pages?

• Fall '08
• Staff

### 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