Midterm2 !!!

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following best describes the difference between overloading and overriding a method? There is no difference. They mean the same thing. When one method overrides another, both methods will have the same signature. When one method overloads another, both methods will have the same signature. Overloading only makes sense in the context of inheritance.

When one method overrides another, both methods will have the same signature.

The diagram below suggests how we could implement a double-ended linked list, in which we maintain a reference to both the first and last nodes in the linked list. Which one of the following operations would be inefficient to carry out when there are a large number of elements in the linked list? insertion at the end to which rear refers deletion from the end to which front refers test for an empty linked list insertion at the end to which front refers deletion from the end to which rear refers

deletion from the end to which rear refers

Given the code fragment. which of the following expressions has the value null? Node p = new Node(12); Node q = new Node(5); p.next = q; q.next = p; ------- p.next.next none of the above q.next p p.next.next

p.next.next

What is the reason for using a "circular queue" instead of a regular one?

reuse empty spaces

What data structure can be used to check if a syntax has balanced parenthesis?

stack

What is the prefix version of the following expression: ( ( AX + ( B * CY ) ) / ( D E ) )

/ + AX * B CY D E

If the sequence of operations - push (5), push (0), pop, push (9), push (2), pop, pop, pop, push (2), pop are performed on an initially empty stack, the sequence of popped out values is:

02952

A stack S of integers initially contains the following data: 6 (top) 2 7 3 The following code is then executed: int x = S.pop(); int y = S.pop(); int z = S.pop(); S.push(x + y); int w = S.pop(); S.push(w + z); After this code has been executed, what are the contents of the stack?

15 3

Given a 5 element queue Q (from front to back: 1, 3, 5, 7, 9), and an empty stack S, remove the elements one-by-one from Q and insert them into S, then remove them one-by-one from S and re-insert them into Q. Select, what are the contents of the queue now look like (from front to back)?

9, 7, 5, 3, 1

What is the Postfix version of the following expression: ( ( AX + ( B * CY ) ) / ( D E ) )

AX B CY * + D E /

You have a singly linked list constructed out of nodes defined as follows: public class Node { public int datum; public Node next; } In the function shown below, the parameter f refers to the first node in the linked list, if there is one, and has the value null otherwise. The intent of the function is to remove the last node of the linked list. public void removeLast(Node first) { Node p, q; p = first; q = p.next; while (q.next != null) { p = q; q = q.next; } p.next = null; } Which of the following describes the class of linked lists for which this function works correctly?

All linked lists with more than one node

What is the need for a circular array compared to a non-circular array-based implementation of a queue?

Effective usage of memory

T/F A method must always catch any exception that is raised when that method is executed.

F

Assuming that A is an interface, which of the following is true? It is possible to instantiate an object of type A. It is possible to declare a variable of type A. Both are true. Neither are true.

It is possible to declare a variable of type A.

Given a collection of algorithms that runs on O(1), O(n log n), O(n), O(n2 ), O(log n), O(n!), order the algorithms from fastest to slowest.

O(1), O(log n), O(n), O(n log n), O(n2 ), O(n!)

For the following code, count the number of operations where some_statement is executed based on the loops for (int j = 1 ; j < n ; j *= 2) { for (int I = 1; i < n ; i++) { some_statement ; } }

O(n(log(n))

Finding the max element in an unordered stack would require

O(n) operations

For the following code, count the number of operations where some_statement is executed based on the loops for (int I = 0; I < n; I +=2){ for (int j = 1; j < n; j++) { some_statement; }}

O(n^2)

Which of the following is described as "dynamic binding"? The contents of variables may change dynamically at run-time. An object may dynamically change its superclass at run-time. The JVM dynamically determines which method to call based on the object's type at run-time. The JVM dynamically determines which method to call based on the variable's type at run-time.

The JVM dynamically determines which method to call based on the object's type at run-time.


Conjuntos de estudio relacionados

FIN611 Chapter 10 Test Review, Chapter 10 - Capital Budgeting, Finance 5320-Chapter 10-Vocabulary: The Basics of Capital Budgeting: Evaluating Cash Flows, FMGT 4510 Chapter 10

View Set

Chemistry II-chapter 1 study guide

View Set

Criminal Justice Today Ch 10: Pretrial Activities and the Criminal Trial

View Set

Pharmacology Chapter 29: Pain Management in Patients with Cancer

View Set