CSE 2231 Final

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/180

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

181 Terms

1
New cards

Abstract class

A "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 in this situation

"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 2 stacks, left and right. Sequence = rev(left) + right

Representation of sequence is 2 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 values of the instance variables 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 definition

Any type whose abstract mathematical model involves: string, set, multiset, tree, binary tree

26
New cards

Collection type examples

Array, queue, set, sequence, stack, map, sorting machine

27
New cards

Array pros

-Direct access

-Constant time access (regardless of length)

28
New cards

Array cons

-Fixed size; can run out of room

-Fixed size; initialization might be expensive if entries go unused

-Adding/removing entires in the middle requires moving other entries, which is slow

29
New cards

Array is 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 tree

-Or can be non-empty tree consisting of root node and 2 subtrees

-Mathematical type: Binary trees with any label of type T

32
New cards

Traversal Orders

1. Pre-order: Root, left, right

2. In-order: Left, root, right

3. Post-order: Left, right, root

33
New cards

Binary Search Tree (BST)

A binary tree where the left node < root, and right node > root

34
New cards

Sorting Machine

-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}

35
New cards

Why is sorting machine 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

36
New cards

T/F: Smart nodes can prevent run-time errors arising from the code managing of a linked list?

False

37
New cards

T/F: Smart nodes can provide significantly faster performance when manipulating the elements of a linked list

False

38
New cards

T/F: Smart nodes can make initial setup of the linked list faster

False

39
New cards

T/F: Smart nodes can aid removal of special cases from some methods that work with a linked list

True

40
New cards

What is the data structure of a doubly-linked list?

2 references per node: one to the "next" node and one to the "previous" node

41
New cards

TF

Type family interface whose kernel is being implemented

42
New cards

What does the standard method newInstance() do?

Returns a new object with the same DYNAMIC type as this, having an initial value (usually 0 or empty)

43
New cards

Server (BugsWorld)

Keeps track of "the world" - Processes client requests, resolves conflicts

44
New cards

Client (BugsWorld)

Each client program simulates creature (bug) behavior for all creatures of one species

45
New cards

Displays (BugsWorld)

Each display shows the current state of the world, plus some statistics about the simulation

46
New cards

3 Compiler Parts

Tokenizer --> Parser --> Code Generator

(TPC)

47
New cards

Abstract Syntax Tree (AST)

-Tree model of an entire program or certain "program structure" (Ex: A statement or expression)

-"Abstract" because 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 the kind of statement it is

48
New cards

Statement

-Component family which allows manipulation of ASTs for BL statements

-Mathematical model: Tree of statement_label

49
New cards

5 Kinds of Statements

1. Block --> Child can be anything except block

2. If --> Child must be block

3. While --> Child must be block

4. If_Else --> 2 children must both be blocks

5. Call --> 0 children

50
New cards

T/F: You can use == to test equality of enums

True

51
New cards

Enumeration (Enum)

Special construct that easily allows use of meaningful symbolic names where you might otherwise be inclined to declare int variables and give them arbitrary values to participate just in equality tests

52
New cards

Statement no-arg constructor

this = compose((BLOCK, ?, ?), <>)

53
New cards

Program

-Component family which allows manipulation of values modeling complete BL programs

-Mathematical model: 3-tuple

{name: IDENTIFIER,

context: CONTEXT,

body: STATEMENT_MODEL}

54
New cards

Program no-arg constructor

this = ("Unnamed", {}, compose((BLOCK, ?, ?), <>))

55
New cards

Refactoring

Restructuring code without changing its behavior for the purpose of improving readability, making small syntax changes, etc.

56
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

57
New cards

Recursive-Descent Parser

An algorithm to parse a BL program and construct the corresponding Program object

58
New cards

Terminal symbols

Terminates at the point, stop writing when you hit that symbol, typically bolded

59
New cards

Non-terminal symbols

Only appears on the left side of a production, typically italicized

60
New cards

Metagrammar

Used to define the context free grammar itself, not a part of the alphabet

61
New cards

Derivation

-A sequence 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

62
New cards

Ambiguity

When some strings in the language of the CFG have more than one derivation tree, which makes it harder to evaluate to the correct outcome

63
New cards

Token

A single entity in the language

64
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 (I think this is the parser's job)

65
New cards

T/F: Purpose of a tokenizer is to remove whitespace and separate the source code into small, meaningful units?

True

66
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

67
New cards

BL Tokenizer

Treats string of consecutive whitespace characters as separators between tokens, since the tokens are the words

68
New cards

2 main uses of CGFs

1. Generate strings in the language

2. Detect if a string is in the language

69
New cards

Parsing

Going from a string to its derivation tree/AST

70
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. "|" in CFG --> "If-else" in parser

5. "{ }" in CFG --> "While" in parser

71
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

72
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

73
New cards

Expression

-Starts with term

-Followed by 0+ add-ops and terms

74
New cards

Term

-Starts with factor

-Followed by 0+ mult-ops and factors

75
New cards

Factor

-Starts with "("

-Followed by expression

-Ends with ")"

-Otherwise, it is a number token

76
New cards

2 facts recognized by modern software

1. Modern software consists of potentially large number of components, that are composed into larger components/systems

2. A class is a component with its client-visible specifications in the interface it implements

77
New cards

How many interfaces can an interface extend?

One or more

78
New cards

T/F: An interface be generic?

True

79
New cards

What contains a description of WHAT the software does?

Interface

80
New cards

What contains a description of HOW the software does it?

Class

81
New cards

What CAN interfaces define?

-Instance methods

-Static final variables

(IS)

82
New cards

What CAN'T interfaces define?

-Constructors

-Instance variables (Not client-view information!!)

-Static methods (Java 8 allows this, but it goes against use of interfaces for client views)

(CIS)

83
New cards

All instance methods in an interface are automatically?

public abstract

84
New cards

T/F: It is usual for an interface to define variables?

False

85
New cards

T/F: Constructors are instance methods?

False; constructors can't be defined in an interface, which is where instance methods are defined

86
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 interfaces without their own contract specifications (Ex: Iterator, comparator)

87
New cards

Enhanced Interface defines...

1. Contract(s) for all other methods for the type

88
New cards

Kernel methods should be a ______________ of ______________ that is ______________.

a) minimal set

b) methods

c) functionally complete

89
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)

90
New cards

Circularity

Interface A extends something of general type interface B in initialization, and interface B extends interface A

91
New cards

A java interface defines a ____ ____ along with its set of ________ _______

a) type name

b) instance methods

92
New cards

T/F: An interface type may be used in Java even if there is no implementation of it in scope

True

93
New cards

Interfaces are _______-____ construct

Compile-time

94
New cards

After a Java program compiles, object types are kept at ___-____ construct

Run-time

95
New cards

Declared (Static) Type

Interface type (left side)

96
New cards

Object (Dynamic) Type

Class type (right side)

97
New cards

T/F: The declared type of a variable may be an interface type

True

98
New cards

T/F: The object type can be an interface type

False; Because you may not instantiate a variable using new followed by an interface type

99
New cards

What happens if the declared type is an interface type?

The object type (a class) MUST implement the declared type (an interface)

100
New cards

What happens to declared types once a Java program compiles?

They disappear in the JVM