CS 165 - Test 4

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Select the options below that are interfaces as per Java Collections framework: List Queue LinkedList Stack

List Queue

Picture a pile of coins on a table. If three coins were taken off from the top and two new coins were added on top of the pile, would this pile represent a stack or would it represent a queue?

Stack

Assume the following code: LinkedList l=new LinkedList();l.add(2);l.add(1,2);l.add(0,4);l.add(2,10);l.add(3,20);l.add(2,30);l.add(3,40); What does l now contain?

[4, 2, 30, 40, 10, 20, 2]

Assume the following sequence of operations on a stack "s": s.push(9); s.push(3); int a=(Integer)s.pop(); s.push(4); int b=(Integer)s.pop(); s.push(2); s.push(7); int c=(Integer)s.pop(); What do a, b and c store?

a = 3, b = 4, c = 7

Assume the following sequence of operations on queue "q": q.offer(9); q.offer(3); int a=(Integer)q.poll(); q.offer(4); int b=(Integer)q.poll(); q.offer(2); q.offer(7); int c=(Integer)q.poll(); What do a, b and c store?

a=9, b=3, c=4

What are the types of collections allowed by the Java Collections framework? tuples maps sets lists

lists maps sets

Which of the following options are methods from the queue class that can be used to delete elements from a queue? offer() poll() remove() peek()

poll() remove()

Which of the following options are methods from the stack class that can be used to delete elements from a stack? top() delete() pop() push()

pop()

Assume that a queue named "q" has been declared to store numbers, and the following operations are performed on the queue in that order: q.offer(4); q.offer(5); q.offer(6); q.peek(); What would q.peek() return?

4

Assume the following code:LinkedList l=new LinkedList();l.add(4);l.add(1,5);l.add(2,1);l.add(3,2);l.add(1,3);l.peekFirst(); What does l.peekFirst() return?

4

Assume that a stack named "s" has been declared to store numbers, and the following operations are performed on the stack in that order: s.push(4); s.push(5); s.push(6); s.pop(); What would s.pop() return?

6

Select all the statements below that are true about data structures: A data structure is a collection of programs and is also known as a library. A data structure allows for data to be accessed and manipulated in specific ways. A data structure can only be implemented in Java. A data structure is a collection of data organized in some fashion.

A data structure allows for data to be accessed and manipulated in specific ways. A data structure is a collection of data organized in some fashion.

Queues operate on Last In First Out principle.

False

Suppose a CPU needs to decide which instruction sets to process first depending on how "important" the instruction sets are, and not based on which instruction set requested CPU time first. Which data structure should the CPU use? linked list stack priority queue queue

Priority Queue

If there is a line of people waiting to purchase movie tickets, and the person at the front of the line is the first to be served and to leave the queue, and any new person would have to join the line at the back, would this be a stack or a queue?

Queue

Stacks work on Last In First Out (LIFO) principle

True


Ensembles d'études connexes

EAQ: Mental Health Foundations-Intermediate

View Set

Cultural Anthropology Lectures 3 & 4

View Set

Chapter 25 point of care sonography

View Set