Ch.3 Flashcards

1
Q

… manage the GameEntry instances
that represent the high scores. The array is allocated with the specified maximum capacity, but all entries are initially n..l. As entries are added, we will
maintain them from highest to lowest score, starting at index 0 of…

A

[null] 105

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In this section, we use a similar technique to solve the [so..g] problem, that is, starting with an unordered array of elements and rearranging them
into nondecreasing order…As a warm-up, in this section we describe a simple sorting algorithm
known as [in..n-s..t]. The algorithm proceeds by considering one element at a time, placing the element in the correct order…

A

[sorting][insertion sort] 110

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In particular, Java
has a built-in class, java.util.Random, whose instances are [ps..m n..r
g..s], that is, objects that compute a sequence of numbers that are statistically
random. These sequences are not actually random, however, in that it is possible
to predict the next number in the sequence given the past list of numbers…

Since the next number in a pseudorandom generator is determined by the previous
number(s), such a generator always needs a place to start, which is called its [s..d]. The sequence of numbers generated for a given seed will always be the same. The seed for an instance of the Java.util.Random class,…

A

[pseudorandom number generators][seed] 113

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An important application of character arrays and strings is [cr..y], which is the science of secret messages. This field involves the process of [e..on],
in which a message, called the [p..xt], is converted into a scrambled message,
called the [c..xt]. Likewise, cryptography studies corresponding ways of performing
[d..on], turning a ciphertext back into its original plaintext.
Arguably the earliest encryption scheme is the [C..r c..er], which is named
after Julius Caesar, who used this scheme to protect important military messages.
(All of Caesar’s messages were written in Latin, of course, which already makes
them unreadable for most of us!) The Caesar cipher is a simple way…

A

[cryptography][encryption][plaintext][cryptotext][decryption][Caesar cipher] 115

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

We continue this approach all the way up to W, which is replaced with Z. Then, we let the substitution pattern [w..ap a..d], so that we replace X with A, Y with B, …

A

[wrap around] 115

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The process of [d..g] the message can be implemented by simply using a different character array to represent the replacement rule—one that effectively
shifts characters in the opposite direction.
In Code Fragment 3.8, we present a Java class that performs the Caesar cipher
with an arbitrary rotational shift. The constructor for the class builds the encoder and…
with the letter having index (k+r)mod 26, where the [m..o] operator,
which returns the remainder after performing an integer division. This operator is
denoted with % in Java, and it is exactly the operator we need to easily perform
the wraparound at the end of the alphabet, for 26 mod 26 0, 27 mod 26 is 1, and 28 mod 26 is 2. The decoder array for the Caesar cipher…

A

[decrypting][modulo] 116

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Many computer games, be they strategy games, simulation games, or first-person
conflict games, involve objects that reside in a two-dimensional space. Software for
such [p..l g..s] needs a way of representing objects in a two-dimensional space. A natural way to do this is with a [t..o-d..l a..y], where we use two
indices, say i and j, to refer to the cells in the array. The first index usually refers
to a row number and the second to a column number. Given such an array, we can
maintain two-dimensional game boards…
Nevertheless, there is a way we can define two-dimensional arrays in
Java—we can create a two-dimensional array as an array of arrays. That is, we can
define a two-dimensional array to be an array with each of its cells being another
array. Such a two-dimensional array is sometimes also called a [m..x]. In Java, we
may declare a two-dimensional array as follows:
int[ ][ ] data = new int[8][10];…

A

[positional games][two-dimensional array][matrix] 118

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

As most school children know, [T..c-T..c-T..e] is a game played in a three-by-three
board. Two players—X and O—alternate in placing their respective marks in the
cells of this board, starting with player X. If either player succeeds in getting three
of his or her marks in a row, column, or diagonal, then that player wins. This is admittedly not a sophisticated positional game, and it’s not even that
much fun to play, since a good player O can always force a tie. Tic-Tac-Toe’s saving
grace is that it is a nice, simple example showing how two-dimensional…

A

[Tic-Tac-Toe] 119

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

…first to last. However, there are many applications in which data can be more naturally viewed as having a [c..c o..r], with well-defined neighboring
relationships, but no fixed beginning or end.
For example, many multiplayer games are turn-based…
In order to support the responsiveness of an arbitrary number of concurrent processes, most operating
systems allow processes to effectively share use of the CPUs, using some form of an algorithm known as [r..d-r..n s..g]. A process is given a short turn
to execute, known as a [t..e s..e], but it is interrupted when the slice ends, even if its job is not yet complete. Each active process is given its own time slice, taking
turns in a cyclic order. New processes can be added to the system…

A

[cyclic order][round robin scheduling][time slice] 128

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In this section, we design a structure known as a [c..y l..d l..t], which is essentially a singularly linked list in which the next reference of the tail node is set to refer back to the head of the list (rather than [n..l]), as shown in Figure 3.16.

A

[circularly linked list][null] 129

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The universal Object superclass defines
a method named [c..e], which can be used to produce what is known as a [s..w c..y] an object. This uses the standard assignment semantics to assign
the value of each field of the new object equal to the corresponding field of
the existing object that is being copied. The reason…

A

[clone][shallow copy] 141

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A shallow copy is not always appropriate for all classes, and therefore, Java
intentionally disables use of the clone( ) method by declaring it as [p..d], and by having it throw a CloneNotSupportedException when called. The author of
a class must explicitly declare...
A

[protected] 141

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

There are more considerations when copying an array that stores reference types rather than primitive types. The clone( ) method produces a [s..w c..y]
of the array, producing a new array whose cells refer to the same objects referenced by the first array…

A [d..p c..y] of the contact list can be created by iteratively cloning the individual
elements, as follows, but only if the Person class is declared as Cloneable.
Person[ ] guests = new Person[contacts.length];
for (int k=0; k < contacts.length; k++)
guests[k] = (Person) contacts[k].clone( ); // returns Object type...
A

[shallow copy][deep copy] 142

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

[p..c c..s] SinglyLinkedList [i..s] Cloneable {
The remaining task is implementing a public version of the clone() method of the class, which we present in Code Fragment 3.21. By convention, that method
should begin by creating a new instance using a call to [s..r].clone( ), which in our
case invokes the method from the Object class (line 3). Because the inherited version
returns an Object, we perform a narrowing cast to type SinglyLinkedList.
At this point in the execution, the other list has been created as a shallow copy
of the original. Since our list class has two fields, size and head, the following
assignments have been made:
other.size = [t..s].size;
other.head = [t..s].head;
While the assignment of the size variable is correct, we cannot allow the new list to
share the same head value (unless it is [n..l]). For a nonempty list to have an independent
state, it must have an entirely new chain…

A

[public class][implements][super][this][this][null] 144

How well did you know this?
1
Not at all
2
3
4
5
Perfectly