.121 WK 5-10 Flashcards

1
Q

Why do we need predicate logic?

A

encompasses all of propositional logic + expands on its limitations
so it accounts for parts of propositions, links between parts of propositions + quantifiers

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

What is predicate logic split into?

A

syntax - notation for concepts + operators used to create formulae
semantics - meaning behind formulae

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

Explain concepts

A

terms - similar to subjects, expressed through nouns/pronouns, written as the lower case of the 1st letter
- argument of the predicate so
written as P(a)

predicates - properties/relations among terms, expressed through verbs, written as the upper case of the 1st letter
properties = “is property”
relations = “is the relation of”/”are related”

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

What are the types of operators?

A

connectives + quantifiers

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

What is an atomic formula?

A

consists of 1 predicate and 1<= terms
functions that take 1+ arguments (constants/variables) and returns true or false (Boolean)

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

What is a constant?

A

term desc. specific individual entities

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

What is a variable?

A

represents general terms (individuals of the same type or a class rather than specific individuals), written with lower case letters from end of alphabet

takes values from the universe of discourse - set of all entities that can replace a variable in an atomic formula

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

Atomic formulae can be…

A

closed/ground formulae - predicate’s arguments are only constants and so are propositions with truth values

                                                         OR

open/unground formulae - predicate’s arguments consist of at least 1 variable and so are not propositions as they have no truth value

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

What is arity of atomic formulae?

A

number of variables it takes as arguments
e.g. unary (1), binary (2) + n-ary (2+)

if arity…
== 0 - propostion
== 1 - properties
>= 2 = relationships

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

What are the 2 quantifiers?

A

universal - every/”for all” (equivalent to a conjunction with all the variables) - denoted by upside down A
negation = not all

existential - at least one/”there exists” (equivalent to a disjunction with all the variables) - denoted by a backwards E
negation = none

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

What are the rules of inference?

A

all of propositional plus…
- universal/existential instantiation
- universal/existential generalisation

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

What is universal + existential instantiation?

A

universal - if it is true for a variable it is true for a constant of that variable

existential - if it is true for a constant it is true for a constant of that variable

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

What is universal + existential generalisation?

A

universal - if it is true for any arbitrary x it is true for every x

existential - if it is true for a constant it is true for a constant of that variable

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

What is the difference between restricted + unrestricted quantifiers?

A

unrestricted quantifiers - all elements in the Universe of Discourse - use conjunction
e.g “Every man has 2 legs”
Ax (M(x) -> L(x))

restricted quantifiers - some elements in the Universe of Discourse (a subset) - use implication
e.g “There is a man who has 2 legs”
Ex (M(x) AND L(x))

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

What functions + properties are needed for a queue?

A

head + tail pointers
enqueue(item)
dequeue
isEmpty()
isFull() - if bounded

int data
element next

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

How does enqueue() work?

A

struct element el = new Element;
el.data = data
el.next = null
if (head == null){
head = el
}
else {
tmp = head
while (tmp.next != null){
tmp = tmp.next
}
tmp.next = el
}

17
Q

How does dequeue work?

18
Q

How to create a 2D array?

A

int array[x][y]

19
Q

Pros + Cons of 2D arrays

A

+ random access - very fast

  • fixed size (can only grow by copying elements - costly)
  • insertion + deletion is costly
20
Q

What properties + functions does a stack need?

A

top pointer
isEmpty()
isFull() if bounded
push()
pop()

element prev
int data

21
Q

How does push(stack, x) work?

A

struct Element el = new Element
el.data = x
el.prev = null
if (isEmpty(stack)){
stack.top = el
}
else{
el.prev = stack.top
s.top = el
}

22
Q

How does pop(stack) work?

A

if (isEmpty(stack)){
underflow error
}
else{
tmp = stack.top
stack.top = stack.top.prev
return tmp.data
}

23
Q

iteration vs recursion

A

iteration :
+ memory usage is controlled explicitly by the programmer - stack overflow is less likely
+ can execute more quickly - no overhead from stack frame creation/destruction
- naturally recursive functions can be harder to understand in iterative form

recursion :
+ naturally recursive functions are much more concise when recursively expressed
+ languages which support tail recursion can eliminate some of the extra costs to performance + stack overflow