Send a link to your students to track their progress
170 Terms
1
New cards
abstract class
"partial" or "incomplete" class that contains bodies for some but (typically) not all of the methods of the interfaces it claims to implement
2
New cards
factoring out common code
method bodies that can be written once, and work for any implementation of NaturalNumberKernel because they are programmed to that interface—have been factored out into an abstract class
3
New cards
Can you instantiate an abstract class?
No. You can't use an abstract class like a normal class and create objects from it.
4
New cards
UUT
unit under testing
5
New cards
How to achieve single-point control over change
"Re-route" all UUT constructor calls to another method, which then calls the UUT constructor, so only the body of that one method needs to be changed to accommodate a different UUT
6
New cards
Class ending with "L"
Kernel class that directly represents the new type using a component from Java libraries
7
New cards
Instance variable
there is a distinct variable (with the same name) for each instance of the class in which it is declared
8
New cards
Criteria for kernel implementation
1. easy to understand and write 2. more efficient
9
New cards
Sequence3 on Stack
Sequence represented as two Stacks, left and right Sequence = rev(left) + right Representation of Sequence is "two Stacks facing each other" in the middle of sequence
10
New cards
Client view
Mathematical models, method contracts Kernel interface SHOWS what the software does
11
New cards
Implementer view
Data representation, algorithms Kernel class shows HOW the software does it
12
New cards
Abstract state space
the set of all possible math model values as seen by the client
13
New cards
concrete state space
the set of all possible math model values of the data representation
14
New cards
abstraction function
How to interpret any concrete value (that satisfies the representation invariant) as an abstract value? @correspondence
15
New cards
representation invariant
what configurations of the instance variable can arise? @convention
16
New cards
Why hashing?
1. can be quickly identified 2. must contain the item
17
New cards
T/F: nodes in a linked list must always have consecutive memory addresses
false
18
New cards
T/F: nodes in a linked list can be accessed in constant time
false
19
New cards
T/F: nodes in a linked list require at least one smart node
false
20
New cards
T/F: nodes in a linked list can be accessed sequentially in linear time
true
21
New cards
T/F: the process of building a heap will completely sort its elements
false
22
New cards
T/F: a subroutine is needed to adjust the root of a subtree to its proper position, assuming the subtree is a heap except for its root
true
23
New cards
T/F: heaps are parameterized by a type and an ordering process
true
24
New cards
T/F: a heap is a binary tree with extra constraints on its shape and organization
true
25
New cards
collection type
any type whose abstract mathematical model involves: string, set, multiset, tree, binary tree
- direct access - constant time access (regardless of length)
28
New cards
array cons
- fixed size; can run out of room - fixed size; instantiation might be expensive if entries go unused - adding/removing other entries in the middle requires moving entries around, which is slow
29
New cards
What's an array represented by?
A contiguous block of memory locations with consecutive memory addresses so the memory address of the entry at index i can be directly calculated from the memory address of the first entry, by using simple arithmetic
30
New cards
JVM
Java Virtual Machine
31
New cards
binary tree
- can be empty - can be non-empty consisting of root node and two subtrees - mathematical type: binary trees with any label of type T
32
New cards
pre-order
root, left, right
33
New cards
in-order
left, root, right
34
New cards
post-order
left, right, root
35
New cards
Binary Search Tree (BST)
a binary tree where the left node < root, and the right node > root
36
New cards
SortingMachine
- Allows adding elements of type T to a collection of such elements, and then removing them one at a time in sorted order - Mathematical model: 3-tuple {insertion_mode: boolean, ordering: binary relation on T, contents: finite multiset of T}
37
New cards
Why is SortingMachine better than sort?
-If all elements are already sorted by the end of "changeToExtractionMode", then there is no difference in performance -If elements are not already sorted by the end of "changeToExtractionMode", then the performance advantage is that you don't need to remove all the elements
38
New cards
T/F: smart nodes can prevent runtime errors arising from the code managing of a linked list
false
39
New cards
T/F: smart nodes can provide significantly faster performance when manipulating the elements of a linked list
false
40
New cards
T/F: smart nodes can make the initial setup of the linked list faster
false
41
New cards
T/F: smart nodes can aid with removal of special cases from some methods that work with a linked list
true
42
New cards
what is the data structure of a doubly-linked list?
two references per node: one to the "next" node and one to the "previous" node
43
New cards
TF
type family interface whose kernel is being implemented
44
New cards
What does the standard method this.newInstance() do?
returns a new object with the same DYNAMIC type as this, having an initial value (usually 0 or empty)
45
New cards
Server (BugsWorld)
each display shows the current state of the world, plus some statistics about the simulation
46
New cards
Client (BugsWorld)
each client program simulates creature (bug) behavior for all creatures of one species
47
New cards
Displays (BugsWorld)
each display shows the current state of the world, plus some statistics about the simulation
48
New cards
3 Compiler Parts
Tokenizer -> Parser -> Code Generator
49
New cards
Abstract Syntax Tree (AST)
- tree model of an entire program or certain "program structure" (ex: a statement or expression) - "abstract" because the characters used in the concrete program do not appear in this representation - mathematical model: 3-tuple {KIND of statement, TEST of condition, CALL of instruction} NOTE: either test or call is relevant information, depending on what kind of statement it is
50
New cards
Statement
- component family which allows for manipulation of ASTs for BL statements
51
New cards
block (for Statement)
child can be anything except block
52
New cards
if (for Statement)
child must be block
53
New cards
while (for Statement)
child must be block
54
New cards
If_Else (for Statement)
two children, both must be blocks
55
New cards
call (for Statement)
zero children
56
New cards
T/F: you can use == to check equality of enums
true
57
New cards
Enumerations (or enums)
special construct, allows for meaningful symbolic names (the kinds in Statement, for example)
58
New cards
Statement no-arg constructor
this = compose((BLOCK, ?, ?), <>)
59
New cards
Program
- component family that allows for the manipulation of values representing entire BL programs
this = ("Unnamed", {}, compose((BLOCK, ?, ?), <>))
63
New cards
refactoring
restructuring code without changing its behavior for the purpose of improving readability, making small syntax changes, etc.
64
New cards
Context-Free Grammar (CFG)
- a set of formation rules for strings in a language that satisfies certain technical conditions - used to implement a recursive-descent parser
65
New cards
Recursive-Descent Parser
an algorithm to parse a BL program and construct the corresponding Program object
66
New cards
Terminal symbols
terminates at the point, stop writing when you hit that symbol, typically bolded in the CFG
67
New cards
Non-terminal symbols
only appears on left side of a production, typically italicized
68
New cards
Metagrammar
used to define the CFG itself, not part of the alphabet
69
New cards
Derivation
- a series of specific rewrite-rule applications that begin with the start symbol and continue until only terminal symbols remain - can be depicted in a derivation tree
70
New cards
ambiguity
when some strings in the language of the CFG have more than one derivation tree, which makes it harder to evaluate the correct outcome
71
New cards
Token
a single entity in a language
72
New cards
T/F: purpose of a tokenizer is to transform source code into machine/object code the computer can more easily understand or interpret
false
73
New cards
T/F: purpose of a tokenizer is to remove whitespace and separate the source code into small, meaningful units
true
74
New cards
T/F: purpose of a tokenizer is to construct an abstract representation of a program that holds information about its intended meaning
false
75
New cards
BL Tokenizer
treats string of consecutive whitespace characters as separators between tokens, since the tokens are the words
76
New cards
main uses of CFGs
- generate strings in a language - detect if a given string is in the language
77
New cards
parsing
going from a string to its derivation tree/AST
78
New cards
5 rules of a Recursive-Descent Parser
1. One parse/method/non-terminal symbol 2. Non-terminal symbol on RHS of rewrite rule --> Call parse method for that non-terminal symbol 3. Terminal symbol on RHS of rewrite rule --> Consume token from input token string 4. "|" (vertical bar) in CFG --> "If-else" in parser 5. "{ }" in CFG --> "While" in parser
79
New cards
CFG Symbols { }
- indicates that the enclosed sequence of symbols can occur 0+ times - Helps turn a left-recursive CFG into an equivalent CFG that can be parsed by recursive-descent
80
New cards
parsing an arithmetic expression
the parser evaluates it by turning the string of tokens (in the language of the CFG) to the value of that expression as an int
81
New cards
facts recognized by modern software
- modern software consists of potentially large number of components that are composed into larger components / systems - a class is a component with its client-visible specifications in the interface it implements
82
New cards
how many interfaces can an interface extend?
one or more
83
New cards
T/F: interfaces can be generic
true
84
New cards
what contains a description of WHAT the software does?
interface
85
New cards
what contains a description of HOW the software does it?
class
86
New cards
all instance methods in an interface are automatically...
public abstract
87
New cards
T/F: it is useful for an interface to define variables
false
88
New cards
T/F: constructors are instance methods
false; constructors can't be defined in an interface, which is where instance methods are defined
89
New cards
Kernel interface defines...
1. mathematical model 2. contract(s) for constructors 3. contract(s) for kernel methods 4. contract(s) for methods from Java library 5. interfaces without their own contract specifications (ex. iterator, comparator)
90
New cards
Enhanced interface defines...
contract(s) for all other methods for the type
91
New cards
Kernel methods should be a ____ of ____ that is ____.
a) minimal set b) methods c) functionally complete
92
New cards
a functionally complete set of kernel methods is powerful enough to...
1. give variable of the type ANY allowable value 2. determine the value of a variable of the type 3. implement "equals" and "toString" 4. check every Kernel method's precondition (GDI-chick)
93
New cards
circularity
Interface A extends something of general type interface B in initialization, and interface B extends interface A
94
New cards
A Java interface defines a ___ ____ along with its set of ____ ____
a) type name b) instance methods
95
New cards
T/F: an interface type may be used in Java even if there is no implementation of it in scope
true
96
New cards
interfaces are ____-____ construct
compile-time
97
New cards
Declared (Static) Type
interface type (left side)
98
New cards
Object (Dynamic) Type
Class type (right side)
99
New cards
T/F: the declared type of a variable may be an interface type
true
100
New cards
What happens if the declared type is an interface type?
the object type (a class) MUST implement the declared type (an interface)