450 exam 3 Flashcards

1
Q

unary operator

A

has one operand; e.g., ++, –

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

binary operator

A

has two operands; e.g., +, -, *, /

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

ternary operator

A

has three operands; e.g., ? : conditional expression syntax (ex: average = (count == 0) ? 0 : sum / count;)

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

operator precedence rules for expression evaluation define

A

the order in which “adjacent” operators of different precedence levels are evaluated

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

typical precedence levels (highest to lowest precedence)

A
parentheses
unary operators
** (if the language supports it)
*, /
\+, -
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

operator associativity rules for expression evaluation define

A

the order in which adjacent operators with the same precedence level are evaluated

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

associativity for operators is typically ? except for ?

A

left to right; ** is right to left

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

what does 2 ** 3 ** 4 evaluate to using typical associativity rules?

A

2 ** 81

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

associativity for assignment is ?

A

right to left

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

what are the values of a=1, b=2, c=3 after executing a = b += c ?

A

a=5, b=5, c=3

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

functional side effects

A

occur when a function changes either one of its parameters or a global variable (declared outside the function but is accessible in the function)

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

functions in mathematics (do/do not) have side effects - why?

A

do not b/c there is no notion of variables in mathematics

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

functional programming languages have no variables, so do they have functional side effects?

A

no

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

a program has referential transparency if

A

any two expressions in the program that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program

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

advantage of referential transparency

A

semantics easier to understand

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

programs in pure functional languages (are/are not) referentially transparent - why?

A

are; b/c they do not have variables (so, if a function uses an outside value, it must be a constant)

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

narrowing conversion

A

converts a value to a type that cannot include all of the value of the original type (ex: float to int)

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

widening conversion

A

a value is converted to a type that can include all of the value of the original type (ex: int to float)

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

coercion

A

implicit type conversion

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

casting

A

explicit type conversion

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

relational expressions

A

use relational operators/operands of various types; evaluate to true or false; operators !=, >=, <=, etc.

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

boolean expressions

A

operands are boolean and the result is boolean; operators &&, ||, !

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

short-circuit evaluation

A

the result is determined without evaluating all of the operands and/or operators

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

when would the following be an example of short-circuit evaluation?
(13 * a) * (b / 13 - 1)

A

if a=0, there is no need to evaluate (b / 13 -1) because the result will be 0

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

assignment statements general syntax

A

[target_var] [assign_operator] [expression]

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

compound assignment operator

A

a shorthand method of specifying a commonly needed form of assignment (e.g., +=)

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

unary assignment operators

A

in C-based languages; combine increment and decrement operations with assignment (e.g., sum = count++;)

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

multiple assignments

A

allowed by Perl, Python, and Ruby; e.g., ($first, $second, $third) = (20, 30, 40);

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

example of multiple assignment in Python

A

interchange: (a, b) = (b, a)

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

mixed-mode assignment in Fortran, C, Perl, and C++

A

any numeric type value can be assigned to any numeric type variable

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

mixed-mode assignment in Java and C#

A

only widening assignment coercions are done (e.g., int x = 3.5;) is valid in C++ but not in Java

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

control structure

A

a control statement and the statements whose execution it controls

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

selection statement

A

provides the means of choosing between two or more paths of execution

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

two general categories of selection statements

A

two-way selectors & multiple-way selectors

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

general form of two-way selection statements

A

if control_expression then
clause
else
clause

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

if the then reserved word (or some other syntactic marker) is not used to introduce the then clause, the control expression is placed in

A

parentheses

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

in what languages can the control expression be arithmetic? what is the type of a control expression in most other languages?

A

C/C++ and Python; Boolean

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

Python uses ? to define clauses and nest selectors

A

indentation

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

Java’s static semantics rule: else matches with which if? to force it to match with something else, use ?

A

the nearest previous if; braces

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

Ruby uses the keyword ? for nesting selectors

A

end

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

in ML, F#, and Lisp, the selector is

A

an expression

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

multiple-way selection statements

A

allow the selection of any number of statements or statement groups

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

C/C++, Java, and JavaScript use ? for multiple-way selection

A

switch statements

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

Ruby uses ? for multiple-way selection

A

case expression

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

Python uses ? for multiple-way selection

A

else-if clauses

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

iterative statement

A

one that causes a statement or collection of statements to be executed zero, one, or more times

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

iteration/recursion

A

the repeated execution of a statement or compound statement

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

an iterative statement is often called a

A

loop

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

counter-controlled loops: a counting iterative statement has

A

a loop variable, and a means of specifying the initial and terminal, and stepsize values

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

counter-controlled loops example

A

for loop

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

if the (first/second/third) expression is absent in a for loop, it is an infinite loop

A

second

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

counter-controlled loop syntax in C-based languages

A

for([expr1]; [expr2]; [expr3]) {
statement(s)
}

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

counter-controlled loop syntax in Python

A

for loop_variable in object:

loop body

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

the object in a Python counter-controlled loop is often a

A

range, which is either a list of values in brackets or a call to the range function

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

logically-controlled loops are also called

A

event-controlled (or condition-controlled) loops

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

repetition control in logically-controlled loops is based on

A

a Boolean expression

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

logically-controlled loops in C-based languages

A

while or do-while loops

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

C and C++ allow the control expression to be

A

arithmetic

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

Java is like C and C++ in regards to logically-controlled loops, except

A

the control expression must be Boolean and Java has no goto

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

unconditional branch statement

A

transfers execution control to a specified place in the program (e.g., goto statement)

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

major concerns of unconditional branching

A

readability and reliability

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

what represented one of the most heated debates in the 1960’s and 1970’s?

A

unconditional branching (e.g., goto statements)

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

do all languages support goto?

A

no; for instance, Java

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

guarded command language (GCL)

A

language defined by Dijkstra in 1975

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

purpose of guarded command language

A

to support a new programming methodology that supported verification (correctness) during program development

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

basic idea of guarded command language

A

if the order of evaluation is not important, the program should not specify one

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

guarded command

A

each line in the selection statement, consisting of a Boolean expression (a guard) and a statement or statement sequence

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

semantics of guarded command: when construct is reached,

A

evaluate all Boolean expressions
if more than one is true, choose one non-deterministically
if none of the conditions are true, error

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

subprogram definition

A

describes the interface to and the actions of the subprogram abstraction

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

subprogram call (or invocation)

A

an explicit request that the subprogram be executed

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

subprogram header

A

the first part of the definition, including the name, the kind of subprogram, and the formal parameters

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

subprogram profile/signature

A

the name of the subprogram and the parameter list (number, order, and types of its parameters)

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

subprogram protocol

A

a subprogram’s profile and its return type

74
Q

formal parameter

A

a dummy variable listed in the subprogram

header and used in the subprogram

75
Q

actual parameter

A

represents a value used in the subprogram call statement (aka argument)

76
Q

the parameters in the method declaration max(int num1, int num2) are (actual/formal)

A

formal

77
Q

the parameters in the method call max(x, y) are (actual/formal)

A

actual

78
Q

actual/formal parameter correspondence: positional

A

the binding of actual parameters to formal parameters is by position: the first actual parameter is bound to the first formal parameter etc.

safe and effective

79
Q

actual/formal parameter correspondence: keyword

A

the name of the formal parameter to which an actual parameter is to be bound is
specified with the actual parameter

parameters can appear in any order, but user must know formal parameter names

80
Q

keyword correspondence is supported by

A

Python, Ruby, R, Visual Basic, etc.

81
Q

example of calling a method with keyword correspondence for the following method definition:

def show_interest(principle, rate, periods):

A

show_interest(rate=0.01, periods=10, principle=10000.0)

82
Q

in certain languages (e.g., Python, C++, Ruby, PHP), formal parameters can have ? if no actual parameter is passed

A

default values

83
Q

example of a method using default values

A

void greet(string name, string msg=”Good morning!”)

if no msg is passed, the “Good morning!” value is used

84
Q

languages that support variable number of parameters

A

Java, C/C++, C#, Python, Ruby, etc.

85
Q

example of a method header using variable number of parameters

A

public static void print(int… numbers)

vararg parameters are treated as arrays

86
Q

two categories of subprograms

A

procedures & functions

87
Q

procedures

A

collections of statements that define computations; do not return values

88
Q

functions

A

semantically modeled on mathematical functions; return values

89
Q

functions are expected to ?

A

produce no side effects (but in practice, they do)

90
Q

models of parameter passing: in mode

A

passes info from caller to callee

caller –> callee

91
Q

models of parameter passing: out mode

A

callee writes values in caller

caller

92
Q

models of parameter passing: inout mode

A

caller tells callee value of variable, which may be updated by callee

caller callee

93
Q

pass-by-value is (in/out/inout) mode

A

in

94
Q

pass-by-value

A

changes made to the formal parameter do not get transmitted back to the caller; any modifications to the parameter variable inside the called function will not be reflected

95
Q

pass-by-reference is (in/out/inout) mode

A

inout

96
Q

pass-by-reference (aka pass-by-sharing)

A

changes made to formal parameter get transmitted back to the caller through parameter passing; any changes to the formal parameter are reflected in the parameter in the calling environment b/c the formal parameter receives a reference to the actual data.

97
Q

pass-by-result is (in/out/inout) mode

A

out

98
Q

pass-by-result

A

no value is transmitted to the subprogram; the corresponding formal parameter acts as a local variable and its value is transmitted to the caller’s actual parameter

99
Q

pass-by-value-result is (in/out/inout) mode

A

inout

100
Q

pass-by-value-result

A

a combination of pass-by- value and pass-by-result

101
Q

pass-by-name is (in/out/inout) mode

A

inout

102
Q

pass-by-name

A

symbolic name of a variable is passed, which allows it both to be accessed and updated; used in Algol

103
Q

in some languages (e.g., Python, JavaScript, Haskell), subprograms can be passed as ?

A

parameters

104
Q

three choices of the referencing environment for executing a subprogram passed as a parameter

A

deep binding, shallow binding, ad-hoc binding

105
Q

deep binding

A

the environment of the definition of the passed subprogram; most natural for static-scoping

106
Q

shallow binding

A

the environment of the call statement that enacts the passed subprogram; most natural for dynamic-scoping

107
Q

overloaded subprogram

A

one that has the same name as another subprogram in the same referencing environment

108
Q

every version of an overloaded subprogram has

A

a unique protocol (essentially same name, but return type/parameters may vary)

109
Q

generic (or polymorphic) subprogram

A

takes parameters of different types on different activations

110
Q

generic functions in C++ are named

A

template functions

111
Q

example of a template function (C++ generic function)

A
template 
Type max(Type first, Type second) {
     //method body
}
112
Q

subprogram linkage

A

the subprogram call and return operations of a language

113
Q

activation record

A

the format (or layout) of the non-code part of an executing subprogram

114
Q

activation record instance

A

a concrete example of an activation record (the collection of data for a particular subprogram activation)

115
Q

an activation record includes

A

local variables, parameters, and the return address

116
Q

activation record instances reside on the ? and are dynamically created when ?

A

run-time stack; a subprogram is called

117
Q

dynamic link of a subprogram

A

always points to the caller, which immediately precedes it on the stack; used to reset top-of-stack when a subprogram exits

118
Q

dynamic chain (or call chain)

A

the collection of dynamic links in the stack at a given time

119
Q

typical activation record for a language with stack-dynamic local variables

A

local variables, parameters, dynamic link, return address

120
Q

environment pointer (EP)

A

always points at the base of the activation record instance of the currently executing program unit

121
Q

local offset

A

local variables can be accessed by their local offset from the beginning of the activation record, whose address is in the environment pointer

122
Q

the local_offset of a local variable (can/cannot) be determined easily at compile time

A

can

123
Q

the first local variable in a subprogram would be allocated where?

A

in the AR two position (for return address and dynamic link) plus the number of parameters from the bottom

124
Q

static link in an activation record instance for subprogram A

A

points to the activation record instance of A’s static parent

125
Q

static chain

A

a chain of static links that connects certain activation record instances

126
Q

the static chain from an activation record instance connects it to

A

all of its static ancestors

127
Q

static_depth

A

an integer associated with a static scope whose value is the depth of nesting of that scope

128
Q

chain_offset (or nesting_depth) of a nonlocal reference

A

the difference between the static_depth of the reference and that of the scope where it is declared

129
Q

a reference to a variable can be represented by the pair

A

(chain_offset, local_offset), where local_offset is the offset in the activation record of the variable being referenced

130
Q

the design of the imperative languages is based directly on

A

the von Neumann architecture

131
Q

the design of the functional languages is based on

A

mathematical functions

132
Q

primary concern of imperative languages

A

efficiency

133
Q

lambda expression

A

specifies the parameter(s) and the mapping of a function; describe nameless functions; applied to parameter(s) by placing the parameter(s) after the expression

134
Q

functional form

A

a higher-order function that either takes functions as parameters or yields a function as its result, or both

135
Q

function composition

A

a functional form that takes two functions as parameters and yields a function whose value is the first actual parameter function applied to the application of the second

136
Q

form of function composition

A

h ≡ f * g means h(x) ≡ f(g(x))

137
Q

apply-to-all

A

a functional form that takes a single function as a parameter and yields a list of values obtained by applying the given function to each element of a list of parameters

138
Q

form of apply-to-all

A

α

example for h(x) = x* x
α(h, (2, 3, 4) yields (4, 9, 16)

139
Q

objective of functional programming languages

A

to mimic mathematic functions to the greatest extent possible

140
Q

referential transparency

A

in a functional programming language, the evaluation of a function always produces the same result given the same parameters

141
Q

if in Scheme

A

if predicate then_exp else_exp

ex:
if <= n 1
1 //return one if true
0 //else zero

142
Q

cond in Scheme

A
(cond
     ((zero? (modulo year 400)) #t)
     ((zero? (modulo year 100)) #f)
     (else (zero? (modulo year 4)))    //default case
)
143
Q

list function

A

returns a new list of its parameters

144
Q

car function

A

returns first element of its list parameter

145
Q

cdr function

A

returns the remainder of its list parameter after the first element has been removed

146
Q

cons function

A

puts its first parameter into its second parameter, a list, to make a new list

147
Q

what does (list ‘A ‘B ‘(C D)) return?

A

(A B (C D))

148
Q

what does (car ‘(A B C)) return?

A

A

149
Q

what does (cdr ‘(A B C)) return?

A

(B C)

150
Q

what does (cons ‘A ‘(B C)) return?

A

(A B C)

151
Q

list? function returns #t if

A

parameter is a list

152
Q

null? function returns #t if

A

the parameter is the empty list

153
Q

member takes an atom and a simple list; returns #t if

A

atom is in the list

154
Q

append takes two lists as parameters; returns

A

the first parameter list with the elements of the second parameter list appended at the end

155
Q

a function is tail recursive if

A

its recursive call is the last operation in the function

156
Q

functional programming features in Python

A

lambda expressions, map

157
Q

imperative languages pros/cons

A

complex syntax & semantics, efficient execution

158
Q

functional languages pros/cons

A

simple syntax & semantics, less efficient execution

159
Q

logic programming languages

A

AKA declarative languages; use a logical inferencing process to produce results (only specification of results are stated)

160
Q

compound term

A

one element of a mathematical relation, written like a mathematical function (a mapping)

161
Q

compound term is composed of two parts

A

functor (function symbol that names the relationship) and an ordered list of parameters

e.g., student(jon)
student - functor
jon - parameter

162
Q

clausal form has two parts

A

antecedent (right side - if) and consequent (left side - then)

163
Q

resolution

A

an inference rule that allows inferred propositions to be computed from given propositions

essentially cutting out the middle man

164
Q

unification

A

finding values for variables in propositions that allows matching process to succeed

165
Q

instantiation

A

assigning temporary values to variables to allow unification to succeed

166
Q

backtracking

A

with a goal of multiple subgoals, if it fails to show truth of one of the subgoals, reconsider another subgoal to find an alternative solution; begin search where previous search left off

167
Q

Horn clauses have two forms

A

headed and headless

168
Q

headed Horn clause

A

single atomic proposition on left side

e.g., likes(bob, trout) ⊂ likes(bob, fish) ∩ fish(trout)

169
Q

headless Horn clause

A

empty left side (used to state facts or queries)

e.g., father(bob, jake)

170
Q

fact statements

A

headless Horn clauses

171
Q

rule statements

A

headed Horn clauses

e.g., ancestor(mary, shelley) :- mother(mary, shelley).

172
Q

conjunction

A

multiple terms separated by logical AND operations (use a comma)

173
Q

goal statements (or queries)

A

in form of a proposition that we want the system to prove or disprove; same as a headless Horn

e.g., man(fred).
e.g., father(X, mike).
X is a variable that will yield the result, if one is found

174
Q

process of proving a subgoal is called

A

matching or satisfying

175
Q

forward chaining

A

begin with facts and rules of database and attempt to find a sequence of matches that lead to goal

176
Q

backward chaining

A

begin with goal and attempt to find a sequence of matching propositions that lead to some set of original facts in the database

177
Q

Prolog implementations use (forward/backward) chaining

A

backward

178
Q

when goal has more than one subgoal, can use either

A

depth-first search or breadth-first search

179
Q

depth-first search

A

find a complete proof for the first subgoal before working on others

180
Q

breadth-first search

A

work on all subgoals in parallel

181
Q

Prolog uses (breadth-first/depth-first) search

A

depth-first

182
Q

applications of logic programming

A

relational DB management systems, expert systems, natural language processing