lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › fcs1 ›...

38
Foundations of Computer Science 1 — LIACS 1 Lecture 17 revision of topics

Upload: others

Post on 04-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !1

Lecture 17 revision of topics

Page 2: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !2

Sets: definitions, relationships

-set relations: subset, superset, equality, disjointness

-the “element of” relation, ways to specify, predicate, basic properties

-set operations: intersection, union, set difference, symmetric difference

-the universe/universal set & complement

-Venn diagrams, “regions of the diagram” (how many?)

Theorem 1.4. The following claims are equivalent: ! ! !

(1) A ⊆ B(2) A ∩ B = A(3) A ∪ B = B

! ! !

(4) Bc ⊆ Ac

(5) A ∩ Bc = ∅(6) Ac ∪ B = U

Page 3: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !3

Sets: definitions, relationships

-Power set ! , number of elements%(A) or 2A

-Principle of inclusion and exclusion

-Digression: associativity, distributivity and commutativity of operations (know examples and counterexamples!)

Page 4: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !4

Commutativity: A∩ B = B∩ A A∪ B = B ∪ A

Associativity (A∩ B) ∩ C = A∩ (B∩ C) (A∪ B)∪ C = A∪ (B∪ C)

Distributivity: A∩(B∪ C) = (A∩ B)∪(A∩ C) A∪(B∩ C) = (A∪ B)∩(A∪ C)

Idempotence A∩ A = A A∪ A = A

De Morgan (A∪ B)c= Ac∩ Bc (A∩ B)c= Ac ∪ Bc

nul element (identity) A ∩ = A∪ = A

identity element A∩ U= A A∪ U= U

double complement (involution) (Ac)c= A

complementation rules A∩ Ac= A∪ Ac= U

∅ ∅ ∅

Theorem 6.5

Sets: definitions, relationships

algebra of sets & duality

digression: bitstrings and powersets

understand binary representation

Page 5: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !5

Example question & solutions: sets

Venn DIAGRAMS

*,,z

A 'D 'A " (Bty

Also ok

1¥ Him.

c EG . A'big = CANDY -1""

E¥€¥¥E¥¥ it:*:" .¥E#¥#

Page 6: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !6

Example question & solutions: sets

fan ( BUA ' )'

) Uf AaB) = A

Page 7: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !6

Example question & solutions: sets

fan ( BUA ' )'

)UfAhB) = A

fan ( Butt 't'

) UIAAB)* ¥..nl/tnlBhMlUlMME...*n--fAAAlnBYVlAnBl;aeFo+en.

( AAB' ) VIAND) = An 1134131DISTR .

NOTE : ABSORPTION '

iii.nniiiuiie.in"÷÷÷÷¥÷÷÷÷¥:÷÷÷i

Page 8: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !7

Relations & functions

-binary relations; domain, codomain, image, preimage (notation!!), inverse relation

-Cartesian product, tuples, counting (cardinality), definitions, representations

-injective, surjective, bijective, total, functional

-relation composition (associative)

-binary relations on ! : reflexive, symmetric, antisymmetric, transitive, partial order, equivalence relation (definitions, examples counterexamples)

A × A

For relations :

r .

Page 9: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !8

-P-closure of a relation (reflexive, symmetric, transitive). Properties and characterizations

Relations & functions

(1) R is reflexive ! (2) R is symmetric !

⇔ id ⊆ R⇔ R−1 ⊆ R R∘n ⊆ R

⇔ R ∘ R ⊆ R(1) Transitive (then also )

-Functions as relations; Domain, codomain, preimage, image

Many mistakes here, understand notation f(A) and ! for !

f −1(B),A ⊆ Dom( f ), B ⊆ Codom( f )

Injective, surjective, bijective functions (as relations): characterizations. Inverse function. Composition, associativity.

E.g.:

=

set of all x C- Don ( t )mapped into B !

Page 10: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !9

Special functions: sequences and series

-Definitions, basic examples

-Arithmetic and geometric

!k

∑i= 0

,k

∏i= 0

,

⋃i= 0

kk

⋂i= 0

-computing basic sums/products (sums of all numbers, of squares etc…)

*

$6,

Page 11: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !10

Example question & solutions functions and relations

Let f : # →I be an injective function ( surjective)

Prove or disprove : f? fat. flxl . f- Cx )is injective .

Curiedive)?

Page 12: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !10

Example question & solutions functions and relations

Let f : # →I be an injective function

Prove or disprove : f? ftlxliflxl . flx )is injective .

surjective? Solution :

text :X . fatten a

×= - X .

it injective tin -tin ⇒ ⇐ Y. EN

SAME counterexample for Shri five

Page 13: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !11

Example question & solutions functions and relations

f- iA→B ④¥Prove VEA ⇒ f'

'

Iff)) ? V

V, :-. f- (VI-

- { flxllxev }xev ⇒ xtftflrll

x # t- ' HIM

f-'

ful - fxe AHHHH) ) twelfth ) ⇒"IHeartY .

Page 14: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !12

General graphs

-definitions of types (undir., dir., simple), basic teminology (vertex/note, edge (arrow), connected, adjacent, incident, degree indegree, outdegree, neighbour(hood))

-subgraphs, vertex induced subgraphs, connected components, edge removal, bridge, etc.

-sum-degree formula, handshaking lemma (proof?)

-isomorphism and equality

µ

Page 15: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !13

General graphs

-Walking the undirected and directed graph! simple path, trail, cycle, circuit

-Euler graph = has euler circuit - know characterization (idea of proof) -Euler trail = recall difference

-Hamilton cycle - definition.

-Special graphs; Bipartite graphs (characterization); complete graphs, clique planar graphs.

-Labeled graphs

Page 16: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !14

Theorem 9.2. a) strongly connected if and only a closed spanning path exists b) weakly connected if and only if a spanning semipath exists f

Theorem 9.3. A directed graph G without cycles has a source and a sink.

Theorem 9.3. If G is a directed graph without cycles, then there exists a topological ordering of G (and converse)

-Basics of directed graphs…

-Topological ordering

know Theorems (not proofs):

Page 17: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !15

Example question & solutions: Graphs

Kmm ÷:qµ each with each

• When does Kanin ( complete ) have an Euler cycle ? ( min both

even :)

• Let 9 have a Hamilton cycle of lengthIs it bipartite?

↳ Recacc : Bipartite ⇐ no odd cycle !

Page 18: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !16

Combinatorics

Permutations and combinations

“sampling with and without replacement”

!Factorials, binomial coefficients (n-choose-k)

(connected to inclusion exclusion, powerset counting)

Page 19: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !17

Example question & solutions: counting and combinatorics

THERE ARE (Yc ) bitting , length n with exactly k ones

There are e bit-string, representing a number n t e

How many are either for my ,k=2 ,e -- 7

° 0000 8 1000I 0001 g 1001 Mroom :p : Inclusion / et ( µ) - ( AADHIz 001 I 12 1100

40100 13 no ,exclusion f

j 0101 14 11106 0110 J'- 0111

't " "ft 2¥ , -3

More generally e=zi - n . .. j bits .

..

.

= 4th -- to

IAF ( Y ) B -

- bit stingless than I ⇒ just j sits !

→ IAVBI : laltlbl-la.no/.-lY/t2i - fi ) !

Page 20: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !17

Example question & solutions: counting and combinatorics

More counting . . .

Let L = { x. h . - x , I xitlqb.cl ; exactly 2 x 's are a

Ot X,= a }

5 ways to put in an"

a"

Kk ? ←

A = X.. . X,

St exactly 2' '

a"

's = 24×5 t 5 ← 5 ways to put in the second

p"a" ( note ace = cia )

-I

4 "free"

variables but cannot be"

q"

= 24 options

D= 35 ..

I HAD I ? ends with"a"

tha tree = 24×5

⇒ IAH IBI - LANDI = 35+245×4,

Page 21: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !18

Induction and recursion

-recursive and inductive definitions (examples, Fibonacci)

-proofs by induction! Total induction. (Sometimes said there are types ! )P(k) ⇒ P(k + 1); (∀l ≤ kP(k)) ⇒ P(k + 1)-structural induction over inductively defined objects (induction over “size” usually) (e.g. prove property of graphs or languages — Blurps!!)

Know how to prove arithmetic equalities inductively!

I aaa

Page 22: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !19

Example question & solutions: recursion and induction (total)INDUCTION-

4""

> h'

for 473

basis : 42 > g ⇐ s 16 > 9 V

4"> Intel' ( if 4 "

"

> hit

44=4×4"- '

7 4th' - . . need yur > lump torn's

b

by assumption h't with > h't Intl = (http^

So IF/Then 477 ( htt )

.

✓ .

Page 23: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !20

Example question & solutions: recursion and induction (total)

EXAMPLE MU PUZZLE ( IF TIME )

Page 24: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !21

General trees

-basic definitions and types

-Theorem: n-vertex tree has n-1 edges (proof?)

-basic concepts

Characterizations:

Page 25: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !22

Binary trees

-definition, recursive definition; binary tree in CS and rooted, ordered trees of max degree 2

-First child - right sibling: (Knuth encoding)

-(Binary) tree traversals: preorder, postorder, symmetric ordering (inorder) / NLR, LRN, LRN

-Arithmetic expressions as trees; Polish and reverse polish notation

-Recursive computation over trees (how to evaluate expressions)

Page 26: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !23

Example question & solutions: trees, esp. binary trees

Expression tree ( syhthah tree ),Schaum 10.6

.

E - flxtylfsatlbbbp times -- ④" T t" t't l"

powers = ab = : atb

④-Q -

④y

④ H⑤③④② ④⑤ '⑨

Page 27: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !23

Example question & solutions: trees, esp. binary trees

How it works with unary operations a → yaleft - did

" not"

A 1 7 ( b n -ie ) right - siblingx x ④

&⑨ i 9

① → Ql l

⑤ ① Qi Q⑤ ⑨

Page 28: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !24

Congruence (modulo n) relation and modulo computation

-definitions, and basic properties..

-know how to compute stuff! (can use Little Fermat’s theorem) (equivalence relation, hence transitive so can chain!)

Theorem. Suppose that ! and ! . Then

(1) ! (2) ! (3) !

a ≡ b (mod n) c ≡ d (mod n)

a + c ≡ b + d (mod n)a −c ≡ b −d (mod n)a × c ≡ b × d (mod n)

Corollary. If ! then ! for all integer k>0.a ≡ b (mod n) ak ≡ bk (mod n)

-residue classes and partitions…

Page 29: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !25

Example question & solutions: congruence and modulo computation

Divisibilityk

AHN.

. ai dude, . . do die { o ..93 a de Hole

e- nk

Ha ⇐ $1 Edie ( *If. 0

recall .

A b (modal ⇐ s Ma - b ⇐" a 4.

b have

the same reminder whendivided by N .

HH g la means reminder is zero . So it aII.ode nod 9 , they

have same remainder i so one is divisible ⇒ the other is.

vedrandunjko
Sticky Note
see exercises given additionally in previous (pre-)lecture
Page 30: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !26

Langauges and automata

Languages: basic operations on words and languages

Regular languages (generated from singletons with union, kleene star, concatenation)

Regular expressions

Page 31: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !27

Langauges and automata

Automata; definitions

Constructing automata that recognizes/accepts a language (deterministic and non-deterministic)

NDFA = DFA = Regular Languages = Regex

Page 32: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Languageeither starts

( = I xefaib)'t

/ & ends with bb }or doesn't start

- regexwith bb

.

bb I fbbfalblltbb ) / ( blatant lbalalblt )- automaton

Page 33: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Non - deterministic

↳ 0¥89'

..

"

" Yoda..

"002am

Page 34: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !27

Langauges and automata

Automata; definitions

Constructing automata that recognizes/accepts a language (deterministic and non-deterministic)

NDFA = DFA = Regular Languages = Regex

Page 35: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !27

Langauges and automata

Automata; definitions

Constructing automata that recognizes/accepts a language (deterministic and non-deterministic)

NDFA = DFA = Regular Languages = Regex

Page 36: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !27

Langauges and automata

Automata; definitions

Constructing automata that recognizes/accepts a language (deterministic and non-deterministic)

NDFA = DFA = Regular Languages = Regex

Page 37: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !27

Langauges and automata

Automata; definitions

Constructing automata that recognizes/accepts a language (deterministic and non-deterministic)

NDFA = DFA = Regular Languages = Regex

Page 38: Lecture 17 revision of topics - liacs.leidenuniv.nlliacs.leidenuniv.nl › ~dunjkov › FCS1 › FCS1-L17-Final-lecture.pdf · -set relations: subset, superset, equality, disjointness-the

Foundations of Computer Science 1 — LIACS !27

Langauges and automata

Automata; definitions

Constructing automata that recognizes/accepts a language (deterministic and non-deterministic)

NDFA = DFA = Regular Languages = Regex