CS-182

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following strings is NOT a palindrome? "madam" "" "adam" "deed"

"adam"

Which of the following strings is a palindrome?

"r"

The Java ______ operator is used to obtain the wraparound effect of a circular array-based queue.

%

Which of the following is a fully parenthesized expression? x * y + z (x * y) + z ((x * y) + z) (x) * (y) + (z)

((x * y) + z)

The midpoint of a sorted array can be found by ______, where first is the index of the first item in the array and last is the index of the last item in the array. first / 2 + last / 2 first / 2 - last / 2 (first + last) / 2 (first - last) / 2

(first + last) / 2

Which of the following is NOT a valid prefix expression? - + a b + c d / a + b c * + * a b c d * - a b c d

* - a b c d

For anArray = <2, 3, 5, 6, 9, 13, 16, 19>, what is the value returned by a recursive binary search algorithm if the value being searched for is 10? -1 0 1 10

-1

Which of the following is the prefix form of the infix expression: (8 + 6) / (16 - 4)?

/ + 8 6 - 16 4

Which of the following is a prefix expression? / a + b c a b c + / a * b + c a / (b + c)

/ a + b c

To initialize a queue that is represented by a circular array, front is set to ______.

0

A recursive solution that finds the factorial of n always reduces the problem size by ______ at each recursive call. 1 2 half one-third

1

The factorial of zero is ______. -1 0 1 2

1

Write a recursive definition for the set of positive odd numbers.

1 is odd, and if n is odd, so is n+2.

If we wanted to write an if-statement that executes whenever the real number x is between 10.0 and 20.0, how should the test condition be written? 10.0 < x || x > 20.0 10.0 < x && x > 20.0 10.0 < x && x < 20.0 10.0 < x || x < 20.0

10.0 < x && x < 20.0

What is the value of the prefix expression: - * 3 8 + 6 5?

13

How many bases cases will be required in a recursive solution that solves a problem by solving two smaller problems of the same type? 0 1 2 3

2

What is the value of sum after the following code executes? int sum = 0; int count = 0; while (count < 4) { sum += count / 2; count += 1; }

2

What is the value of the infix expression: 8 * (5 - 2)?

24

The Towers of Hanoi problem makes exactly ______ moves when it starts with N disks. 2^N 2^N - 1 N^2 N^3 - 1

2^N - 1

Which of these is not a legal Java identifier? 2be to_be TOBE tobE

2be

For anArray = <2, 3, 5, 6, 9, 13, 16, 19>, what is the value returned by a recursive binary search algorithm if the value being searched for is 6? 1 3 4 6

3

If x is a variable of type int, what is the largest possible value of the expression (x % 5) ? 1 4 5 2^31 - 1

4

If s = "hello, world" (with exactly one space between the comma and 'w'), what does s.indexOf(",") return?

5

In the Fibonacci sequence, which of the following integers comes after the sequence 1, 1, 2, 3? 3 4 5 6

5

The Java expression 9 / 5 + 9 % 5 equals ______. 0 1 3 5 6

5

What is the value of the postfix expression: 6 7 + 8 2 - *? -3 -10 48 78

78

What are the three types of operations on data?

: Add data to a data collection. Remove data from a data collection. Ask questions about the data in a data collection.

What are the three principles of object-oriented programming?

: Encapsulation: objects combine data and operations Inheritance: classes can inherit properties from other classes Polymorphism: objects can determine appropriate operations at execution time

The correct grammar for the following language L: L = {w: w is of the form SnDn for some n ≥ 0} is ______. <legal-word> = S | <legal-word> | D <legal-word> = empty string | S | <legal-word> | D <legal-word> = S <legal-word> D <legal-word> = empty string | S <legal-word> D

<legal-word> = empty string | S <legal-word> D

What is a base case?

A base case is a special case of a recursive solution that terminates the recursive processing

What is a closed-form formula?

A closed-form formula is a nonrecursive algebraic expression.

What is an Application Programming Interface (API) ? Why is it useful?

A collection of preexisting software that is part of the run-time library of your Java installation. It contains predefined classes and methods for commonly used data structures and operations so that you do not have to reinvent the wheel.

When is a compiler-generated default constructor created?

A compiler-generated default constructor is created when the programmer does not include any constructor in a class.

What is a constructor?

A constructor is a method that creates and initializes new instances of a class.

What is data abstraction?

A data abstraction is a design principle that separates the operations that can be performed on a collection of data from the implementation of the operations.

What is a data structure?

A data structure is a construct that is defined within a programming language to store a collection of data.

What is a deque?

A deque is an ADT that allows for insertions and deletions at both ends.

What is a dummy head node?

A dummy head node is a first node that is not used for data but is always present, even when the linked list is empty.

What is a fully parenthesized expression?

A fully parenthesized expression is one that has parentheses around each pair of operands together with their operator.

What is meant by a grammar?

A grammar states the rules for forming the strings in a language.

What is the difference between a linked list and an array in terms of their capacity to store data?

A linked list is able to grow as needed, whereas, an array can hold only a fixed number of data items.

What is a loop invariant?

A loop invariant is a condition that is true before and after each execution of an algorithm's loop.

When is a method in a subclass said to override a method in the superclass?

A method in a subclass is said to override a method in the superclass if the two methods have the same declarations.

What are some of the benefits of modularity?

A modular problem is easier to write, read, and modify. Modularity also isolates errors and eliminates redundancies.

What is a mutator method?

A mutator method is a method that sets a data field's value.

What does a node of a linear linked list contain?

A node of a linked list contains data and a reference to the next node in the list.

How can a package be created in Java?

A package can be created by placing a package statement at the top of each class file that is part of the package.

What is a pivot item?

A pivot item is an element that an algorithm uses to organize data by value.

What is a postfix expression?

A postfix expression is an algebraic expression in which every binary operator follows its two operands.

What is a prefix expression?

A prefix expression is an algebraic expression in which every binary operator precedes its two operands.

What is a prototype program and what is it used for?

A prototype program is a program that simulates the behavior of portions of the desired software product. It is used to clarify the specifications of the software.

What is a recognition algorithm?

A recognition algorithm is based on a language's grammar, and determines whether a given string is in the language.

What is a head record?

A record that contains the external reference to the first node in a linked list, along with global information about the list, such as its length.

What is a recurrence relation?

A recurrence relation is a mathematical formula that generates the terms in a sequence from previous terms.

What information is stored in a reference to an object?

A reference to an object contains the location, or address in memory, of the object.

How does a sequential search work?

A sequential search starts at the beginning of the collection and looks at every item in the collection in order until the item being searched for is found.

What is an event-driven simulation?

A simulation that uses events generated by a mathematical model that is based on statistics and probability.

What is a superclass?

A superclass is a class from which another class is derived.

What is a tail-recursive method?

A tail-recursive method is a method where the solitary recursive call in the method is the last action that the method takes.

What does a traversal operation do?

A traversal operation sequentially visits each node in a list until it reaches the end of the list.

What is meant by the first-in, first-out property of a queue?

According to the first-in, first-out property of a queue, the first item inserted into a queue is the first item to leave the queue.

What is an abstract data type (ADT)?

An ADT is a collection of data together with a set of operations on that data.

What is an accessor method?

An accessor method is a method that returns a data field's value.

What is an activation record?

An activation record is a record that contains a method's local environment at the time of and as a result of the call to the method.

What is an axiom?

An axiom is a mathematical rule.

What is an empty string?

An empty string is a string of length zero.

What is the difference between an external event and an internal event?

An external event is an event that is determined from the input data to an event-driven simulation. An internal event is an event that is determined by a computation within an event-driven simulation.

What is the advantage an implementation of a queue that uses the ADT list over an implementation that uses a linked list?

An implementation of a queue that uses the ADT list is much simpler to write and read than an implementation that uses a linked list.

What is an infix expression?

An infix expression is an algebraic expression in which every binary operator appears between its two operands.

What kind of relationship exists between a superclass and a subclass?

An is-a relationship exists between a superclass and a subclass.

Short-circuit evaluation refers to: Jumping from the try block to the catch block when an exception is thrown. Avoiding the testing of a boolean condition that is unnecessary. Truncating the integer result of a division operation. Avoiding the execution of the else clause of an if-statement.

Avoiding the testing of a boolean condition that is unnecessary.

______ is a problem-solving technique that involves guesses at a solution.

Backtracking

Why is a loop necessary to find an arbitrary node in a linked list?

Because a linked list typically has many nodes, and the list itself maintains at most only references to the head and tail of the list. To visit any of the other nodes requires us to traverse the list until we find the appropriate one.

Why does the Java statement System.out.println("answer = " + 3 + 4); not print answer = 7 ?

Because the + operator is left-to-right associative. We evaluate the first + first, and by doing so we concatenate the integer 3 into the string. Then, we concatenate the 4 into the string.

How do checked exceptions and runtime exceptions differ in the way that they are handled?

Checked exceptions must be handled locally or explicitly thrown from the method. Runtime exceptions do not have to be caught locally or explicitly thrown again by the method.

In a UML diagram, what does it mean if there is an arrow pointing from class A to class B? .

Class A is a subclass of class B

What is the meaning of the declaration: String [][] a = new String [60][80]; ? Create an array of 60 strings, each of size 80 characters. Create an array of 80 strings, each of size 60 characters. Create a two-dimensional array of strings with 60 columns and 80 rows. Create a two-dimensional array of strings with 60 rows and 80 columns.

Create a two-dimensional array of strings with 60 rows and 80 columns.

What are the three high-level steps to insert a new node into a linear linked list?

Determine the point of insertion. Create a new node and store the new data in it. Connect the new node to the linked list by changing references.

Which of the following is an example of a wrapper class? Double int String System

Double

In the following list: John, Kate, Fred, Mark, Jon, Adam, Drew which element is the tail of the list? John Mark Drew Adam

Drew

What are exceptions used for?

Exceptions are used for handling errors during the execution of a program.

In order to declare a named constant, the declaration must use which Java keyword? final int static void

Final

Name two advantages of implementing the ADT list as an array instead of using a linked list (reference based).

Finding a value does not require a loop. Takes up less memory.

What are two advantages of using a reference-based implementation of the ADT list instead of an array-based implementation?

First, a reference-based implementation does not shift items during insertion and deletion operations. Second, a reference-based implementation does not impose a fixed maximum length on the list.

Name two important features of fail-safe programming.

First, error checking of input. Second, checking of the program's own logic and assumptions before critical operations are performed.

What is the procedure for proving a statement by mathematical induction?

First, show that the base case(s) are correct. Then we make an inductive hypothesis, that the statement is true for some integer k. Finally, we show that if the statement is true for k, it follows that it is also true for k+1.

What are the four parts necessary to proving that a loop is correctly implemented?

First, the loop invariant must be true initially. Second, executing the loop from one iteration to the next must preserve the truth of the loop invariant. Third, the loop invariant must capture the correctness of the algorithm (i.e. must be materially correct). Finally, the loop must terminate.

When using the method System.out.printf( ), what is the purpose of the %d format code? For printing a double For printing a float For printing a String For printing an int

For printing an int

What is the goal of a simulation?

Generally, the goal of a simulation is to generate statistics that summarize the performance of an existing system or to predict the performance of a proposed system.

What are the four questions that must be considered when constructing a recursive solution?

How can you define the problem in terms of a smaller problem of the same type? How does each recursive call diminish the size of the problem? What instance of the problem can serve as the base case? As the problem size diminishes, will you reach this base case?

For defining palindromes, why is it not enough to use just the empty string as a base case?

If a string has an odd length, we will eventually get down to the case of a string of length 1, which should also be a base case because it is a trivial palindrome.

Which of the following exceptions can be thrown if an object cannot be instantiated? IllegalAccessException ArithmeticException IndexOutOfBoundsException NoSuchMethodException

IllegalAccessException

In Java, when is an object marked for garbage collection?

In Java, an object is marked for garbage collection when there is no reference to that object.

What is the difference between a linear linked list and a circular linked list?

In a circular linked list, the next portion of the last node of the list references the first node in the list. This is not the case with a linear linked list, where the next portion of the last node contains the value null.

What is the main difference between a stack and a queue?

In a stack, all operations are performed at the top of the stack. As a result, the first item to enter the stack is the last item to leave the stack. In contract, operations are performed at both ends of a queue. In a queue, the first item to enter the queue is the first item to leave the queue.

Suppose a program contains a recursive method findFibonacci(int n), which computes the n-th Fibonacci number. Even if we know that a client method will never call findFibonacci( ) with the values 1 or 2 as arguments, why does the implementation of findFibonacci( ) still need to have base cases?

In the course of findFibonacci's own recursion it will eventually reach values of n = 1 or 2 that it passes to itself. If these are not identified as base cases, then the recursion will logically continue forever, which is incorrect.

______ can be used to prove properties about recursive algorithms. Prefix notations Postfix notations Induction Backtracking

Induction

What is information hiding?

Information hiding is a process that hides certain implementation details within a module and makes them inaccessible from outside the module.

What is meant by information hiding?

Information hiding refers to hiding the details of a module from public view and ensuring that no other module can temper with these hidden details.

______ enables the reuse of existing classes.

Inheritance

is the ability of a class to derive properties from a previously defined class.

Inheritance

Name two advantages of implementing the ADT list as a linked list (reference based) instead of an array. .

Inserting and removing do not require a loop. There is no notion of a linked list becoming "full" and having to be reallocated and moved to a larger space

What is meant by object type compatibility?

It is a characteristic of objects that enables you to use an instance of a subclass where an instance of the superclass is expected, but not the converse.

What is wrong with this loop? How would you fix it? int num = 1; while (num <= 10) { System.out.println("num = " + num); } .

It is an infinite loop. After the print statement, we need to increment num, as in the statement num++;

Interpret the overall meaning of this if-statement: if (num % 7 == 0 || num % 11 == 0)

It tests to see if the value of num is divisible by either 7 or 11.

Suppose we want to write a loop that traverses a doubly-linked circular linked list. Assume that each node has a prev and a next reference, and the list itself maintains a reference to a head node. What is wrong with this loop header? for (Node curr = head; curr != head.prev; curr = curr.next)

It will stop just short of the last node.

Give two examples of run-time errors or exceptions that may occur when we enqueue or dequeue.

It's an error to attempt to dequeue from an empty queue. Also, if the queue is represented as an array and we try to enqueue, we may run up against the maximum size of the queue.

In the following list: John, Kate, Fred, Mark, Jon, Adam, Drew which element does not have a predecessor? John Mark Drew Kate

John

In the following list: John, Kate, Fred, Mark, Jon, Adam, Drew which element is the head of the list? John Mark Drew Adam

John

What are the three high-level steps to delete a node from a linear linked list?

Locate the node that you want to delete. Disconnect this node from the linked list by changing references. Return the node to the system

What are some ways of finding logic errors?

Logic errors can be found by using watches, breakpoints, or temporary System.out.println statements.

To initialize a queue that is represented by a circular array, back is set to ______.

MAX_QUEUE - 1

Name two things that an abstract class may include that an interface would not.

Method implementations, and data members.

What are some of the benefits of modularity?

Modularity makes it easier to construct large programs. Modularity also isolates errors which makes it easier to debug the program. Also, modular programs are easier to read. Modularity also isolates modifications to the code, and eliminates redundant code.

Do all Java source files define classes? Explain.

No. Sometimes a Java source file defines an interface instead.

If a linked list is empty, the statement head.getNext() will throw a(n) ______. IllegalAccessException ArithmeticException IndexOutOfBoundsException NullPointerException

NullPointerException

If you attempt to use a reference variable before it is instantiated, a(n) ______ will be thrown. IndexOutOfBoundsException InstantiationException IllegalAccessException NullPointerException

NullPointerException

In Java, every class is ultimately derived from the class _____ through inheritance. String Object Math Exception

Object

_______ is a process that transforms an object into a stream of bytes that can be saved to and restored from a file. Information hiding Object serialization Encapsulation Inheritance

Object serialization

______ is the ability of a variable name to represent, during program execution, instances of different but related classes that descend from a common superclass.

Polymorphism

What are some of the advantages of using an object-oriented approach to the development of a software?

Previously implemented classes can be reused in future programs. Program maintenance is easier. Program verification is easier.

What is the benefit of procedural abstraction?

Procedural abstraction enables the use of a method, without knowing the particulars of its algorithm, as long as a statement of its purpose and a description of its parameters are present.

What is procedural abstraction?

Procedural abstraction is a design principle that separates the purpose and use of a module from its implementation.

What is meant by procedural abstraction?

Procedural abstraction refers to separating the purpose of a method from its implementation.

Define the problem of rightward drift in an array-based implementation of a queue.

Rightward drift is the problem of the front of the queue moving toward the end of the array.

Which of the following is NOT a precondition for an array that is to be sorted by a recursive binary search algorithm? (first is the index of the first item in the array, last is the index of the last item in the array, and SIZE is the maximum size of the array) SIZE <= first 0 <= first last <= SIZE - 1 anArray[first] <= anArray[first + 1] <= ... <= anArray[last]

SIZE <= first

Why do some compilers automatically replace tail recursion with iteration?

Some compilers automatically replace tail recursion with iteration because tail-recursive methods are often less efficient than their iterative counterparts and the conversion of a tail-recursive method to an equivalent iterative method is rather mechanical.

What are the nine phases of the software life cycle?

Specification, design, risk analysis, verification, coding, testing, refining, production, and maintenance.

How many times are the indicated statements (#1) and #2) each executed? for (int i = 1; i <= 10; ++i) for (int j = 1; j <= 10; ++j) for (int k = 1; k <= 5; ++k) ++count; // statement #1 System.out.printf("%d\n", count); // statement #2

Statement #1 executes 500 times, and statement #2 executes 1 time.

Which is not a primitive type in Java?

String

A built-in class that helps to split strings into pieces, such as words of a sentence, is:

StringTokenizer

The following code containing a loop attempts to find how many times the letter 'r' appears in a string. But something is wrong with the loop. How would you fix it? String s = "railroad"; int count = 0; char letter = s.charAt(index); for (int index = 0; index < s.length(); ++index) if (letter == 'r') ++count;

The assignment to letter needs to be moved down into the loop right before we check to see if the letter is an r.

What is the base case for the recursive solution to the Towers of Hanoi problem?

The base case for the recursive solution to the Towers of Hanoi problem is a recursive call that has only one disk to move.

When is the base case of the Eight Queens problem reached?

The base case of the Eight Queens problem is reached when there are no more columns to consider.

What is the box trace?

The box trace is a systematic way to trace the actions of a recursive method.

What does it mean for a class to "implement an interface" ?

The class definition provides an implementation (i.e. code) for all methods named in the interface.

Define the client of a class?

The client of a class is a program or module that uses the class.

What will happen when you try to run a program that has a syntax error?

The compiler will not be able to compile your program, because it does not understand your code. Thus, no class file (byte code) will be created to run on the Java virtual machine.

What is the action performed by the dequeue operation?

The dequeue operation retrieves and removes the front of a queue - the item that was added earliest. It throws a QueueException if the operation is not successful.

What is the action performed by the dequeueAll operation?

The dequeueAll operation removes all items from a queue.

What is the action performed by the enqueue operation?

The enqueue operation adds a new item at the back of a queue. It throws a QueueException if the operation is not successful.

Suppose a try block needs to be followed by two catch blocks, each catching a different exception. Which exception should be caught first? The exception that is more likely to occur The exception that is more general The exception that is more specific It does not matter in what order exceptions are caught

The exception that is more specific

Suppose s is of type String. What would it mean if s.lastIndexOf(s.charAt(0)) returns the value 1? The first character appears once in the string. The first two characters in the string are identical. The length of the string is 2. The second character of the string is '0'.

The first two characters in the string are identical.

List the information provided in a method's postcondition.

The information provided in a method's postcondition includes the method's effect on its parameters - or in the case of a valued method, the value it returns - and any other action that has occurred.

List the information provided in a method's precondition.

The information provided in a method's precondition includes the method's formal parameters, any class named constants that the method uses, and any assumptions that the method makes.

What elements are included in a method's local environment?

The local environment of a method includes the method's local variables, a copy of the actual value arguments, a return address in the calling routine, and the value of the method itself.

What is the main benefit of using a grammar that is recursive?

The main benefit of a grammar that is recursive is that, based on the grammar, it is very easy to write a recognition algorithm for the language.

What does it mean for the return type of a method to be void? The method will never return a value. The method will return the value zero. The method does not take parameters. The method does not have a body.

The method will never return a value.

What are some good guidelines for deciding on a name for a method of a class?

The name should sound like a verb (e.g. findArea( ) instead of just area( )). Also the first letter should be lowercase, and all other letters should be lowercase except the initial letters of subsequent words.

If the implementation of a linked list maintains information about only one node, the head of the list, how is it able to be a collection of more than one node? In other words, how can we have a linked list of 20 nodes, if the list implementation only stores information about the head node?

The nodes are all linked to each other. So if we start at the head node and follow the "next" reference repeatedly, we are able to find all the other nodes.

What is meant by the object-oriented approach to modularity?

The object-oriented approach to modularity produces a collection of objects that have behaviors. An object is a component of a modular solution that combines data and operations on the data.

What is the action performed by the peek operation?

The peek operation retrieves the front of a queue, but does not change the queue. That is, it retrieves the item that was added earliest. It throws a QueueException if the retrieval is not successful.

What is the difference between the physical size and the logical size of an array?

The physical size of an array is the maximum length of the array. The logical size of an array is the number of items currently in the array.

Describe in your own words the language defined by this recursive definition: < S > = @ | < W > | @ < S > < W > = aab | aa < W > b

The set of words containing: an arbitrary number of @ symbols, followed by instances of the letter a, followed by instances of the letter b: where there are twice as many a's as b's.

What are the two base cases for a recursive binary search algorithm?

The two base cases are: first > last value == anArray[mid] (where first is the index of the first item in the array, last is the index of the last item in the array, and mid is the midpoint of the array).

What are the two base cases in a recursive description of a palindrome?

The two base cases in a recursive description of a palindrome are strings of length 0 and strings of length 1.

What are the two factors which contribute to the inefficiency of some recursive solutions?

The two factors are the overhead associated with method calls, and the inherent inefficiency of some recursive algorithms.

What are the two basic kinds of relationships among classes?

The two kinds of relationships are: is-a relationship and has-a relationship.

Suppose c1 and c2 are objects of the class Circle. A Circle has a single data member, its radius. The Circle class has a default constructor (implemented correctly), but no other methods have been defined in the implementation of the Circle class. What will happen when we try to execute this code? Circle c1 = new Circle(12.0); Circle c2 = new Circle(12.0); boolean same = (c1.equals(c2)); The code will not compile because equals( ) has not been implemented in Circle. The value of same will be true. The value of same will be false.

The value of same will be false.

How many constructors can a class have? Exactly one At least one but no more than three Exactly the same as the number of data members There is no restriction on the number of constructors

There is no restriction on the number of constructors

When is the base case value == anArray[mid] (where mid is the midpoint of the array) reached in a recursive binary search algorithm?

This base case is reached when the value being searched for is in the original array

When is the base case first > last (where first is the index of the first item in the array and last is the index of the last item in the array) reached in a recursive binary search algorithm?

This base case is reached when the value being searched for is not in the original array.

What kind of methods are appropriate to implement in an abstract class?

Those that provide access to private data fields, or that express functionality common to all of its subclasses.

What are three examples of position-oriented ADT?

Three position-oriented ADTs are the list, the stack and the queue.

How is the finally keyword used in Java? To indicate that a method should terminate and pass a value to the calling environment. To indicate the last statement that will execute in a program. To indicate an action that should take place whether an exception occurred or not. To indicate a termination condition for a loop.

To indicate an action that should take place whether an exception occurred or not.

Explain how you would design a method, returning boolean, that determines if a string passed as a parameter satisfies this recursive definition. < S > = < W > < W > < W > = a | b | a < W > | b < W >

We are basically looking to see if the string is the same substring repeated twice, such as "abcdabcd". First, return false if the string length is less than 2 or odd. Next, find the midpoint of the string, and create two substrings, s1 and s2. Then, check to see if s1 matches s2.

In Java, how do we tell the compiler that the body of a loop consists of several statements, rather than one? We enter all the statements on the same line We indent all the statements at the same level of indentation We enclose the statements in curly braces We insert a break statement at the end of the loop

We enclose the statements in curly braces

Suppose c is a variable of type char. We want to know if c is a lowercase vowel letter (a/e/i/o/u). What is wrong with the following comparison? if (c == 'a' || 'e' || 'i' || 'o' || 'u')

We have to repeat the "c ==" each time we want to perform a comparison. A vowel by itself is not a boolean expression.

If an object is inserted into a queue, how soon can it be removed?

We have to wait for all of the other elements to be dequeued first, because of the inherent FIFO policy of queues.

Why does the Fibonacci sequence have two base cases? In other words, would it be possible to write a correct recursive Fibonacci method that has only one base case?

We need two base cases, because if we don't, by the time we get down to the case where n = 2, fib(2) is defined in terms of fib(1) and fib(0), and fib(0) is undefined. Since fib(0) is undefined its recursion will continue down forever.

If you wanted to write a program to simulate queues in front a bank teller, on what basis would you decide on a maximum size of your queue?

We would first consider how many people could realistically be waiting on line at the same time.

What are some of the questions that must be answered during the specification phase of the software life cycle?

What is the input data? What data in valid and what data is invalid? Who will use the software, and what user interface should be used? What error detection and error messages are desirable? What assumptions are possible? Are there special cases? What is the form of the output? What documentation is necessary? What enhancements to the program are likely in the future?

What is an advantage to defining an ADT that uses a generic data type? .

When retrieving an item from the ADT, it won't be necessary to cast the return value from Object, and we can thus avoid class cast exceptions if the type of the data in the collection was inappropriate

If an ADT list is implemented as an array, why would it be necessary for the ADT operations to "shift" elements?

When we want to insert a value in between two existing values in the array, all the entries to the right of the new value need to be shifted to the right by one position to make room. Analogously, when we remove an element from the interior of an array, we don't want to leave a blank, so we shift left by one position those elements to the right of where we just deleted.

Is it legal for a subclass of an abstract class not to implement all of the methods it inherits? Briefly explain.

Yes, but it would then have to declare those unimplemented methods as abstract.

Can the object type of an argument in the call to a method be difference from the object type of the corresponding formal parameter? Explain.

Yes, the two object types can be different. The object type of an argument in a call to a method can be a subclass of the corresponding formal parameter's object type.

What feature of Java allows you to enforce information hiding when you define a class such as an ADT? .

You can declare the data members as private instead of public

Which of the following is an infix expression? / a + b c a b c + / a b / + c a / (b + c)

a / (b + c)

Which of the following is the postfix form of the infix expression: a * b - (c + d)? a b c d + - * a b * c d + - a b c - * d + a b c - d + *

a b * c d + -

Which of the following is the postfix form of the prefix expression: * + a b c? a + b * c a + b c * a b + c * a b * c +

a b + c *

Which of the following is a postfix expression? / a + b c a b c + / * a b c / + a / (b + c)

a b c + /

Which of the following is NOT a valid postfix expression? a b c - d * a b - c d + - a b c + / a b * c + d *

a b c - d *

Object-oriented programming views a program as ______. a sequence of actions a sequence of statements a group of methods a collection of objects

a collection of objects

Which of the following is true about a constructor in Java? all constructors have a return type of void a constructor cannot have parameters a constructor has the same name as the class a class can only have a single constructor

a constructor has the same name as the class

What is an access modifier?

a keyword which is used to control the visibility of the members of a class.

Which of the following is an example of an error in input data? a program encounters an instruction to divide by zero an array subscript in a program goes out of range an algorithm that converts a temperature in Celsius to Fahrenheit displays the wrong results a program expects a positive number but reads -23

a program expects a positive number but reads -23

What is meant by dynamic binding?

a situation in which the appropriate version of a method is decided at execution time.

What is meant by static binding?

a situation in which the appropriate version of a method is determined at compilation time.

What is backtracking? .

a strategy for guessing at a solution and backing up when an impasse is reached

In a recursive method that writes a string of characters in reverse order, the base case is ______. a string with a length of 0 a string whose length is a negative number a string with a length of 3 a string that is a palindrome

a string with a length of 0

Which of the following CANNOT be used in a linear linked list? a head node a dummy head node a precede reference a tail reference

a tail reference

A subclass that fails to implement all of the abstract methods of its superclass must be declared as a(n) ______ class.

abstract

If a method definition in a superclass has the field modifier ______, a subclass is required to override the method. static protected final abstract

abstract

A(n) ____ is a collection of data and a set of operations on the data.

abstract data type

In the box trace, each box roughly corresponds to a(n) ______. recursive relation activation record base case pivot item

activation record

A(n) ______ is a step-by-step specification of a method to solve a problem within a finite amount of time. prototype module solution algorithm

algorithm

An event list for an event-driven simulation of a bank contains ______.

all arrival and departure events that will occur but have not occurred yet

Which of the following is NOT true about packages?

all classes in a package are available to clients of the package

The statement: JavaPrograms = {strings w : w is a syntactically correct Java program} signifies that ______. all strings are syntactically correct Java programs all syntactically correct Java programs are strings the JavaPrograms language consists of all the possible strings a string is a language

all syntactically correct Java programs are strings

Which of the following is an example of a logical error? an algorithm that calculates the monthly payment of a loan displays incorrect results an array subscript in a program goes out of range a program expects a nonnegative number but reads -23 the beginning of a while loop is written as "whille" instead of "while"

an algorithm that calculates the monthly payment of a loan displays incorrect results

Which of the following is an example of an exception? a statement does not contain a semicolon at the end an array subscript in a program goes out of range an algorithm that converts a temperature in Celsius to Fahrenheit displays the wrong results a program expects a positive number but reads -23

an array subscript in a program goes out of range

What type of Java statement allows you to use classes contained in other packages?

an import statement

What would happen if a negative value is passed to a method that returns the factorial of the value passed to it? the method will calculate the correct value for the factorial of the number the method will calculate a negative value for the factorial of the number the method would terminate immediately an infinite sequence of recursive calls will occur

an infinite sequence of recursive calls will occur

What is a subinterface?

an interface that is derived from an existing interface.

In a reference-based implementation of an ADT list ______. increasing the size of the list can waste storage and time less memory is required to store an item than in an array-based implementation an item explicitly references the next item the location of the item after a particular item is implied

an item explicitly references the next item

In a sorted array, the kth smallest item is given by ______. anArray[k-1] anArray[k] anArray[SIZE-k] anArray[SIZE+k]

anArray[k-1]

A statement about a particular condition at a certain point in an algorithm is called a(n) ______.

assertion

In the ADT list, items can be added ______.

at any position in the list

In the recursive solution to the kth smallest item problem, the problem size decreases by ______ at each recursive call. 1 at least 1 half at least half

at least 1

In Java, a class can extend ______. at most 1 class at most 16 classes at most 32 classes as many classes as required

at most 1 class

A(n) ______ can be used to precisely specify the behavior of each of the operations of an ADT. exception data structure axiom client

axiom

Consider the following code that appears in a test class. A a = new A(); int c = a.b; In order for this code to work, which statement must be true? a must be declared public inside class A b must be declared public inside class A c must be declared public inside class A Method b( ) must return int

b must be declared public inside class A

Write the code fragment to insert the item newItem into a queue that is represented by a circular array.

back = (back+1) % MAX_QUEUE; items[back] = newItem; ++count;

In a recursive solution, the ______ terminates the recursive processing. local environment pivot item base case recurrence relation

base case

The class from which another class is derived is known as the

base class

Suppose x and y are int variables. Write a statement that declares the boolean variable between, and sets this variable equal to true if the value of y is between 0 and x, inclusive, and equal to false otherwise. (Assume that you don't know if x is positive or negative.)

boolean between = (x >= y && y >= 0) || (0 >= y && y >= x);

Operations on a queue can be carried out at ______.

both its front and back

How can precedence and association rules be avoided in infix notation?

by using fully parenthesized expressions; that is, placing parentheses around each pair of operands together with their operator.

To ______ an exception means to deal with the error condition. throw catch implement declare

catch

A module reacts to an exception that another module throws by ______ the exception.

catching

A set of objects that have the same type is called a(n) ______.

class

A(n) ______ is a Java construct that enables a programmer to define a new data type. class method data field object

class

Java packages provide a way to group related ______ together.

classes

A program that uses an ADT is called a(n) ______. data structure interface axiom client

client

When you solve a problem by solving two or more smaller problems, each of the smaller problems must be ______ the base case than the original problem. closer to farther to either closer to or the same "distance" from either farther to or the same "distance" from

closer to

The syntax errors of a program are removed during the ______ phase of the program's life cycle.

coding

The Java ______ determines whether a given string is a syntactically correct Java program.

compiler

The symbol • means ______.

concatenate

A subclass inherits all of the following members of its superclass EXCEPT

constructors

Which of the following will be true when the reference variable curr references the last node in a linear linked list? curr == null head == null curr.getNext() == null head.getNext() == null

curr.getNext() == null

Write the code fragment to delete the node that the reference variable curr references in a circular doubly linked list?

curr.getPrecede().setNext(curr.getNext()); curr.getNext().setPrecede(curr.getPrecede());

Which of the following is true about a time-driven simulation of a bank?

currentTime is incremented by 1 to simulate the ticking of a clock

A class contains methods and ______. clients interfaces data fields data structures

data fields

A(n) ______ is a construct that can be defined to store a collection of data.

data structure

In the recursive solution to the Towers of Hanoi problem, the number of disks to move ______ at each recursive call. decreases by 1 increases by 1 decreases by half increases by half

decreases by 1

Which of the following is true about a circular doubly linked list? inserting into the first position of the list is a special case deleting from the last position of the list is not a special case the precede reference of the last node has the value null the next reference of the last node has the value null

deleting from the last position of the list is not a special case

The ______ operation retrieves and removes the front of a queue.

dequeue

The pop operation of the ADT stack is similar to the ______ operation of the ADT queue.

dequeue

If a queue is implemented as the ADT list, which of the following queue operations can be implemented as list.remove(1)?

dequeue()

Which of the following methods of QueueInterface does NOT throw a QueueException?

dequeueAll

The class which inherits the members of another class is known as the

derived class

A subclass is said to be a ______ of its superclass.

descendant

The data flow among the modules of a program is specified during the ______ phase of the software life cycle.

design

Which type of loop is guaranteed to execute its body at least once? do-while for switch while

do-while

Suppose a is a one-dimensional array of double. Show how you would find the largest element of a using Java code.

double max = a[0]; for (int i = 1; i < a.length; ++i) if (a[i] > max) max = a[i];

Suppose temp is an array of 12 double values that holds the average temperatures of the 12 months of the year, January through December, in that order. Use Java to find the average of the temperatures for the 3 summer months, June, July and August only, and set this answer to the variable summerAverage.

double summerAverage = (temp[5] + temp[6] + temp[7]) / 3.0;

Which of the following is true about all doubly linked lists? each node references both its predecessor and its successor the precede reference of the last node has the value null the last node references the first node the precede reference of the first node references the last node

each node references both its predecessor and its successor

Static binding is also known as ______.

early binding

The ______ operation adds a new item to a queue.

enqueue

In all circular linked lists, ______. every node references a predecessor every node references a successor the next reference of the last node has the value null each node references both its predecessor and its successor

every node references a successor

In the Eight Queens problem, each column can contain ______.

exactly one queen

A(n) ______ is a mechanism for error handling.

exception

Which of the following is NOT used to find logical errors?

exceptions

The definition of a subclass includes a(n) ______ clause to indicate its superclass. extends super this implements

extends

The keyword ______ is used in the class declaration of a subclass to indicate its superclass.

extends

The base case for a recursive definition of the factorial of n is ______. factorial (-1) factorial (0) factorial (1) factorial (n - 1)

factorial (0)

A base class is a class that inherits the members of another class.

false

A binary search starts at the beginning of the collection of items.

false

A default Java constructor has a single parameter.

false

A default constructor requires at least one parameter in order to compile correctly.

false

A local reference variable has a default value of null.

false

A method that is declared as static is an object method.

false

A module indicates that an error has occurred by catching an exception.

false

A package cannot contain other packages

false

A programmer can decrease the time needed to develop a program by starting to write the code of the program before creating a solution design.

false

A string of length 1 is not a palindrome.

false

A subclass cannot add new members to those it inherits from the superclass.

false

A superclass's private data fields can be revised by one of its subclasses.

false

According to the following statement: JavaPrograms = {strings w : w is a syntactically correct Java program} all strings are Java programs.

false

According to the principle of information hiding, a module should be completely isolated from other modules.

false

All Java classes must contain a method called main.

false

All constructors in Java have a return type of void.

false

An abstract data type is another name for a data structure.

false

An instance of a superclass can be used anywhere an instance of its subclass is expected.

false

An iterative method always calls itself.

false

By default, all members in a class are public.

false

Clients of a class can directly access the protected members of that class.

false

Comments beginning with the characters // can extend for multiple lines until the compiler encounters \\.

false

Each node in a linear linked list references both its predecessor and its successor.

false

If a string is added to a stack, characters removed from the stack will occur in the order in which they appear in the original string.

false

If an int is added to a float, the result will be an int.

false

If two programs perform the same task, then the faster program is always better.

false

In Java, the programmer must explicitly deallocate memory.

false

In a circular doubly linked list, inserting into the first position of the list is a special case.

false

In a time-driven simulation, no action is required between events.

false

In an event-driven simulation of a bank, the arrival of a customer is an internal event.

false

Infix expressions do not need precedence rules.

false

Integer literals beginning with the digit 0 are interpreted to be in decimal notation.

false

Logical errors of a program are removed during the coding phase of the software life cycle.

false

New items enter a queue at its front.

false

Operations of the ADT stack can be viewed as general versions of the list and queue operations.

false

Rightward drift is a problem that is encountered in a reference-based implementation of a queue.

false

Syntax errors are corrected during the maintenance phase of the software life cycle.

false

The binary search algorithm can be applied to an unsorted array.

false

The expression: (a + b) / c is a fully parenthesized expression.

false

The following string is a valid prefix expression: + * a b c d

false

The head of a list does not have a successor.

false

The specifications of a module indicate how that module should be implemented.

false

If the field modifier ______ is specified in a method definition, the method cannot be overridden by a subclass.

final

Methods declared as ______ use static binding.

final

Which of the following is a base case for a recursive binary search algorithm? (first is the index of the first item in the array, last is the index of the last item in the array, and mid is the midpoint of the array). last > first first > last 0 <= first last <= SIZE-1

first > last

Write the code fragment to remove the front item of a queue that contains more than one items and which is represented by a circular linked list. ;

firstNode = lastNode.getNext(); lastNode.setNext(firstNode.getNext())

Complete the following code so that it sets found to true if the array a consisting of integers contains the value zero. int index = 0; boolean found = false;

for (index = 0; index < a.length; index++) if (a[index] == 0) found = true;

Which of the following loop headers will arrange for the loop body to execute exactly 10 times?

for (int i = -5; i < 5; ++i)

The following code attempts to find the sum of the elements in the third column (from the left) of a two dimensional int array called a that has 10 rows and 20 columns. Correct the errors in the code. int sum = 0; for (int i = 0; i < 20; i++) sum = sum + a[3][i];

for (int i = 0; i < 10; i++) sum = sum + a[i][2];

Write a for-loop that will print all the positive integers from 100 down to 1, inclusive, one number per line.

for (int i = 100; i >= 1; i--) System.out.println(i);

Which of the following code fragments is used to delete the item at the front of a queue represented by a circular array? front = MAX_QUEUE - front;

front = (front+1) % MAX_QUEUE; --count;

A recursive binary search algorithm always reduces the problem size by ______ at each recursive call. 1 2 half one-third

half

An empty string ______.

has a length of 0

The last node of a linear linked list ______. has the value null has a next reference whose value is null has a next reference which references the first node of the list cannot store any data

has a next reference which references the first node

Containment is another name for a(n) ______ relationship.

has-a

A reference variable whose sole purpose is to locate the first node in a linked list is called ______. top front head first

head

Which of the following statements deletes the first node of a linear linked list that has 10 nodes? head.setNext(curr.getNext()); prev.setNext(curr.getNext()); head = head.getNext(); head = null;

head = head.getNext();

A ______ can be used to store global information about a linked list. head record tail reference precede reference dummy head node

head record

Suppose a String variable s is initialized to the value "inheritance". What value is returned by the call s.substring(2, 5) ? nher nheri her heri

her

Suppose a, b and c are the lengths of the 3 sides of a triangle. Write an if-statement that will determine if the triangle is isosceles (at least 2 of the 3 sides are equal). You may assume that a, b and c are of type int.

if (a == b || a == c || b == c) System.out.println("isosceles triangle");

A leap year occurs when the year number (e.g. 1984) is divisible by 4. But there is a special case for years ending in 00: these must be divisible by 400 to be considered a leap year. Thus, 1900 was not a leap year, but 2000 was. Write an if-statement that determines if the integer variable year represents a leap year. (Hint: use the % operator for taking remainders.)

if (year % 100 == 0 && year % 400 == 0 || year % 100 != 0 && year % 4 == 0) System.out.println("It's a leap year.");

According to the following statement: JavaPrograms = {strings w : w is a syntactically correct Java program} when is a given string a member of the language JavaPrograms?

if it is a syntactically correct Java program.

Data structures are part of an ADT's ______. definition implementation specifications usage

implementation

______ describes the ability of a class to derive properties from a previously defined class.

inhertiance

What is wrong with this Java statement? int num = new int(5);

int is a primitive type in Java, not a class. We can immediately assign it the value of 5; there is no constructor to call, and no need to dynamically allocate memory.

A Java ______ specifies behaviors that are common to a group of classes.

interface

A(n) ______ allows two modules to communicate with each other. data structure axiom interface client

interface

The communication mechanisms among modules are called ______.

interfaces

The insertion operation of the ADT list can insert new items ______. only at the front of the list only at the end of the list only in the middle of the list into any position of the list

into any position of the list

A(n) ______ is a condition that is always true at a particular point in an algorithm.

invariant

What is an abstract class?

is a class without instances that forms the basis of other classes that descend from it.

What is containment?

is a relationship between classes whereby one class contains an instance of another class.

A dummy head node ______. facilitates adding nodes at the end the linked list is used to store the first item in the linked list is the second node in the linked list is always present, even when the linked list is empty

is always present, even when the linked list is empty

What is method overloading?

is when a method is created that has the same name as another method, but a different set of parameters.

Inheritance should only be used when a(n) ______ relationship exists between the superclass and the subclass.

is-a

Give three examples of ADT operations that ask questions about the data in a collection.

isEmpty( ), size( ), get( )

Which of the following is true about an abstract class? it can be instantiated it can contain zero or more abstract methods it cannot be inherited by other classes it cannot contain data fields

it can contain zero or more abstract methods

A(n) ______ is a class that is used to provide access to another class that contains many objects.

iterator

A comment in Java that begins with /** and ends with */ is what kind of comment?

javadoc comment

Dynamic binding is also known as ______.

late binding

The ADT ______ allows you to insert into, delete from, and inspect the item at any position of the ADT.

list

In an implementation of a queue uses the ADT list, which of the following can be used to implement the operation enqueue(newItem)?

list.add(list.size()+1, newItem)

Suppose sa is a sorted array of integer values, and we wish to search for a number target in this array. If sa contains n elements, and we use the binary search strategy, what is the approximate maximum number of comparisons necessary to determine that the value target is or is not in the array? How would your answer change if the array were not sorted?

log2 n. But for an unsorted array, the answer would be n.

Modularity describes a program that is organized into ______.

loosely coupled and highly cohesive modules

User-detected errors are corrected during the ______ phase of the software life cycle.

maintenance

In the following code segment: Integer maxNum; maxNum = new Integer (15); ______ is a reference variable. Integer maxNum new 15

maxNum

An ADT's operations are known as its ______. axioms methods variables interfaces

methods

During the design phase of the software life cycle, the program is divided into ______.

modules

Self-contained units of code are called ______. modules invariants algorithms exceptions

modules

A recursive solution that finds the factorial of n generates ______ recursive calls. n-1 n n+1 n*2

n

The factorial of n is equal to ______. n - 1 n - factorial (n-1) factorial (n-1) n * factorial (n-1)

n * factorial (n-1)

A recursive method that computes the number of groups of k out of n things has the precondition that ______. n is a positive number and k is a nonnegative number n is a nonnegative number and k is a positive number n and k are nonnegative numbers n and k are positive numbers

n and k are nonnegative number

The symbol AnBn is standard notation for the string that consists of ______. an A, followed by an n, followed by a B, followed by an n an equal number of A's and B's, arranged in a random order n consecutive A's, followed by n consecutive B's a pair of an A and a B, followed another pair of an A and a B

n consecutive A's, followed by n consecutive B's

Which of the following is a precondition for a method that accepts a number n and computes the nth Fibonacci number? n is a negative integer n is a positive integer n is greater than 1 n is an even integer

n is a positive integer

A statement invoking a constructor should also use the Java keyword ______.

new

Write the code fragment to insert a new node that the reference variable newNode references before the node referenced by the reference variable curr in a doubly linked list.

newNode.setNext(curr); newNode.setPrecede(curr.getPrecede()); curr.setPrecede(newNode); newNode.getPrecede().setNext(newNode);

Write the code segment which is used to insert a new node, referenced by the reference variable newNode, between the nodes referenced by the reference variables prev and curr in a linear linked list.

newNode.setNext(curr); prev.setNext(newNode);

Which of the following statements is used to insert a new node, referenced by newNode, at the end of a linear linked list? newNode.setNext(curr); prev.setNext(newNode); newNode.setNext(head); head = newNode; prev.setNext(newNode); prev.setNext(curr); newNode.setNext(curr);

newNode.setNext(curr); prev.setNext(newNode);

Write the code segment that is used to insert a new node, referenced by the reference variable newNode, at the beginning of a linear linked list.

newNode.setNext(head); head = newNode;

Write the code fragment to insert a new node, referenced by newNode, into a nonempty queue represented by a circular linked list.

newNode.setNext(lastNode.getNext()); lastNode.setNext(newNode); lastNode = newNode;

Which of the following is the code to insert a new node, referenced by newNode, into an empty queue represented by a circular linked list?

newNode.setNext(newNode); lastNode = newNode;

Name 3 important operations that an iterator object can perform.

next( ) hasNext( ) remove( )

A linked list contains components, called ______, which are linked to one another. nodes arrays vectors references

nodes

Object-oriented design identifies objects by focusing on the ______ in the problem statement.

nouns

A reference variable declared as a data field within a class has the default value ______. 0 -1 null empty

null

In the following code segment: final int SIZE = 20; // line 1 int groupSize; // line 2 groupSize = SIZE; // line 3 groupSize = groupSize * 2; // line 4 what is the value of groupSize in line 2? 0 null 20 40

null

A(n) ______ is an instance of a class. method data field interface object

object

All classes extend which built-in class?

object

An array is a(n) ______. class method object variable

object

An instance of a class is known as a(n) ______.

object

Encapsulation combines an ADT's data with its operations to form a(n) ______. exception method object variable

object

A reference-based implementation of a queue that uses a circular linked list would need at least ______ external references.

one

In the recursive solution to the Eight Queens problem, the problem size decreases by ______ at each recursive step.

one column

In a queue, items can be added ______.

only at the back of the queue

A method that has the same name but a different set of parameters as an existing method is said to ______ the original method.

overload

A method in a subclass is said to ______ an inherited method if it has the same method declarations as the inherited method.

override

If a queue is implemented as the ADT list, which of the following queue operations can be implemented as list.get(1)?

peek

The ______ operation retrieves the item that was added earliest to a

peek

Which of the following operations leaves a queue unchanged?

peek

With ______, objects can determine appropriate operations at execution time.

polymorphism

Which of the following is NOT an ADT queue operation?

pop

The items in the ADT list are referenced by ______. name value position number position name

position number

Which of the following is true about algebraic expressions? parentheses are needed in all algebraic expressions infix expressions do not require precedence rules postfix expressions do not require association rules fully parenthesized expressions are difficult to recognize and evaluate

postfix expressions do not require association rules

A ______ allows the deletion of a node from a linked list without the need to traverse the list to establish a trailing reference. head record dummy head node tail reference precede reference

precede reference

Which of the following statements deletes the node that curr references? prev.setNext(curr); curr.setNext(prev); curr.setNext(curr.getNext()); prev.setNext(curr.getNext());

prev.setNext(curr.getNext());

A class's ______ members can only be used by its own methods.

private

According to the principle of information hiding, the data fields of a class must be declared as ______. public protected private abstract

private

In general, a class's data fields should be declared as ______.

private

The ______ access modifier hides the members of a class from the class's clients but makes them available to a subclass and to another class within the same package.

protected

Which of the following is NOT a part of the maintenance phase of the software life cycle? correcting user-detected errors adding more features to the software proving the correctness of algorithms modifying existing features of the software to better suit the users

proving the correctness of algorithms

A class's ______ members are available to instances of all classes.

public

In a class within a package, the keyword ______ must appear in front of the class keyword to make the class available to clients of the package.

public

Suppose a class Planet had a method findLife( ) that we call as follows in main( ): int value = p.findLife("goat", true, 0.5); How would the findLife( ) method be declared in Planet.java?

public int findLife(String s, boolean b, double d)

Write a recursive method that takes 3 parameters: an integer array a, and two integers first and last. The method will find the largest value in a between indices first and last, inclusive. That is, it will return the largest value in the part of the array a[first..last] . You may assume that first ≤ last.

public static int findMax(int [] a, int first, int last) { if (first == last) return a[first]; int firstValue = a[first]; int maxOfRest = findMax(a, first + 1, last); if (firstValue > maxOfRest) return firstValue; else return maxOfRest; }

Write a recursive method that takes a String parameter and prints out the characters of the string in reverse order.

public static void reverse(String s) { if (s.length() == 0) return; char lastChar = s.charAt(s.length() - 1); System.out.print(lastChar); reverse(s.substring(0, s.length() - 1)); }

The specifications of a module describe its ______.

public view

The enqueue operation of the ADT queue is similar to the ______ operation of the ADT stack.

push

Which of the following is an operation of the ADT stack?

push

The line of customers in a bank can be represented as a(n) ______.

queue

Which of the following ADTs is like a line of people?

queue

A ______ is a mathematical formula that generates the terms in a sequence from previous terms. local environment pivot item base case recurrence relation

recurrence relation

When you declare a variable that refers to an object of a given class, you are creating a(n) ______ to the object. interface reference method ADT

reference

Which of the following is an operation of the ADT list?

remove

Which of the following operations of the ADT list changes the list? remove isEmpty size get

remove

What does the reference super represent?

represents the object reference for the superclass.

An array-based implementation of an ADT list ______. requires less memory to store an item than a reference-based implementation is not a good choice for a small list has a variable size has items which explicitly reference the next items

requires less memory to store an item than a

Suppose s1 is a String variable. We want to check to see if the first and last characters of s1 are the same. Complete the following if-statement to accomplish the task. boolean same; if (______________________________________________) same = true; else same = false;

s1.charAt(0) == s1.charAt(s1.length() - 1)

What feature of Java transforms class objects into a sequence of bytes that may be used by another program?

serialization

To delete a node N from a linear linked list, you will need to ______. set the reference next in the node that precedes N to reference the node that follows N set the reference next in the node that precedes N to reference N set the reference next in the node that follows N to reference the node that precedes N set the reference next in N to reference the node that follows N

set the reference next in the node that precedes N to reference the node that follows N

A prototype program is created during the ______ phase of the software life cycle.

specification

The first phase of the life cycle of software is the ______ phase. design risk analysis specification coding

specification

A method's contract includes the method's ______. code algorithm(s) implementation specifications

specifications

An ADT's ______ govern(s) what its operations are and what they do. specifications implementation documentation data structure

specifications

A class method is defined as ______. static abstract private protected

static

Which access modifier, used when defining a method, indicates that only one such method is available for all instances of the class?

static

A(n) ______ is a class that inherits the members of another class. base class superclass abstract class subclass

subclass

A superclass method can be accessed by a subclass, even though it has been overridden by the subclass, by using the ______ reference.

super

The ______ keyword is used to call the constructor of the superclass. extends super this implements

super

The constructor of a subclass can call the constructor of the superclass by using the ______ reference.

super

A language is a set of strings of ______.

symbols

A _______ can be used to facilitate adding nodes to the end of a linear linked list. head record dummy head node tail reference precede reference

tail reference

If the value being searched for by a recursive binary search algorithm is in the array, which of the following is true? the algorithm cannot return a nonpositive number the algorithm cannot return a nonnegative number the algorithm cannot return a zero the algorithm cannot return a negative number

the algorithm cannot return a negative number

Which of the following is an example of a syntax error? a program encounters an instruction to divide by zero an array subscript in a program goes out of range the beginning of a while loop is written as "whille" instead of "while" an algorithm that calculates the monthly payment of a loan displays incorrect results

the beginning of a while loop is written as "whille" instead of "while"

In an event-driven simulation of a bank, which of the following is an internal event?

the departure from the bank of a customer

In the box trace for a recursive method, a new box is created each time ______. the method is called the method returns a value the object is created the object is initialized

the method is called

In the box trace, each box contains all of the following EXCEPT ______. the values of the references and primitive types of the method's arguments the method's local variables the method's class variables a placeholder for the value returned by each recursive call from the current box the value of the method itself

the method's class variables

In a linear linked list, ______. the next reference of each node has the value null the last node references the first node the precede reference of the dummy head node references the last node the next reference of the last node has the value null

the next reference of the last node has the value null

In the ADT list, when an item is deleted from position i of the list, ______. the position of all items is decreased by 1 the position of each item that was at a position smaller than i is decreased by 1 the position of each item that was at a position greater than i is decreased by 1 the position of each item that was at a position smaller than i is increased by 1 while the position of each item that was at a position greater than i is decreased by 1

the position of each item that was at a position greater than i is decreased by 1

In the ADT list, when an item is inserted into position i of the list, ______. the position of all items is increased by 1 the position of each item that was at a position smaller than i is increased by 1 the position of each item that was at a position greater than i is increased by 1 the position of each item that was at a position smaller than i is decreased by 1 while the position of each item that was at a position greater than i is increased by 1

the position of each item that was at a position greater than i is increased by 1

Which of the following is NOT true about all circular linked lists? every node references a successor the last node references the first node the precede reference of each node references the node that precedes it no node contains null in its next reference

the precede reference of each node references the node that precedes it

The number of ways to choose k out of n things is ______. the number of ways to choose k - 1 out of n - 1 things the number of ways to choose k out of n - 1 things the sum of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things the product of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things

the sum of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things

What is the advantage of using prefix or postfix expressions instead of infix expressions? .

these expressions do not need precedence rules, association rules, or parentheses. Therefore, the grammars for prefix and postfix expressions are quite simple. In addition, the algorithms that recognize and evaluate these expressions are relatively straightforward

Which of the following is true about runtime exceptions? they must be handled locally they must be explicitly thrown from the method they are used in situations where the method has encountered a serious problem they can often be prevented by fail-safe programmin

they can often be prevented by fail-safe programmin

A method indicates that an error has occurred by ______ an exception. throwing catching implementing declaring

throwing

In an event-driven simulation of a bank, which of the following equations can be used to determine the time of a customer's departure?

time of next departure = time service begins + length of transaction

A package and the directory that contains all the classes in the package must have the same name.

true

A queue can be used to preserve the order of occurrences.

true

A recursive solution can have more than one base cases.

true

A recursive solution solves a problem by solving a smaller instance of the same problem.

true

A subclass can contain its own version of an inherited method.

true

Abstraction separates the purpose of a module from its implementation.

true

All Java programs must define at least one class.

true

All the items in a list must be of the same data type.

true

An application can use the operations of an ADT without knowing how the ADT is implemented.

true

An instance of a subclass can access the protected members of the superclass.

true

An iterative solution involves loops.

true

Any instance of a subclass can be used in a program anywhere that an instance of the superclass can be used.

true

Coding is a relatively minor phase in the software life cycle.

true

Data structures are part of an ADT's implementation.

true

During the specification phase of the life cycle of software, the programmer should specify what enhancements to the program are likely in the future.

true

Every node in a circular linked list has a successor.

true

Every recursive method must have a base case.

true

If d is a double and i is an int, then the assignment statement d = i; is legal in Java.

true

If s1 = "dog" and s2 = "cat", then s1.compareTo(s2) returns a positive integer value.

true

If the string w is a palindrome, the first and last characters of w are the same.

true

In Java, when we write an if-statement of the form if(condition), the condition must evaluate to a boolean value.

true

In an event-driven simulation of a bank, the departure times of customers are determined by the simulation.

true

Induction can be used to prove that a recursive algorithm is correct.

true

Inheritance should not be used to implement a has-a relationship.

true

Insertion at the end of a linear linked list is a special case.

true

No node in a circular linked list contains the value null in its next reference.

true

Parentheses are not necessary in prefix expressions.

true

The ADT list can have an arbitrary length.

true

The Java expression (75 - 63) * 10 / 6 - 1 evaluates to 19.

true

The addition of an item to an empty queue is a special case.

true

The base case for a recursive solution to the kth smallest item problem cannot be predicted in advance.

true

The constant null can be used as the value of a reference to any type of object.

true

The cost of software includes the consequences of the software not behaving correctly.

true

The empty string is a palindrome.

true

The first item to be added to a queue is the first item to be removed from the queue.

true

The stricter the definition of a language, the easier it is for a compiler to recognize a syntactically legal expression.

true

When a linked list is empty, the value of the head reference is null.

true

When constructing a recursive solution, you should assume that a recursive call's postcondition is true if its precondition is true.

true

A reference-based implementation of a queue that uses a linear linked list would need at least ______ external references.

two

The ADT sorted list inserts and deletes items by their ______. name value position name position number

value

A top-down design identifies actions by focusing on the ______ in the problem statement.

verbs

During the ______ phase of the software life cycle, formal methods may be used to prove the correctness of an algorithm.

verification

If the string w is a palindrome, which of the following is true? w minus its first character is a palindrome w minus its last character is a palindrome w minus its first and last characters is a palindrome the first half of w is a palindrome the second half of w is a palindrome

w minus its first and last characters is a palindrome

The specifications of an ADT's operations indicate ______. how to implement the operations how to store the data in the ADT how to carry out the operations what the operations do

what the operations do

In a grammar, the symbol x y means ______.

x followed by y

In a grammar, the symbol x | y means ______.

x or y

Which of these expressions is illegal in Java? x++ 5 x =+ 5 x += 5 x == 5

x++5

If s1 is of type String, what does s1.compareTo(s1) return? zero true false Cannot be determined without knowing the value of s1.

zero


Set pelajaran terkait

CCNA Cybersecurity Operations (Version 1.1) - CyberOps Chapter 8 Exam

View Set

Development and community exam study

View Set

Ch. 18: Reports on Audited Financial Statements

View Set

Study.com Financial Accounting Practice Test

View Set

Module 3 Biology EVOLUTION W13 HW

View Set

Chapter 24: Real Property and Environmental Law

View Set

Exam 1 - Pectoralis Major, Pectoralis Minor, Subclavius

View Set

Micro Economics Anirudh Bagchi Test #2 with diagrams

View Set